From: Youness Alaoui Date: Wed, 28 Jan 2015 00:25:04 +0000 (-0500) Subject: Auto detect language based on locale X-Git-Tag: lulzbot-15.02.1-1.01~75^2~2 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=f32e43b1bcf6a7d18e5b5ef8cc10367452537bf9;p=cura.git Auto detect language based on locale This wasn't tested on Windows, but the code is in a try/except and will fallback to using the default locale if it fails. Fixes issue #29 --- diff --git a/Cura/util/profile.py b/Cura/util/profile.py index 93572c27..afdc764c 100644 --- a/Cura/util/profile.py +++ b/Cura/util/profile.py @@ -486,7 +486,7 @@ setting('check_for_updates', 'False', bool, 'preference', 'hidden').setLabel(_(" setting('submit_slice_information', 'False', bool, 'preference', 'hidden').setLabel(_("Send usage statistics"), _("Submit anonymous usage information to improve future versions of Cura")) setting('youmagine_token', '', str, 'preference', 'hidden') setting('filament_physical_density', '1240', float, 'preference', 'hidden').setRange(500.0, 3000.0).setLabel(_("Density (kg/m3)"), _("Weight of the filament per m3. Around 1240 for PLA. And around 1040 for ABS. This value is used to estimate the weight if the filament used for the print.")) -setting('language', 'English', str, 'preference', 'hidden').setLabel(_('Language'), _('Change the language in which Cura runs. Switching language requires a restart of Cura')) +setting('language', 'AUTO', str, 'preference', 'hidden').setLabel(_('Language'), _('Change the language in which Cura runs. Switching language requires a restart of Cura')) setting('active_machine', '0', int, 'preference', 'hidden') setting('model_colour', '#C9E240', str, 'preference', 'hidden').setLabel(_('Model colour'), _('Display color for first extruder')) diff --git a/Cura/util/resources.py b/Cura/util/resources.py index d92eb2ae..e5e42909 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 @@ -53,7 +55,13 @@ def setupLocalization(selectedLanguage = None): #Default to english languages = ['en'] - if selectedLanguage is not None: + if selectedLanguage is None or selectedLanguage == 'AUTO': + defaultLocale = getDefaultLocale() + if defaultLocale is not None: + for item in getLanguageOptions(): + if item[0] is not None and defaultLocale.startswith(item[0]): + languages = [item[0]] + else: for item in getLanguageOptions(): if item[1] == selectedLanguage and item[0] is not None: languages = [item[0]] @@ -75,3 +83,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