MCPcopy Create free account
hub / github.com/pyfa-org/Pyfa / UpdateLanguage

Method UpdateLanguage

gui/app.py:43–77  ·  view source on GitHub ↗

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, t

(self, lang=None)

Source from the content-addressed store, hash-verified

41 #-----------------------------------------------------------------------
42
43 def UpdateLanguage(self, lang=None):
44 """
45 Update the language to the requested one.
46
47 Make *sure* any existing locale is deleted before the new
48 one is created. The old C++ object needs to be deleted
49 before the new one is created, and if we just assign a new
50 instance to the old Python variable, the old C++ locale will
51 not be destroyed soon enough, likely causing a crash.
52
53 :param string `lang`: one of the supported language codes.
54 """
55
56 # Language domain.
57 langDomain = config.CATALOG
58
59 # If an unsupported language is requested default to English.
60
61 if self.locale:
62 assert sys.getrefcount(self.locale) <= 2
63 del self.locale
64
65 # Create a locale object for this language.
66 langInfo = wx.Locale.FindLanguageInfo(lang)
67 if langInfo is not None:
68 pyfalog.debug("Setting language to: " + lang)
69 self.locale = wx.Locale(langInfo.Language)
70 if self.locale.IsOk():
71 success = self.locale.AddCatalog(langDomain)
72 if not success:
73 print("Langauage catalog not successfully loaded")
74
75 else:
76 pyfalog.debug("Cannot find langauge: " + lang)
77 self.locale = wx.Locale(wx.Locale.FindLanguageInfo(LocaleSettings.defaults['locale']).Language)

Callers 1

OnInitMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected