From 5159b91856fcbfa2451841ad3226c4728684e6da Mon Sep 17 00:00:00 2001
From: Simon Schampijer <simon@laptop.org>
Date: Tue, 5 Mar 2013 14:17:36 +0100
Subject: [PATCH] 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>
---
bin/sugar-activity | 7 ++++---
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
|
b
|
def main(): |
107 | 107 | |
108 | 108 | # must be done early, some activities set translations globally, SL #3654 |
109 | 109 | locale_path = i18n.get_locale_path(bundle.get_bundle_id()) |
110 | | gettext.bindtextdomain(bundle.get_bundle_id(), locale_path) |
111 | | gettext.bindtextdomain('sugar-toolkit', sugar3.locale_path) |
112 | | gettext.textdomain(bundle.get_bundle_id()) |
| 110 | if locale_path: |
| 111 | gettext.bindtextdomain(bundle.get_bundle_id(), locale_path) |
| 112 | gettext.bindtextdomain('sugar-toolkit', sugar3.locale_path) |
| 113 | gettext.textdomain(bundle.get_bundle_id()) |
113 | 114 | |
114 | 115 | splitted_module = args[0].rsplit('.', 1) |
115 | 116 | module_name = splitted_module[0] |
diff --git a/src/sugar3/activity/i18n.py b/src/sugar3/activity/i18n.py
index 8b8e663..fe0d968 100644
a
|
b
|
def get_locale_path(bundle_id): |
119 | 119 | @type bundle_id: string |
120 | 120 | @param bundle_id: The bundle id of the activity in question |
121 | 121 | @rtype: string |
122 | | @return: the preferred locale path |
| 122 | @return: the preferred locale path or None in the |
| 123 | case of an error |
123 | 124 | """ |
124 | 125 | |
125 | 126 | # Note: We pre-assign weights to the directories so that if no translations |
… |
… |
def get_locale_path(bundle_id): |
135 | 136 | |
136 | 137 | candidate_dirs[os.path.join(sys.prefix, 'share', 'locale')] = 0 |
137 | 138 | |
| 139 | default_locale = locale.getdefaultlocale()[0] |
| 140 | if not default_locale: |
| 141 | return None |
| 142 | |
138 | 143 | for candidate_dir in candidate_dirs.keys(): |
139 | 144 | if os.path.exists(candidate_dir): |
140 | 145 | full_path = os.path.join(candidate_dir, \ |
141 | | locale.getdefaultlocale()[0], 'LC_MESSAGES', \ |
| 146 | default_locale, 'LC_MESSAGES', \ |
142 | 147 | bundle_id + '.mo') |
143 | 148 | if os.path.exists(full_path): |
144 | 149 | try: |