-# coding=utf-8
from __future__ import absolute_import
+__copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
+
import os
import sys
-__all__ = ['getPathForResource', 'getPathForImage', 'getPathForMesh']
+#Cura/util classes should not depend on wx...
+import wx
+import gettext
+if sys.platform.startswith('darwin'):
+ try:
+ #Foundation import can crash on some MacOS installs
+ from Foundation import *
+ except:
+ pass
if sys.platform.startswith('darwin'):
if hasattr(sys, 'frozen'):
- from Foundation import *
- resourceBasePath = NSBundle.mainBundle().resourcePath()
+ try:
+ resourceBasePath = NSBundle.mainBundle().resourcePath()
+ except:
+ resourceBasePath = os.path.join(os.path.dirname(__file__), "../../../../../")
else:
resourceBasePath = os.path.join(os.path.dirname(__file__), "../resources")
else:
def getPathForFirmware(name):
return getPathForResource(resourceBasePath, 'firmware', name)
+
+def setupLocalization(selectedLanguage = None):
+ try:
+ if sys.platform.startswith('darwin'):
+ languages = NSLocale.preferredLanguages()
+ else:
+ #Using wx.Locale before you created wx.App seems to cause an nasty exception. So default to 'en' at the moment.
+ languages = [wx.Locale(wx.LANGUAGE_DEFAULT).GetCanonicalName()]
+ except Exception as e:
+ languages = ['en']
+
+ 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'],
+ ['fr', 'French'],
+ ['nl', 'Nederlands'],
+ ['sp', 'Spanish'],
+ ['po', 'Polish']
+ ]