diff --git a/script.js b/script.js index a462339..eec964e 100644 --- a/script.js +++ b/script.js @@ -1,3 +1,273 @@ +// Polish translation system +const translations = { + en: { + // UI Elements + "Power System Designer": "Power System Designer", + "Calculate Voltage Drops": "Calculate Voltage Drops", + "Clear All": "Clear All", + "Export Data": "Export Data", + "Import Data": "Import Data", + "Objects": "Objects", + "Transformer": "Transformer", + "Cable Box": "Cable Box", + "Pole": "Pole", + "End Connection": "End Connection", + "Cables": "Cables", + "Underground Cable": "Underground Cable", + "Overhead Cable": "Overhead Cable", + "Tools": "Tools", + "Select Mode": "Select Mode", + "Delete Mode": "Delete Mode", + "Auto Arrange - One Click to Make Everything Look Nice and Tidy": "Auto Arrange - One Click to Make Everything Look Nice and Tidy", + "Properties": "Properties", + "No object selected": "No object selected", + + // Object Properties + "Transformer Properties": "Transformer Properties", + "Number:": "Number:", + "Name:": "Name:", + "Upper Voltage (V):": "Upper Voltage (V):", + "Bottom Voltage (V):": "Bottom Voltage (V):", + "Power (kVA):": "Power (kVA):", + "Description:": "Description:", + "Transformer Info": "Transformer Info", + "Type:": "Type:", + "ID:": "ID:", + "Position:": "Position:", + "Ratio:": "Ratio:", + "Outputs:": "Outputs:", + "Actions": "Actions", + "Delete Transformer": "Delete Transformer", + + // Node Properties + "Node Properties": "Node Properties", + "Box": "Box", + "End": "End", + "Enter type description": "Enter type description", + "3-Phase Consumers (7kW each):": "3-Phase Consumers (7kW each):", + "1-Phase Consumers (3kW each):": "1-Phase Consumers (3kW each):", + "Custom Power (kW):": "Custom Power (kW):", + "Node Info": "Node Info", + "Total Power:": "Total Power:", + "3-Phase:": "3-Phase:", + "consumers": "consumers", + "1-Phase:": "1-Phase:", + "Custom:": "Custom:", + "Inputs:": "Inputs:", + "Delete Node": "Delete Node", + + // Cable Properties + "Power Cable Properties": "Power Cable Properties", + "Label:": "Label:", + "Cable Type:": "Cable Type:", + "YAKY (Ground Cable)": "YAKY (Ground Cable)", + "NA2XY-J (Ground Cable)": "NA2XY-J (Ground Cable)", + "AL (Overhead Cable)": "AL (Overhead Cable)", + "AsXSn (Overhead Cable)": "AsXSn (Overhead Cable)", + "Cross Section (mm²):": "Cross Section (mm²):", + "Length (m):": "Length (m):", + "Cable Info": "Cable Info", + "From:": "From:", + "To:": "To:", + "Specifications:": "Specifications:", + "Section Resistance:": "Section Resistance:", + "Section Current:": "Section Current:", + "Voltage Drop:": "Voltage Drop:", + "Total Consumers:": "Total Consumers:", + "Diversity Factor:": "Diversity Factor:", + "⚠️ Overhead cables can only connect to poles or end connections!": "⚠️ Overhead cables can only connect to poles or end connections!", + "Delete Cable": "Delete Cable", + + // Error Messages + "Cannot connect object to itself!": "Cannot connect object to itself!", + "Connection already exists!": "Connection already exists!", + "Transformer can only have one outgoing connection!": "Transformer can only have one outgoing connection!", + "Node can only have one incoming connection!": "Node can only have one incoming connection!", + "End connections cannot have outgoing connections!": "End connections cannot have outgoing connections!", + "Cannot connect from end connections!": "Cannot connect from end connections!", + "Cannot connect from node to transformer!": "Cannot connect from node to transformer!", + "Failed to import file: Invalid format": "Failed to import file: Invalid format", + "Need at least 2 objects to align": "Need at least 2 objects to align", + "Select at least 2 objects to align": "Select at least 2 objects to align", + "Need at least 3 objects to distribute": "Need at least 3 objects to distribute", + "No transformer found for auto-arrangement": "No transformer found for auto-arrangement", + + // Confirmation Messages + "Are you sure you want to clear all objects and connections?": "Are you sure you want to clear all objects and connections?", + + // Cable Names + "Cable": "Cable", + + // Node Types Display + "Ground": "Ground", + "Overhead": "Overhead", + "Node": "Node" + }, + pl: { + // UI Elements + "Power System Designer": "Analiza sieci nN", + "Calculate Voltage Drops": "Oblicz Spadki Napięcia", + "Clear All": "Wyczyść Wszystko", + "Export Data": "Eksportuj Dane", + "Import Data": "Importuj Dane", + "Objects": "Obiekty", + "Transformer": "Transformator", + "Cable Box": "Złącze Kablowe", + "Pole": "Słup", + "End Connection": "Odbiorca (napowietrzny)", + "Cables": "Kable", + "Underground Cable": "Kabel Ziemny", + "Overhead Cable": "Kabel Napowietrzny", + "Tools": "Narzędzia", + "Select Mode": "Tryb Wyboru", + "Delete Mode": "Tryb Usuwania", + "Auto Arrange - One Click to Make Everything Look Nice and Tidy": "Auto Rozmieszczenie", + "Properties": "Właściwości", + "No object selected": "Nie wybrano obiektu", + + // Object Properties + "Transformer Properties": "Właściwości Transformatora", + "Number:": "Numer:", + "Name:": "Nazwa:", + "Upper Voltage (V):": "Napięcie Górne (V):", + "Bottom Voltage (V):": "Napięcie Dolne (V):", + "Power (kVA):": "Moc (kVA):", + "Description:": "Opis:", + "Transformer Info": "Informacje o Transformatorze", + "Type:": "Typ:", + "ID:": "ID:", + "Position:": "Pozycja:", + "Ratio:": "Przekładnia:", + "Outputs:": "Wyjścia:", + "Actions": "Akcje", + "Delete Transformer": "Usuń Transformator", + + // Node Properties + "Node Properties": "Właściwości Węzła", + "Box": "Złącze Kablowe", + "End": "Koniec", + "Enter type description": "Wprowadź opis typu", + "3-Phase Consumers (7kW each):": "Odbiorcy 3-fazowi (7kW każdy):", + "1-Phase Consumers (3kW each):": "Odbiorcy 1-fazowi (3kW każdy):", + "Custom Power (kW):": "Niestandardowa Moc (kW):", + "Node Info": "Informacje o Węźle", + "Total Power:": "Moc Całkowita:", + "3-Phase:": "3-fazowe:", + "consumers": "odbiorców", + "1-Phase:": "1-fazowe:", + "Custom:": "Niestandardowe:", + "Inputs:": "Wejścia:", + "Delete Node": "Usuń Węzeł", + + // Cable Properties + "Power Cable Properties": "Właściwości Kabla Zasilającego", + "Label:": "Etykieta:", + "Cable Type:": "Typ Kabla:", + "YAKY (Ground Cable)": "YAKY", + "NA2XY-J (Ground Cable)": "NA2XY-J", + "AL (Overhead Cable)": "AL", + "AsXSn (Overhead Cable)": "AsXSn", + "Cross Section (mm²):": "Przekrój (mm²):", + "Length (m):": "Długość (m):", + "Cable Info": "Informacje o Kablu", + "From:": "Od:", + "To:": "Do:", + "Specifications:": "Specyfikacje:", + "Section Resistance:": "Rezystancja Odcinka:", + "Section Current:": "Prąd Odcinka:", + "Voltage Drop:": "Spadek Napięcia:", + "Total Consumers:": "Łączna Liczba Odbiorców:", + "Diversity Factor:": "Współczynnik Jednoczesności:", + "⚠️ Overhead cables can only connect to poles or end connections!": "Kable napowietrzne mogą łączyć się tylko ze słupami lub końcowymi połączeniami!", + "Delete Cable": "Usuń Kabel", + + // Error Messages + "Cannot connect object to itself!": "Nie można połączyć obiektu z samym sobą!", + "Connection already exists!": "Połączenie już istnieje!", + "Transformer can only have one outgoing connection!": "Transformator może mieć tylko jedno połączenie wychodzące!", + "Node can only have one incoming connection!": "Węzeł może mieć tylko jedno połączenie przychodzące!", + "End connections cannot have outgoing connections!": "Końcowe połączenia nie mogą mieć połączeń wychodzących!", + "Cannot connect from end connections!": "Nie można łączyć z końcowych połączeń!", + "Cannot connect from node to transformer!": "Nie można łączyć z węzła do transformatora!", + "Failed to import file: Invalid format": "Błąd importu pliku: Nieprawidłowy format", + "Need at least 2 objects to align": "Potrzeba co najmniej 2 obiektów do wyrównania", + "Select at least 2 objects to align": "Wybierz co najmniej 2 obiekty do wyrównania", + "Need at least 3 objects to distribute": "Potrzeba co najmniej 3 obiektów do rozłożenia", + "No transformer found for auto-arrangement": "Nie znaleziono transformatora do automatycznego rozmieszczenia", + + // Confirmation Messages + "Are you sure you want to clear all objects and connections?": "Czy na pewno chcesz wyczyścić wszystkie obiekty i połączenia?", + + // Cable Names + "Cable": "Kabel", + + // Node Types Display + "Ground": "Podziemny", + "Overhead": "Napowietrzny", + "Node": "Węzeł" + } +}; + +// Current language setting +let currentLanguage = 'pl'; // Default to Polish + +// Translation function +function t(key) { + return translations[currentLanguage][key] || translations.en[key] || key; +} + +// Translate static HTML UI elements +function translateStaticUI() { + // Header and buttons + const header = document.querySelector(".header h1"); + if (header) header.textContent = t("Power System Designer"); + + const calculateBtn = document.getElementById("calculateBtn"); + if (calculateBtn) calculateBtn.textContent = t("Calculate Voltage Drops"); + + const clearBtn = document.getElementById("clearBtn"); + if (clearBtn) clearBtn.textContent = t("Clear All"); + + const exportBtn = document.getElementById("exportBtn"); + if (exportBtn) exportBtn.textContent = t("Export Data"); + + const importBtn = document.getElementById("importBtn"); + if (importBtn) importBtn.textContent = t("Import Data"); + + // Toolbar labels + document.querySelectorAll(".toolbar-label").forEach((el) => { + if (el.textContent.trim() === "Objects") el.textContent = t("Objects"); + if (el.textContent.trim() === "Cables") el.textContent = t("Cables"); + if (el.textContent.trim() === "Tools") el.textContent = t("Tools"); + }); + + // Icon tooltips + document.querySelectorAll(".icon-btn[data-type]").forEach((btn) => { + const type = btn.getAttribute("data-type"); + if (type === "triangle") btn.title = t("Transformer"); + if (type === "box") btn.title = t("Cable Box"); + if (type === "pole") btn.title = t("Pole"); + if (type === "end") btn.title = t("End Connection"); + if (type === "underground") btn.title = t("Underground Cable"); + if (type === "overhead") btn.title = t("Overhead Cable"); + }); + + // Tool buttons tooltips + const selectBtn = document.getElementById("selectBtn"); + if (selectBtn) selectBtn.title = t("Select Mode"); + const deleteBtn = document.getElementById("deleteBtn"); + if (deleteBtn) deleteBtn.title = t("Delete Mode"); + const autoArrangeBtn = document.getElementById("autoArrangeBtn"); + if (autoArrangeBtn) autoArrangeBtn.title = t("Auto Arrange - One Click to Make Everything Look Nice and Tidy"); + + // Properties panel + const propertiesPanel = document.querySelector(".properties-panel h3"); + if (propertiesPanel) propertiesPanel.textContent = t("Properties"); +} + +// Call translation on DOMContentLoaded +window.addEventListener("DOMContentLoaded", translateStaticUI); + class ObjectFlowDesigner { constructor() { this.canvas = document.getElementById("canvas"); @@ -1069,7 +1339,7 @@ class ObjectFlowDesigner { } else if (this.selectedConnection) { this.updateConnectionProperties(panel); } else { - panel.innerHTML = '
No object selected
'; + panel.innerHTML = `${t("No object selected")}
`; } } @@ -1080,37 +1350,31 @@ class ObjectFlowDesigner { // Transformer properties panel.innerHTML = `Type: Transformer
-ID: ${obj.id}
-Position: (${Math.round(obj.x)}, ${Math.round(obj.y)})
-Ratio: ${obj.data.upperVoltage}V / ${ - obj.data.bottomVoltage - }V
-Outputs: ${obj.connections.outputs.length}/1
+${t("Type:")} ${t("Transformer")}
+${t("ID:")} ${obj.id}
+${t("Position:")} (${Math.round(obj.x)}, ${Math.round(obj.y)})
+${t("Ratio:")} ${obj.data.upperVoltage}V / ${obj.data.bottomVoltage}V
+${t("Outputs:")} ${obj.connections.outputs.length}/1
Type: ${ - obj.data.nodeType === "cable_box" - ? "Cable Box" - : obj.data.nodeType === "pole" - ? "Pole" - : "End Connection" - }
-ID: ${obj.id}
-Position: (${Math.round(obj.x)}, ${Math.round(obj.y)})
-Total Power: ${this.calculateNodeTotalPower(obj)} kW
-3-Phase: ${obj.data.consumers3Phase || 0} consumers (${ - (obj.data.consumers3Phase || 0) * 7 - }kW)
-1-Phase: ${obj.data.consumers1Phase || 0} consumers (${ - (obj.data.consumers1Phase || 0) * 3 - }kW)
-Custom: ${obj.data.customPowerKW || 0} kW
-Inputs: ${obj.connections.inputs.length}${ - obj.data.nodeType === "end_connection" ? "" : "/1" - }
-Outputs: ${obj.connections.outputs.length}${ - obj.data.nodeType === "end_connection" ? "/0" : "" - }
+${t("Type:")} ${obj.data.nodeType === "cable_box" ? t("Cable Box") : obj.data.nodeType === "pole" ? t("Pole") : t("End Connection")}
+${t("ID:")} ${obj.id}
+${t("Position:")} (${Math.round(obj.x)}, ${Math.round(obj.y)})
+${t("Total Power:")} ${this.calculateNodeTotalPower(obj)} kW
+${t("3-Phase:")} ${obj.data.consumers3Phase || 0} ${t("consumers")} (${(obj.data.consumers3Phase || 0) * 7}kW)
+${t("1-Phase:")} ${obj.data.consumers1Phase || 0} ${t("consumers")} (${(obj.data.consumers1Phase || 0) * 3}kW)
+${t("Custom:")} ${obj.data.customPowerKW || 0} kW
+${t("Inputs:")} ${obj.connections.inputs.length}${obj.data.nodeType === "end_connection" ? "" : "/1"}
+${t("Outputs:")} ${obj.connections.outputs.length}${obj.data.nodeType === "end_connection" ? "/0" : ""}
ID: ${conn.id}
-Type: ${conn.data.cableType} ${ - isOverheadCable ? "(Overhead)" : "(Ground)" - }
-From: ${conn.from.data.number || conn.from.data.name} (${ - conn.from.type === "triangle" - ? "Transformer" - : this.getNodeDisplayType(conn.from.data.nodeType) - })
-To: ${conn.to.data.number || conn.to.data.name} (${ - conn.to.type === "triangle" - ? "Transformer" - : this.getNodeDisplayType(conn.to.data.nodeType) - })
-Specifications: ${conn.data.crossSection}mm² × ${ - conn.data.length - }m
- ${ - hasElectricalData - ? ` -Section Resistance: ${ - Math.round(conn.data.sectionResistance * 1000) / 1000 - } Ω
-Section Current: ${ - Math.round(conn.data.sectionCurrent * 10) / 10 - } A (per phase)
-Voltage Drop: ${ - Math.round(conn.data.voltageDrop * 1000) / 1000 - } V
-Total Consumers: ${this.getTotalConsumers(conn.to)}
-Diversity Factor: ${( - this.getDiversityFactor(this.getTotalConsumers(conn.to)) * 100 - ).toFixed(0)}%
- ` - : "" - } - ${ - isOverheadCable - ? '⚠️ Overhead cables can only connect to poles or end connections!
' - : "" - } +${t("ID:")} ${conn.id}
+${t("Type:")} ${conn.data.cableType} ${isOverheadCable ? `(${t("Overhead")})` : `(${t("Ground")})`}
+${t("From:")} ${conn.from.data.number || conn.from.data.name} (${conn.from.type === "triangle" ? t("Transformer") : this.getNodeDisplayType(conn.from.data.nodeType)})
+${t("To:")} ${conn.to.data.number || conn.to.data.name} (${conn.to.type === "triangle" ? t("Transformer") : this.getNodeDisplayType(conn.to.data.nodeType)})
+${t("Specifications:")} ${conn.data.crossSection}mm² × ${conn.data.length}m
+ ${hasElectricalData ? `${t("Section Resistance:")} ${Math.round(conn.data.sectionResistance * 1000) / 1000} Ω
${t("Section Current:")} ${Math.round(conn.data.sectionCurrent * 10) / 10} A (per phase)
${t("Voltage Drop:")} ${Math.round(conn.data.voltageDrop * 1000) / 1000} V
${t("Total Consumers:")} ${this.getTotalConsumers(conn.to)}
${t("Diversity Factor:")} ${(this.getDiversityFactor(this.getTotalConsumers(conn.to)) * 100).toFixed(0)}%
` : ""} + ${isOverheadCable ? `${t("⚠️ Overhead cables can only connect to poles or end connections!")}
` : ""}