diff options
author | Simon Schampijer <simon@laptop.org> | 2013-03-05 13:17:36 (GMT) |
---|---|---|
committer | Ajay Garg <ajay@activitycentral.com> | 2013-03-09 11:27:22 (GMT) |
commit | a0195f9433033719fd66a4d9ce88ef7f7ff98e1e (patch) | |
tree | 5e10e764705d153e5291dfc689e6adcd4055cdb3 | |
parent | 61c59074054467e175d5f151cad6518011e9d90e (diff) |
i18n get_locale_path: handle the case when the default locale is not set, SL #4450
If the default locale is not set (see SL #4450 for a use case), get_locale_path
does now return None so that the sugar-activity script can handle that case
cleanly.
Signed-off-by: Simon Schampijer <simon@laptop.org>
Reviewed-by: Daniel Drake <dsd@laptop.org>
Signed-off-by: Ajay Garg <ajay@activitycentral.com>
-rw-r--r-- | bin/sugar-activity | 7 | ||||
-rw-r--r-- | src/sugar3/activity/i18n.py | 9 |
2 files changed, 11 insertions, 5 deletions
diff --git a/bin/sugar-activity b/bin/sugar-activity index abaa091..7cec4c4 100644 --- a/bin/sugar-activity +++ b/bin/sugar-activity @@ -107,9 +107,10 @@ def main(): # must be done early, some activities set translations globally, SL #3654 locale_path = i18n.get_locale_path(bundle.get_bundle_id()) - gettext.bindtextdomain(bundle.get_bundle_id(), locale_path) - gettext.bindtextdomain('sugar-toolkit', sugar3.locale_path) - gettext.textdomain(bundle.get_bundle_id()) + if locale_path: + gettext.bindtextdomain(bundle.get_bundle_id(), locale_path) + gettext.bindtextdomain('sugar-toolkit', sugar3.locale_path) + gettext.textdomain(bundle.get_bundle_id()) splitted_module = args[0].rsplit('.', 1) module_name = splitted_module[0] diff --git a/src/sugar3/activity/i18n.py b/src/sugar3/activity/i18n.py index 8b8e663..fe0d968 100644 --- a/src/sugar3/activity/i18n.py +++ b/src/sugar3/activity/i18n.py @@ -119,7 +119,8 @@ def get_locale_path(bundle_id): @type bundle_id: string @param bundle_id: The bundle id of the activity in question @rtype: string - @return: the preferred locale path + @return: the preferred locale path or None in the + case of an error """ # Note: We pre-assign weights to the directories so that if no translations @@ -135,10 +136,14 @@ def get_locale_path(bundle_id): candidate_dirs[os.path.join(sys.prefix, 'share', 'locale')] = 0 + default_locale = locale.getdefaultlocale()[0] + if not default_locale: + return None + for candidate_dir in candidate_dirs.keys(): if os.path.exists(candidate_dir): full_path = os.path.join(candidate_dir, \ - locale.getdefaultlocale()[0], 'LC_MESSAGES', \ + default_locale, 'LC_MESSAGES', \ bundle_id + '.mo') if os.path.exists(full_path): try: |