import os
import sys
import glob
+import platform
+import locale
import gettext
for item in getLanguageOptions():
if item[1] == selectedLanguage and item[0] is not None:
languages = [item[0]]
+ break
+ if languages[0] == 'AUTO':
+ languages = ['en']
+ defaultLocale = getDefaultLocale()
+ if defaultLocale is not None:
+ for item in getLanguageOptions():
+ if item[0] == 'AUTO':
+ continue
+ if item[0] is not None and defaultLocale.startswith(item[0]):
+ languages = [item[0]]
locale_path = os.path.normpath(os.path.join(resourceBasePath, 'locale'))
translation = gettext.translation('Cura', locale_path, languages, fallback=True)
def getLanguageOptions():
return [
+ ['AUTO', 'Autodetect'],
['en', 'English'],
['de', 'Deutsch'],
['fr', 'French'],
# ['es', 'Spanish'],
# ['po', 'Polish']
]
+
+def getDefaultLocale():
+ defaultLocale = None
+
+ # On Windows, we look for the actual UI language, as someone could have
+ # an english windows but use a non-english locale.
+ if platform.system() == "Windows":
+ try:
+ import ctypes
+
+ windll = ctypes.windll.kernel32
+ defaultLocale = locale.windows_locale[windll.GetUserDefaultUILanguage()]
+ except:
+ pass
+
+ if defaultLocale is None:
+ try:
+ defaultLocale = locale.getdefaultlocale()[0]
+ except:
+ pass
+
+ return defaultLocale