--- a/svghmi/svghmi.py Tue Jan 05 01:23:45 2021 +0100
+++ b/svghmi/svghmi.py Fri Jan 15 10:11:05 2021 +0100
@@ -30,6 +30,7 @@
import targets
from editors.ConfTreeNodeEditor import ConfTreeNodeEditor
from XSLTransform import XSLTransform
+from svghmi.i18n import POTWriter, POReader
HMI_TYPES_DESC = {
"HMI_NODE":{},
@@ -460,9 +461,9 @@
"method": "_StartInkscape"
},
- # TODO : Launch POEdit button
- # PO -> SVG layers button
- # SVG layers -> PO
+ # TODO : Launch POEdit button for new languqge (opens POT)
+
+ # TODO : Launch POEdit button for existing languqge (opens one of existing PO)
# TODO : HMITree button
# - can drag'n'drop variabes to Inkscape
@@ -474,6 +475,10 @@
project_path = self.CTNPath()
return os.path.join(project_path, "svghmi.svg")
+ def _getPOTpath(self, project_path=None):
+ if project_path is None:
+ project_path = self.CTNPath()
+ return os.path.join(project_path, "messages.pot")
def OnCTNSave(self, from_project_path=None):
if from_project_path is not None:
@@ -513,6 +518,19 @@
res = [hmi_tree_root.etree(add_hash=True)]
return res
+ def GetTranslations(self, _context, msgs):
+
+ w = POTWriter()
+ w.ImportMessages(msgs)
+ # XXX get POT path
+ # XXX save POT file
+
+ # XXX scan existing PO files
+ # XXX read PO files
+
+ r = POReader()
+ return None # XXX return all langs from all POs
+
def CTNGenerate_C(self, buildpath, locations):
location_str = "_".join(map(str, self.GetCurrentLocation()))
@@ -532,7 +550,8 @@
# TODO : move to __init__
transform = XSLTransform(os.path.join(ScriptDirectory, "gen_index_xhtml.xslt"),
[("GetSVGGeometry", lambda *_ignored:self.GetSVGGeometry()),
- ("GetHMITree", lambda *_ignored:self.GetHMITree())])
+ ("GetHMITree", lambda *_ignored:self.GetHMITree()),
+ ("GetTranslations", self.GetTranslations)])
# load svg as a DOM with Etree
@@ -649,6 +668,28 @@
svgfile = None
open_svg(svgfile)
+ def _StartPOEdit(self, POFile):
+ open_poedit = True
+ if not self.GetCTRoot().CheckProjectPathPerm():
+ dialog = wx.MessageDialog(self.GetCTRoot().AppFrame,
+ _("You don't have write permissions.\nOpen POEdit anyway ?"),
+ _("Open POEdit"),
+ wx.YES_NO | wx.ICON_QUESTION)
+ open_poedit = dialog.ShowModal() == wx.ID_YES
+ dialog.Destroy()
+ if open_poedit:
+ # XXX TODO
+ pass
+
+ def _EditTranslation(self):
+ """ Select a specific translation and edit it with POEdit """
+ pass
+
+ def _EditNewTranslation(self):
+ """ Start POEdit with untouched empty catalog """
+ POFile = self._getPOTpath()
+ self._StartPOEdit(POFile)
+
def CTNGlobalInstances(self):
# view_name = self.BaseParams.getName()
# return [ (view_name + "_" + name, iec_type, "") for name, iec_type in SPECIAL_NODES]