@@ -211,57 +224,145 @@
// --- STATE MANAGEMENT ---
let specificUtilities = [];
let utilityGroups = [];
+ let currentLanguage = 'it';
+ let lastCalculationData = null;
+
+ // --- TRANSLATIONS ---
+ const translations = {
+ mainTitle: { it: 'Calcolatore Economico Fotovoltaico', en: 'Economic Photovoltaic Calculator' },
+ mainSubtitle: { it: 'Analizza costi, risparmi e guadagni del tuo impianto solare.', en: 'Analyze costs, savings, and earnings of your solar system.' },
+ totalConsumptionLabel: { it: 'Consumo Totale Casa (kWh)', en: 'Total Home Consumption (kWh)' },
+ totalConsumptionPlaceholder: { it: 'Es. 450', en: 'E.g. 450' },
+ gridConsumptionLabel: { it: 'Consumo dalla Rete (kWh)', en: 'Consumption from Grid (kWh)' },
+ gridConsumptionPlaceholder: { it: 'Es. 150', en: 'E.g. 150' },
+ feedInEnergyLabel: { it: 'Energia Immessa in Rete (kWh)', en: 'Energy Fed into Grid (kWh)' },
+ feedInEnergyPlaceholder: { it: 'Es. 100', en: 'E.g. 100' },
+ purchasePriceLabel: { it: 'Costo Acquisto kWh (€)', en: 'Purchase Price per kWh (€)' },
+ purchasePricePlaceholder: { it: 'Es. 0.25', en: 'E.g. 0.25' },
+ sellPriceLabel: { it: 'Prezzo Vendita kWh (€)', en: 'Selling Price per kWh (€)' },
+ sellPricePlaceholder: { it: 'Es. 0.10', en: 'E.g. 0.10' },
+ groupManagementTitle: { it: 'Gestione Gruppi di Utenze', en: 'Utility Groups Management' },
+ newGroupNameLabel: { it: 'Nome Nuovo Gruppo', en: 'New Group Name' },
+ newGroupNamePlaceholder: { it: 'Es. Utenze Notturne', en: 'E.g. Night Utilities' },
+ saveGroupBtn: { it: 'Salva Lista Corrente come Gruppo', en: 'Save Current List as Group' },
+ savedGroupsLabel: { it: 'Gruppi Salvati', en: 'Saved Groups' },
+ loadBtn: { it: 'Carica', en: 'Load' },
+ deleteBtn: { it: 'Elimina', en: 'Delete' },
+ specificUtilitiesTitle: { it: 'Aggiungi Utenze Specifiche (Opzionale)', en: 'Add Specific Utilities (Optional)' },
+ utilityNameLabel: { it: 'Nome Utenza', en: 'Utility Name' },
+ utilityNamePlaceholder: { it: 'Es. Auto Elettrica', en: 'E.g. Electric Car' },
+ consumptionLabel: { it: 'Consumo (kWh)', en: 'Consumption (kWh)' },
+ consumptionPlaceholder: { it: '100', en: '100' },
+ addBtn: { it: 'Aggiungi', en: 'Add' },
+ calculateBtn: { it: 'Calcola Bilancio', en: 'Calculate Balance' },
+ economicSummaryTitle: { it: 'Riepilogo Economico', en: 'Economic Summary' },
+ costFromGridLabel: { it: 'Costo dalla Rete', en: 'Cost from Grid' },
+ savingsFromSelfConsumptionLabel: { it: 'Risparmio Autoconsumo', en: 'Self-Consumption Savings' },
+ feedInRevenueLabel: { it: 'Guadagno Immissione', en: 'Feed-in Revenue' },
+ finalBalanceLabel: { it: 'Bilancio Finale', en: 'Final Balance' },
+ energySummaryTitle: { it: 'Riepilogo Energetico (kWh)', en: 'Energy Summary (kWh)' },
+ selfConsumedEnergyLabel: { it: 'Energia Autoconsumata', en: 'Self-Consumed Energy' },
+ energyFromGridLabel: { it: 'Energia da Rete', en: 'Energy from Grid' },
+ fedInEnergySummaryLabel: { it: 'Energia Immessa', en: 'Fed-in Energy' },
+ totalPVProductionLabel: { it: 'Totale Prodotto da FV', en: 'Total PV Production' },
+ specificUtilitiesCostAnalysisTitle: { it: 'Analisi Costi Utenze Specifiche', en: 'Specific Utilities Cost Analysis' },
+ energySourcesBreakdownTitle: { it: 'Ripartizione Fonti Energetiche (Consumo Casa)', en: 'Energy Sources Breakdown (Home Consumption)' },
+ utilitiesImpactTitle: { it: 'Incidenza Utenze sui Consumi Totali', en: 'Utilities Impact on Total Consumption' },
+ noUtilitiesAdded: { it: 'Nessuna utenza specifica aggiunta.', en: 'No specific utilities added.' },
+ utilityNamePlaceholderEdit: { it: 'Nome Utenza', en: 'Utility Name' },
+ saveBtn: { it: 'Salva', en: 'Save' },
+ cancelBtn: { it: 'Annulla', en: 'Cancel' },
+ editBtn: { it: 'Modifica', en: 'Edit' },
+ removeBtn: { it: 'Rimuovi', en: 'Remove' },
+ fromGridLabel: { it: 'Dalla Rete', en: 'From Grid' },
+ fromPVLabel: { it: 'Da Fotovoltaico', en: 'From PV' },
+ totalSpecificUtilitiesLabel: { it: 'Totale Utenze Specifiche', en: 'Total Specific Utilities' },
+ otherConsumptionsLabel: { it: 'Altri Consumi', en: 'Other Consumptions' },
+ totalUtilitiesCostLabel: { it: 'Costo Totale Utenze', en: 'Total Utilities Cost' },
+ selectGroupOption: { it: '-- Seleziona un gruppo --', en: '-- Select a group --' },
+ };
// --- DOM REFERENCES ---
- // Inputs
- const consumoTotaleInput = document.getElementById('consumoTotale');
- const consumoReteInput = document.getElementById('consumoRete');
- const energiaImmessaInput = document.getElementById('energiaImmessa');
- const costoKwhInput = document.getElementById('costoKwh');
- const prezzoVenditaInput = document.getElementById('prezzoVendita');
- // Utenze
- const nomeUtenzaInput = document.getElementById('nomeUtenza');
- const consumoUtenzaInput = document.getElementById('consumoUtenza');
- const addUtenzaBtn = document.getElementById('addUtenzaBtn');
- const listaUtenzeDiv = document.getElementById('listaUtenze');
- // Gruppi
- const groupNameInput = document.getElementById('groupNameInput');
- const saveGroupBtn = document.getElementById('saveGroupBtn');
- const groupSelect = document.getElementById('groupSelect');
- const loadGroupBtn = document.getElementById('loadGroupBtn');
- const deleteGroupBtn = document.getElementById('deleteGroupBtn');
- // Buttons & Messages
- const calcolaBtn = document.getElementById('calcolaBtn');
- const risultatiDiv = document.getElementById('risultati');
- const errorMessageDiv = document.getElementById('error-message');
- // Results Sections
- const costoReteEl = document.getElementById('costoRete');
- const risparmioFVEl = document.getElementById('risparmioFV');
- const guadagnoImmissioneEl = document.getElementById('guadagnoImmissione');
- const bilancioFinaleEl = document.getElementById('bilancioFinale');
- const bilancioCardEl = document.getElementById('bilancioCard');
- const energiaFVEl = document.getElementById('energiaFV');
- const energiaReteEl = document.getElementById('energiaRete');
- const energiaImmessaOutEl = document.getElementById('energiaImmessaOut');
- const energiaProdottaEl = document.getElementById('energiaProdotta');
- const analisiCostiSpecificaDiv = document.getElementById('analisi-costi-specifica');
- const listaCostiUtenzeDiv = document.getElementById('lista-costi-utenze');
- // Graphs
- const barraReteEl = document.getElementById('barraRete');
- const barraFVEl = document.getElementById('barraFV');
- const percentualeReteEl = document.getElementById('percentualeRete');
- const percentualeFVEl = document.getElementById('percentualeFV');
- const graficoSpecificaDiv = document.getElementById('grafico-specifica');
- const barraSpecificaEl = document.getElementById('barraSpecifica');
- const barraAltriEl = document.getElementById('barraAltri');
- const percentualeSpecificaEl = document.getElementById('percentualeSpecifica');
- const percentualeAltriEl = document.getElementById('percentualeAltri');
+ const allDomRefs = {
+ consumoTotaleInput: document.getElementById('consumoTotale'),
+ consumoReteInput: document.getElementById('consumoRete'),
+ energiaImmessaInput: document.getElementById('energiaImmessa'),
+ costoKwhInput: document.getElementById('costoKwh'),
+ prezzoVenditaInput: document.getElementById('prezzoVendita'),
+ nomeUtenzaInput: document.getElementById('nomeUtenza'),
+ consumoUtenzaInput: document.getElementById('consumoUtenza'),
+ addUtenzaBtn: document.getElementById('addUtenzaBtn'),
+ listaUtenzeDiv: document.getElementById('listaUtenze'),
+ groupNameInput: document.getElementById('groupNameInput'),
+ saveGroupBtn: document.getElementById('saveGroupBtn'),
+ groupSelect: document.getElementById('groupSelect'),
+ loadGroupBtn: document.getElementById('loadGroupBtn'),
+ deleteGroupBtn: document.getElementById('deleteGroupBtn'),
+ calcolaBtn: document.getElementById('calcolaBtn'),
+ risultatiDiv: document.getElementById('risultati'),
+ errorMessageDiv: document.getElementById('error-message'),
+ costoReteEl: document.getElementById('costoRete'),
+ risparmioFVEl: document.getElementById('risparmioFV'),
+ guadagnoImmissioneEl: document.getElementById('guadagnoImmissione'),
+ bilancioFinaleEl: document.getElementById('bilancioFinale'),
+ bilancioCardEl: document.getElementById('bilancioCard'),
+ energiaFVEl: document.getElementById('energiaFV'),
+ energiaReteEl: document.getElementById('energiaRete'),
+ energiaImmessaOutEl: document.getElementById('energiaImmessaOut'),
+ energiaProdottaEl: document.getElementById('energiaProdotta'),
+ analisiCostiSpecificaDiv: document.getElementById('analisi-costi-specifica'),
+ listaCostiUtenzeDiv: document.getElementById('lista-costi-utenze'),
+ barraReteEl: document.getElementById('barraRete'),
+ barraFVEl: document.getElementById('barraFV'),
+ percentualeReteEl: document.getElementById('percentualeRete'),
+ percentualeFVEl: document.getElementById('percentualeFV'),
+ graficoSpecificaDiv: document.getElementById('grafico-specifica'),
+ barraSpecificaEl: document.getElementById('barraSpecifica'),
+ barraAltriEl: document.getElementById('barraAltri'),
+ percentualeSpecificaEl: document.getElementById('percentualeSpecifica'),
+ percentualeAltriEl: document.getElementById('percentualeAltri'),
+ langItBtn: document.getElementById('lang-it'),
+ langEnBtn: document.getElementById('lang-en'),
+ };
// --- FUNCTIONS ---
+ const setLanguage = (lang) => {
+ if (lang !== 'it' && lang !== 'en') {
+ lang = 'en'; // Default to English
+ }
+ currentLanguage = lang;
+ localStorage.setItem('photovoltaicCalculator_language', lang);
+
+ document.documentElement.lang = lang;
+ allDomRefs.langItBtn.classList.toggle('active', lang === 'it');
+ allDomRefs.langEnBtn.classList.toggle('active', lang === 'en');
+
+ document.querySelectorAll('[data-translate-key]').forEach(el => {
+ const key = el.dataset.translateKey;
+ if (translations[key] && translations[key][lang]) {
+ el.textContent = translations[key][lang];
+ }
+ });
+
+ document.querySelectorAll('[data-translate-key-placeholder]').forEach(el => {
+ const key = el.dataset.translateKeyPlaceholder;
+ if (translations[key] && translations[key][lang]) {
+ el.placeholder = translations[key][lang];
+ }
+ });
+
+ renderUtilitiesList();
+ populateGroupSelect();
+ if (allDomRefs.risultatiDiv.classList.contains('hidden') === false && lastCalculationData) {
+ renderResults(lastCalculationData);
+ }
+ };
+
const renderUtilitiesList = () => {
+ const { listaUtenzeDiv } = allDomRefs;
listaUtenzeDiv.innerHTML = '';
if (specificUtilities.length === 0) {
- listaUtenzeDiv.innerHTML = `
Nessuna utenza specifica aggiunta.
`;
+ listaUtenzeDiv.innerHTML = `
${translations.noUtilitiesAdded[currentLanguage]}
`;
return;
}
@@ -272,11 +373,11 @@
if (utenza.isEditing) {
utenzaEl.innerHTML = `
`;
@@ -288,8 +389,8 @@
${utenza.consumption} kWh