28 from util.ProcessLogger import ProcessLogger |
28 from util.ProcessLogger import ProcessLogger |
29 from runtime.typemapping import DebugTypesSize |
29 from runtime.typemapping import DebugTypesSize |
30 import targets |
30 import targets |
31 from editors.ConfTreeNodeEditor import ConfTreeNodeEditor |
31 from editors.ConfTreeNodeEditor import ConfTreeNodeEditor |
32 from XSLTransform import XSLTransform |
32 from XSLTransform import XSLTransform |
33 from svghmi.i18n import POTWriter, POReader, open_pofile |
33 from svghmi.i18n import EtreeToMessages, SaveCatalog, ReadTranslations, MatchTranslations, TranslationToEtree |
34 |
34 |
35 HMI_TYPES_DESC = { |
35 HMI_TYPES_DESC = { |
36 "HMI_NODE":{}, |
36 "HMI_NODE":{}, |
37 "HMI_STRING":{}, |
37 "HMI_STRING":{}, |
38 "HMI_INT":{}, |
38 "HMI_INT":{}, |
528 global hmi_tree_root |
528 global hmi_tree_root |
529 res = [hmi_tree_root.etree(add_hash=True)] |
529 res = [hmi_tree_root.etree(add_hash=True)] |
530 return res |
530 return res |
531 |
531 |
532 def GetTranslations(self, _context, msgs): |
532 def GetTranslations(self, _context, msgs): |
533 |
533 messages = EtreeToMessages(msgs) |
534 w = POTWriter() |
534 |
535 w.ImportMessages(msgs) |
535 SaveCatalog(self._getPOTpath(), messages) |
536 |
536 |
537 with open(self._getPOTpath(), 'w') as POT_file: |
537 translations = ReadTranslations(self.CTNPath()) |
538 w.write(POT_file) |
538 |
539 |
539 langs,translated_messages = MatchTranslations(translations, messages, |
540 # XXX scan existing PO files |
540 errcallback=self.GetCTRoot().logger.write_warning) |
541 # XXX read PO files |
541 |
542 |
542 print(langs,translated_messages) |
543 r = POReader() |
543 |
544 return None # XXX return all langs from all POs |
544 return TranslationToEtree(langs,translated_messages) |
545 |
545 |
546 def CTNGenerate_C(self, buildpath, locations): |
546 def CTNGenerate_C(self, buildpath, locations): |
547 |
547 |
548 location_str = "_".join(map(str, self.GetCurrentLocation())) |
548 location_str = "_".join(map(str, self.GetCurrentLocation())) |
549 view_name = self.BaseParams.getName() |
549 view_name = self.BaseParams.getName() |
697 project_path = self.CTNPath() |
697 project_path = self.CTNPath() |
698 dialog = wx.FileDialog(self.GetCTRoot().AppFrame, _("Choose a PO file"), project_path, "", _("PO files (*.po)|*.po"), wx.OPEN) |
698 dialog = wx.FileDialog(self.GetCTRoot().AppFrame, _("Choose a PO file"), project_path, "", _("PO files (*.po)|*.po"), wx.OPEN) |
699 if dialog.ShowModal() == wx.ID_OK: |
699 if dialog.ShowModal() == wx.ID_OK: |
700 POFile = dialog.GetPath() |
700 POFile = dialog.GetPath() |
701 if os.path.isfile(POFile): |
701 if os.path.isfile(POFile): |
702 if os.path.dirname(POFile) == project_path: |
702 if os.path.relpath(POFile, project_path) == os.path.basename(POFile): |
703 self._StartPOEdit(POFile) |
703 self._StartPOEdit(POFile) |
704 else: |
704 else: |
705 self.GetCTRoot().logger.write_error(_("PO file misplaced: %s is not in %s\n") % (POFile,project_path)) |
705 self.GetCTRoot().logger.write_error(_("PO file misplaced: %s is not in %s\n") % (POFile,project_path)) |
706 else: |
706 else: |
707 self.GetCTRoot().logger.write_error(_("PO file do not exist: %s\n") % POFile) |
707 self.GetCTRoot().logger.write_error(_("PO file do not exist: %s\n") % POFile) |