chiark / gitweb /
Merge tag '15.01-RC4' into upstream
[cura.git] / Cura / util / resources.py
index 0259ef97f64d2ae50ea3417a34eb1afb14199c51..b03b68aefb26ef9d23c7847d2ce558aa1775a99c 100644 (file)
@@ -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