From 6ab742b34d14b538d491723f9c523ad45e582c49 Mon Sep 17 00:00:00 2001
From: olpc user <olpc@xo-1e-88-ab.localdomain>
Date: Wed, 27 Feb 2013 15:55:32 +0000
Subject: [PATCH 1/1] CP language section: display language (country) each in
its own language - SL #4327
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This is how Wikipedia does, for example. For a user to search for its language,
it is much better to display it in its own language, not in the current
language of the system.
There was also an issue when having more than one language and English as the
primary one (see the referenced ticket). This bypasses that bug too.
Signed-off-by: Manuel Quiñones <manuq@laptop.org>
---
extensions/cpsection/language/view.py | 31 +++++++++++++++++++++++++++----
1 file changed, 27 insertions(+), 4 deletions(-)
diff --git a/extensions/cpsection/language/view.py b/extensions/cpsection/language/view.py
index 99275d4..6945dee 100644
a
|
b
|
from sugar3.graphics.icon import Icon |
25 | 25 | from jarabe.controlpanel.sectionview import SectionView |
26 | 26 | from jarabe.controlpanel.inlinealert import InlineAlert |
27 | 27 | |
28 | | _translate_language = lambda msg: gettext.dgettext('iso_639', msg) |
29 | | _translate_country = lambda msg: gettext.dgettext('iso_3166', msg) |
| 28 | def _translate_language(language_name, language): |
| 29 | """Translate a language name in the given language |
| 30 | |
| 31 | If no translation is found, return the language name English. |
| 32 | |
| 33 | """ |
| 34 | try: |
| 35 | # ISO 639 is the standard that specifies names of languages |
| 36 | translation = gettext.translation('iso_639', languages=[language]) |
| 37 | return translation.gettext(language_name) |
| 38 | except IOError: |
| 39 | return language_name |
| 40 | |
| 41 | def _translate_country(country_name, language): |
| 42 | """Translate a country name in the given language |
| 43 | |
| 44 | If no translation is found, return the country name English. |
| 45 | |
| 46 | """ |
| 47 | try: |
| 48 | # ISO 3166 is the standard that specifies names of countries |
| 49 | translation = gettext.translation('iso_3166', languages=[language]) |
| 50 | return translation.gettext(country_name) |
| 51 | except IOError: |
| 52 | return country_name |
30 | 53 | |
31 | 54 | CLASS = 'Language' |
32 | 55 | ICON = 'module-language' |
… |
… |
class Language(SectionView): |
101 | 124 | |
102 | 125 | store = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING) |
103 | 126 | for language, country, code in self._available_locales: |
104 | | description = '%s (%s)' % (_translate_language(language), \ |
105 | | _translate_country(country)) |
| 127 | description = '%s (%s)' % (_translate_language(language, code), \ |
| 128 | _translate_country(country, code)) |
106 | 129 | store.append([code, description]) |
107 | 130 | |
108 | 131 | combobox = Gtk.ComboBox(model=store) |