Finish up the dynamic translations
This commit is contained in:
29
gui/app.py
29
gui/app.py
@@ -1,7 +1,7 @@
|
||||
import wx
|
||||
import config
|
||||
import os
|
||||
|
||||
import sys
|
||||
from logbook import Logger
|
||||
pyfalog = Logger(__name__)
|
||||
from service.settings import LocaleSettings
|
||||
@@ -54,27 +54,24 @@ class PyfaApp(wx.App):
|
||||
"""
|
||||
|
||||
# Language domain.
|
||||
langDomain = "lang"
|
||||
|
||||
# Languages you want to support.
|
||||
supLang = LocaleSettings.supported_langauges
|
||||
langDomain = config.CATALOG
|
||||
|
||||
# If an unsupported language is requested default to English.
|
||||
if lang in supLang:
|
||||
selLang = supLang[lang].wxLocale
|
||||
else:
|
||||
selLang = wx.LANGUAGE_ENGLISH_US
|
||||
|
||||
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)
|
||||
if not success:
|
||||
print("Langauage catalog not successfully loaded")
|
||||
langInfo = wx.Locale.FindLanguageInfo(lang)
|
||||
if langInfo is not None:
|
||||
pyfalog.debug("Setting language to: " + lang)
|
||||
self.locale = wx.Locale(langInfo.Language)
|
||||
if self.locale.IsOk():
|
||||
success = self.locale.AddCatalog(langDomain)
|
||||
if not success:
|
||||
print("Langauage catalog not successfully loaded")
|
||||
|
||||
else:
|
||||
self.locale = None
|
||||
pyfalog.debug("Cannot find langauge: " + lang)
|
||||
self.locale = wx.Locale(wx.Locale.FindLanguageInfo(LocaleSettings.defaults['locale']).Language)
|
||||
@@ -102,12 +102,13 @@ class PFGeneralPref(PreferenceView):
|
||||
self.stLangLabel.Wrap(-1)
|
||||
langSizer.Add(self.stLangLabel, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)
|
||||
|
||||
self.langChoices = sorted([wx.Locale.FindLanguageInfo(x) for x in wx.Translations.Get().GetAvailableTranslations('lang')], key=lambda x: x.Description)
|
||||
self.langChoices = sorted([v for x, v in LocaleSettings.supported_langauges().items()], key=lambda x: x.Description)
|
||||
|
||||
self.chLang = wx.Choice(panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, [x.Description for x in self.langChoices], 0)
|
||||
self.chLang.Bind(wx.EVT_CHOICE, self.onLangSelection)
|
||||
|
||||
self.chLang.SetStringSelection(self.localeSettings.get('locale'))
|
||||
selectedIndex = self.langChoices.index(next((x for x in self.langChoices if x.CanonicalName == self.localeSettings.get('locale')), None))
|
||||
self.chLang.SetSelection(selectedIndex)
|
||||
|
||||
langSizer.Add(self.chLang, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)
|
||||
langBox.Add(langSizer)
|
||||
|
||||
Reference in New Issue
Block a user