Ticket #4450: 0001-i18n-get_locale_path-handle-the-case-when-the-defaul.patch

File 0001-i18n-get_locale_path-handle-the-case-when-the-defaul.patch, 2.6 KB (added by erikos, 10 years ago)

i18n get_locale_path: handle the case when the default locale is not set

  • bin/sugar-activity

    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(): 
    107107
    108108    # must be done early, some activities set translations globally, SL #3654
    109109    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())
    113114
    114115    splitted_module = args[0].rsplit('.', 1)
    115116    module_name = splitted_module[0]
  • src/sugar3/activity/i18n.py

    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): 
    119119        @type   bundle_id:      string
    120120        @param  bundle_id:      The bundle id of the activity in question
    121121        @rtype:                 string
    122         @return:                the preferred locale path
     122        @return:                the preferred locale path or None in the
     123                                case of an error
    123124    """
    124125
    125126    # Note: We pre-assign weights to the directories so that if no translations
    def get_locale_path(bundle_id): 
    135136
    136137    candidate_dirs[os.path.join(sys.prefix, 'share', 'locale')] = 0
    137138
     139    default_locale = locale.getdefaultlocale()[0]
     140    if not default_locale:
     141        return None
     142
    138143    for candidate_dir in candidate_dirs.keys():
    139144        if os.path.exists(candidate_dir):
    140145            full_path = os.path.join(candidate_dir, \
    141                 locale.getdefaultlocale()[0], 'LC_MESSAGES', \
     146                default_locale, 'LC_MESSAGES', \
    142147                bundle_id + '.mo')
    143148            if os.path.exists(full_path):
    144149                try: