diff options
| author | Chris McDonough <chrism@plope.com> | 2011-09-07 19:58:34 -0400 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2011-09-07 19:58:34 -0400 |
| commit | a3cd6b3ff1a02c5fad56cecb5178ca2ec77c3bfa (patch) | |
| tree | 4d580264f4fd94135566df34bb3ea80f8af98790 | |
| parent | 970b888021e81228f38cc2d4099dfe4ca350eba9 (diff) | |
| parent | 58ca44ed326326eba1d249801bc8faea8bc9cf4b (diff) | |
| download | pyramid-a3cd6b3ff1a02c5fad56cecb5178ca2ec77c3bfa.tar.gz pyramid-a3cd6b3ff1a02c5fad56cecb5178ca2ec77c3bfa.tar.bz2 pyramid-a3cd6b3ff1a02c5fad56cecb5178ca2ec77c3bfa.zip | |
Merge branch 'fix.263'
| -rw-r--r-- | CHANGES.txt | 7 | ||||
| -rw-r--r-- | pyramid/i18n.py | 25 | ||||
| -rw-r--r-- | pyramid/tests/pkgs/localeapp/locale/de_DE/LC_MESSAGES/deformsite.mo | bin | 0 -> 531 bytes | |||
| -rw-r--r-- | pyramid/tests/pkgs/localeapp/locale/de_DE/LC_MESSAGES/deformsite.po | 26 | ||||
| -rw-r--r-- | pyramid/tests/test_i18n.py | 5 |
5 files changed, 54 insertions, 9 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 3a3ff335b..d2af41876 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,6 +1,13 @@ Next release ============ +Bug Fixes +--------- + +- Sometimes falling back from territory translations (``de_DE``) to language + translations (``de``) would not work properly when using a localizer. See + https://github.com/Pylons/pyramid/issues/263 + Documentation ------------- diff --git a/pyramid/i18n.py b/pyramid/i18n.py index 4b34534af..f16aeb378 100644 --- a/pyramid/i18n.py +++ b/pyramid/i18n.py @@ -152,16 +152,27 @@ def make_localizer(current_locale_name, translation_directories): translations = Translations() translations._catalog = {} - locales_to_try = [current_locale_name] + locales_to_try = [] if '_' in current_locale_name: - locales_to_try.append(current_locale_name.split('_')[0]) + locales_to_try = [current_locale_name.split('_')[0]] + locales_to_try.append(current_locale_name) + + # intent: order locales left to right in least specific to most specific, + # e.g. ['de', 'de_DE']. This services the intent of creating a + # translations object that returns a "more specific" translation for a + # region, but will fall back to a "less specific" translation for the + # locale if necessary. Ordering from least specific to most specific + # allows us to call translations.add in the below loop to get this + # behavior. for tdir in translation_directories: - locale_dirs = [ (lname, os.path.join(tdir, lname)) for lname in - os.listdir(tdir) ] - for locale_name, locale_dir in locale_dirs: - if locale_name not in locales_to_try: - continue + locale_dirs = [] + for lname in locales_to_try: + ldir = os.path.realpath(os.path.join(tdir, lname)) + if os.path.isdir(ldir): + locale_dirs.append(ldir) + + for locale_dir in locale_dirs: messages_dir = os.path.join(locale_dir, 'LC_MESSAGES') if not os.path.isdir(os.path.realpath(messages_dir)): continue diff --git a/pyramid/tests/pkgs/localeapp/locale/de_DE/LC_MESSAGES/deformsite.mo b/pyramid/tests/pkgs/localeapp/locale/de_DE/LC_MESSAGES/deformsite.mo Binary files differnew file mode 100644 index 000000000..e3b2b0881 --- /dev/null +++ b/pyramid/tests/pkgs/localeapp/locale/de_DE/LC_MESSAGES/deformsite.mo diff --git a/pyramid/tests/pkgs/localeapp/locale/de_DE/LC_MESSAGES/deformsite.po b/pyramid/tests/pkgs/localeapp/locale/de_DE/LC_MESSAGES/deformsite.po new file mode 100644 index 000000000..be055bed9 --- /dev/null +++ b/pyramid/tests/pkgs/localeapp/locale/de_DE/LC_MESSAGES/deformsite.po @@ -0,0 +1,26 @@ +# German translations for deformsite. +# Copyright (C) 2010 ORGANIZATION +# This file is distributed under the same license as the deformsite project. +# FIRST AUTHOR <EMAIL@ADDRESS>, 2010. +# +msgid "" +msgstr "" +"Project-Id-Version: deformsite 0.0\n" +"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" +"POT-Creation-Date: 2010-04-22 14:17+0400\n" +"PO-Revision-Date: 2010-04-22 14:17-0400\n" +"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" +"Language-Team: de <LL@li.org>\n" +"Plural-Forms: nplurals=2; plural=(n != 1)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: Babel 0.9.5\n" + +#: deformsite/__init__.py:459 +msgid "Show approval" +msgstr "Zeigen Genehmigung" + +#: deformsite/__init__.py:466 +msgid "Submit" +msgstr "different" diff --git a/pyramid/tests/test_i18n.py b/pyramid/tests/test_i18n.py index 2abd35bdd..008cf525a 100644 --- a/pyramid/tests/test_i18n.py +++ b/pyramid/tests/test_i18n.py @@ -214,9 +214,10 @@ class Test_make_localizer(unittest.TestCase): locale_name = 'de_DE' result = self._callFUT(locale_name, localedirs) self.assertEqual(result.__class__, Localizer) + self.assertEqual(result.translate('Submit', 'deformsite'), + 'different') # prefer translations from de_DE locale self.assertEqual(result.translate('Approve', 'deformsite'), - 'Genehmigen') - + 'Genehmigen') # missing from de_DE locale, but in de class Test_get_localizer(unittest.TestCase): def setUp(self): |
