From: daid Date: Tue, 1 Oct 2013 14:02:46 +0000 (+0200) Subject: Add language selection. X-Git-Tag: 13.10~30 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=cura.git;a=commitdiff_plain;h=2de8becb4000ab530538e230276070edc75c00ac Add language selection. --- diff --git a/Cura/gui/app.py b/Cura/gui/app.py index 3ef52ba2..3861dbc1 100644 --- a/Cura/gui/app.py +++ b/Cura/gui/app.py @@ -45,7 +45,7 @@ class CuraApp(wx.App): from Cura.util import resources from Cura.util import version - resources.setupLocalization() # it's important to set up localization at very beginning to install _ + resources.setupLocalization(profile.getPreference('language')) # it's important to set up localization at very beginning to install _ #If we do not have preferences yet, try to load it from a previous Cura install if profile.getMachineSetting('machine_type') == 'unknown': diff --git a/Cura/gui/preferencesDialog.py b/Cura/gui/preferencesDialog.py index fd587892..8dc0199d 100644 --- a/Cura/gui/preferencesDialog.py +++ b/Cura/gui/preferencesDialog.py @@ -7,6 +7,7 @@ from Cura.gui import configWizard from Cura.gui import configBase from Cura.util import machineCom from Cura.util import profile +from Cura.util import resources class preferencesDialog(wx.Dialog): def __init__(self, parent): @@ -26,6 +27,9 @@ class preferencesDialog(wx.Dialog): for i in xrange(1, extruderCount): configBase.SettingRow(left, 'model_colour%d' % (i+1), wx.Colour) + configBase.TitleRow(left, _("Language")) + configBase.SettingRow(left, 'language', map(lambda n: n[1], resources.getLanguageOptions())) + configBase.TitleRow(right, _("Filament settings")) configBase.SettingRow(right, 'filament_physical_density') configBase.SettingRow(right, 'filament_cost_kg') diff --git a/Cura/gui/printWindow.py b/Cura/gui/printWindow.py index 8e2d2405..1e4ee6f4 100644 --- a/Cura/gui/printWindow.py +++ b/Cura/gui/printWindow.py @@ -91,7 +91,7 @@ def startPrintInterface(filename): #startPrintInterface is called from the main script when we want the printer interface to run in a separate process. # It needs to run in a separate process, as any running python code blocks the GCode sender python code (http://wiki.python.org/moin/GlobalInterpreterLock). app = wx.App(False) - resources.setupLocalization() + resources.setupLocalization(profile.getPreference('language')) printWindowHandle = printWindow() printWindowHandle.Show(True) printWindowHandle.Raise() diff --git a/Cura/util/profile.py b/Cura/util/profile.py index 4dbe4c2a..679b8914 100644 --- a/Cura/util/profile.py +++ b/Cura/util/profile.py @@ -343,6 +343,7 @@ setting('check_for_updates', 'True', bool, 'preference', 'hidden').setLabel(_("C setting('submit_slice_information', 'False', bool, 'preference', 'hidden').setLabel(_("Send usage statistics"), _("Submit anonymous usage information to improve next 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('active_machine', '0', int, 'preference', 'hidden') setting('model_colour', '#FFC924', str, 'preference', 'hidden').setLabel(_('Model colour')) diff --git a/Cura/util/resources.py b/Cura/util/resources.py index e071e419..8dbe9bd1 100644 --- a/Cura/util/resources.py +++ b/Cura/util/resources.py @@ -44,7 +44,7 @@ def getPathForMesh(name): def getPathForFirmware(name): return getPathForResource(resourceBasePath, 'firmware', name) -def setupLocalization(): +def setupLocalization(selectedLanguage = None): try: if sys.platform.startswith('darwin'): languages = NSLocale.preferredLanguages() @@ -54,7 +54,18 @@ def setupLocalization(): except Exception as e: languages = ['en'] - languages = ['nl'] + if selectedLanguage is not None: + for item in getLanguageOptions(): + if item[1] == selectedLanguage: + languages = [item[0]] + languages + locale_path = os.path.normpath(os.path.join(resourceBasePath, 'locale')) translation = gettext.translation('Cura', locale_path, languages, fallback=True) translation.install(unicode=True) + +def getLanguageOptions(): + return [ + ['en', 'English'], + ['de', 'Deutsch'], + ['nl', 'Nederlands'], + ]