diff --git a/gui/app.py b/gui/app.py new file mode 100644 index 000000000..736c55f6e --- /dev/null +++ b/gui/app.py @@ -0,0 +1,81 @@ +import wx +import config +import os +from logbook import Logger +pyfalog = Logger(__name__) + +class PyfaApp(wx.App): + def OnInit(self): + """ + Do application initialization work, e.g. define application globals. + """ + + # Name for my application. + self.appName = "pyfa" + + #------------ + + # # Simplified init method. + # self.DoConfig() + # self.Init() # InspectionMixin + # # work around for Python stealing "_". + # sys.displayhook = _displayHook + # + # #------------ + + # Return locale folder. + localeDir = os.path.join(config.pyfaPath, "locale") + + # Set language stuff and update to last used language. + self.locale = None + wx.Locale.AddCatalogLookupPathPrefix(localeDir) + # Set language stuff and update to last used language. + self.UpdateLanguage(config.language) + print(_("Market")) + return True + + #----------------------------------------------------------------------- + + def UpdateLanguage(self, lang = "en_US"): + """ + Update the language to the requested one. + + Make *sure* any existing locale is deleted before the new + one is created. The old C++ object needs to be deleted + before the new one is created, and if we just assign a new + instance to the old Python variable, the old C++ locale will + not be destroyed soon enough, likely causing a crash. + + :param string `lang`: one of the supported language codes. + """ + + # Language domain. + langDomain = "lang" + + # Languages you want to support. + supLang = { + "en_US": wx.LANGUAGE_ENGLISH, + "zh_CN": wx.LANGUAGE_CHINESE_SIMPLIFIED, + "de": wx.LANGUAGE_GERMAN + } + + # If an unsupported language is requested default to English. + if lang in supLang: + selLang = supLang[lang] + else: + selLang = wx.LANGUAGE_ENGLISH + + if self.locale: + assert sys.getrefcount(self.locale) <= 2 + del self.locale + + # Create a locale object for this language. + pyfalog.debug("Setting language to: " + lang) + self.locale = wx.Locale(selLang) + if self.locale.IsOk(): + success = self.locale.AddCatalog(langDomain, selLang) + if not success: + print("Langauage catalog not successfully loaded") + + else: + self.locale = None \ No newline at end of file diff --git a/gui/mainFrame.py b/gui/mainFrame.py index ec9006ee4..244d1bf18 100644 --- a/gui/mainFrame.py +++ b/gui/mainFrame.py @@ -143,6 +143,7 @@ class MainFrame(wx.Frame): pyfalog.debug("Initialize MainFrame") self.title = title super().__init__(None, wx.ID_ANY, self.title) + self.supress_left_up = False MainFrame.__instance = self @@ -177,7 +178,7 @@ class MainFrame(wx.Frame): shipBrowserImg = BitmapLoader.getImage("ship_small", "gui") self.marketBrowser = MarketBrowser(self.notebookBrowsers) - self.notebookBrowsers.AddPage(self.marketBrowser, "Market", image=marketImg, closeable=False) + self.notebookBrowsers.AddPage(self.marketBrowser, _("Market"), image=marketImg, closeable=False) self.marketBrowser.splitter.SetSashPosition(self.marketHeight) self.shipBrowser = ShipBrowser(self.notebookBrowsers) diff --git a/locale/README.md b/locale/README.md new file mode 100644 index 000000000..faeb0ea91 --- /dev/null +++ b/locale/README.md @@ -0,0 +1,12 @@ +On my Windows wsl2 (more generic explaination is needed): + +`find ./gui -iname "*.py" | xargs pygettext3 -d lang -o locale/lang.pot` + +This will generate the pot that should be carried over to the various language directories and renamed .po + +`msgfmt -o lang.mo lang` + +Run in each language directory, will compile the .po files to .mo files + +## Issues +`zh_CH` doesn't seem to work. AddCatalog is not functioning. See https://discuss.wxpython.org/t/localization-not-working-with-zh-ch-addcatalog-returns-false/34628 diff --git a/locale/de/LC_MESSAGES/lang.po b/locale/de/LC_MESSAGES/lang.po new file mode 100644 index 000000000..91f10853a --- /dev/null +++ b/locale/de/LC_MESSAGES/lang.po @@ -0,0 +1,21 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR ORGANIZATION +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"POT-Creation-Date: 2020-05-14 01:11-0400\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: pygettext.py 1.5\n" + + +#: ./gui/mainFrame.py:189 +msgid "Market" +msgstr "de Market" + diff --git a/locale/zh_CH/LC_MESSAGES/lang.po b/locale/zh_CH/LC_MESSAGES/lang.po new file mode 100644 index 000000000..da65d4bcf --- /dev/null +++ b/locale/zh_CH/LC_MESSAGES/lang.po @@ -0,0 +1,21 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR ORGANIZATION +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"POT-Creation-Date: 2016-05-19 17:07" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: utf8\n" +"Generated-By: pygettext.py 1.5\n" + + +#: ./gui/mainFrame.py:189 +msgid "Market" +msgstr "zhCH Market" +