X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=Cura%2Futil%2Fresources.py;h=b03b68aefb26ef9d23c7847d2ce558aa1775a99c;hb=54057a68a6093d90ce6a43c1681e049691c1206a;hp=0259ef97f64d2ae50ea3417a34eb1afb14199c51;hpb=76706d0295b292ad922cc70a9f61dee10523e4bd;p=cura.git diff --git a/Cura/util/resources.py b/Cura/util/resources.py index 0259ef97..b03b68ae 100644 --- a/Cura/util/resources.py +++ b/Cura/util/resources.py @@ -8,6 +8,8 @@ __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AG import os import sys import glob +import platform +import locale import gettext @@ -71,6 +73,16 @@ def setupLocalization(selectedLanguage = None): 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) @@ -79,6 +91,7 @@ def setupLocalization(selectedLanguage = None): def getLanguageOptions(): return [ + ['AUTO', 'Autodetect'], ['en', 'English'], ['de', 'Deutsch'], ['fr', 'French'], @@ -89,3 +102,25 @@ def getLanguageOptions(): # ['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