Fixed #29144 -- Made untranslated strings for territorial language variants use translations from the generic language variant.

This commit is contained in:
Patryk Zawadzki 2018-02-19 19:09:33 +01:00 committed by Tim Graham
parent 939e0a5995
commit a20aae414e
9 changed files with 81 additions and 1 deletions

View File

@ -202,6 +202,8 @@ class DjangoTranslation(gettext_module.GNUTranslations):
self._catalog = other._catalog.copy()
else:
self._catalog.update(other._catalog)
if other._fallback:
self.add_fallback(other._fallback)
def language(self):
"""Return the translation language."""

View File

@ -179,6 +179,10 @@ Internationalization
* Added the :meth:`~django.utils.translation.get_supported_language_variant`
function.
* Untranslated strings for territorial language variants now use the
translations of the generic language. For example, untranslated ``pt_BR``
strings use ``pt`` translations.
Management Commands
~~~~~~~~~~~~~~~~~~~

View File

@ -2082,7 +2082,13 @@ translations for the same literal:
In all cases the name of the directory containing the translation is expected to
be named using :term:`locale name` notation. E.g. ``de``, ``pt_BR``, ``es_AR``,
etc.
etc. Untranslated strings for territorial language variants use the translations
of the generic language. For example, untranslated ``pt_BR`` strings use ``pt``
translations.
.. versionchanged:: 2.1
Fallback to the generic language as described above was added.
This way, you can write applications that include their own translations, and
you can override base translations in your project. Or, you can just build

View File

@ -0,0 +1,27 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-04-25 15:39-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: DE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#. Translators: This comment should be extracted
#: __init__.py:1
msgid "Test 1 (en)"
msgstr "Test 1 (de)"
#: __init__.py:2
msgid "Test 2 (en)"
msgstr "Test 2 (de)"

View File

@ -0,0 +1,27 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-04-25 15:39-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: DE-DE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#. Translators: This comment should be extracted
#: __init__.py:1
msgid "Test 1 (en)"
msgstr "Test 1 (de-de)"
#: __init__.py:2
msgid "Test 2 (en)"
msgstr ""

View File

@ -1455,6 +1455,20 @@ class DjangoFallbackResolutionOrderI18NTests(ResolutionOrderI18NTests):
self.assertEqual(gettext('Date/time'), 'Datum/Zeit')
@override_settings(INSTALLED_APPS=['i18n.territorial_fallback'])
class TranslationFallbackI18NTests(ResolutionOrderI18NTests):
def test_sparse_territory_catalog(self):
"""
Untranslated strings for territorial language variants use the
translations of the generic language. In this case, the de-de
translation falls back to de.
"""
with translation.override('de-de'):
self.assertGettext('Test 1 (en)', '(de-de)')
self.assertGettext('Test 2 (en)', '(de)')
class TestModels(TestCase):
def test_lazy(self):
tm = TestModel()