Ticket #4327: 0001-CP-language-section-display-language-country-each-in.patch

File 0001-CP-language-section-display-language-country-each-in.patch, 2.8 KB (added by manuq, 11 years ago)

Patch

  • extensions/cpsection/language/view.py

    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 
    2525from jarabe.controlpanel.sectionview import SectionView
    2626from jarabe.controlpanel.inlinealert import InlineAlert
    2727
    28 _translate_language = lambda msg: gettext.dgettext('iso_639', msg)
    29 _translate_country = lambda msg: gettext.dgettext('iso_3166', msg)
     28def _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
     41def _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
    3053
    3154CLASS = 'Language'
    3255ICON = 'module-language'
    class Language(SectionView): 
    101124
    102125        store = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING)
    103126        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))
    106129            store.append([code, description])
    107130
    108131        combobox = Gtk.ComboBox(model=store)