From a20aae414e762e4d9043e76b0bf8eccd334c8ebc Mon Sep 17 00:00:00 2001 From: Patryk Zawadzki Date: Mon, 19 Feb 2018 19:09:33 +0100 Subject: [PATCH] Fixed #29144 -- Made untranslated strings for territorial language variants use translations from the generic language variant. --- django/utils/translation/trans_real.py | 2 ++ docs/releases/2.1.txt | 4 +++ docs/topics/i18n/translation.txt | 8 +++++- tests/i18n/territorial_fallback/__init__.py | 0 .../locale/de/LC_MESSAGES/django.mo | Bin 0 -> 460 bytes .../locale/de/LC_MESSAGES/django.po | 27 ++++++++++++++++++ .../locale/de_DE/LC_MESSAGES/django.mo | Bin 0 -> 426 bytes .../locale/de_DE/LC_MESSAGES/django.po | 27 ++++++++++++++++++ tests/i18n/tests.py | 14 +++++++++ 9 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 tests/i18n/territorial_fallback/__init__.py create mode 100644 tests/i18n/territorial_fallback/locale/de/LC_MESSAGES/django.mo create mode 100644 tests/i18n/territorial_fallback/locale/de/LC_MESSAGES/django.po create mode 100644 tests/i18n/territorial_fallback/locale/de_DE/LC_MESSAGES/django.mo create mode 100644 tests/i18n/territorial_fallback/locale/de_DE/LC_MESSAGES/django.po diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py index 7d6ef125b5..af11c2ac35 100644 --- a/django/utils/translation/trans_real.py +++ b/django/utils/translation/trans_real.py @@ -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.""" diff --git a/docs/releases/2.1.txt b/docs/releases/2.1.txt index 3495a132a6..b22f27dcd7 100644 --- a/docs/releases/2.1.txt +++ b/docs/releases/2.1.txt @@ -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 ~~~~~~~~~~~~~~~~~~~ diff --git a/docs/topics/i18n/translation.txt b/docs/topics/i18n/translation.txt index 31ee71a05e..c205c15d4c 100644 --- a/docs/topics/i18n/translation.txt +++ b/docs/topics/i18n/translation.txt @@ -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 diff --git a/tests/i18n/territorial_fallback/__init__.py b/tests/i18n/territorial_fallback/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/i18n/territorial_fallback/locale/de/LC_MESSAGES/django.mo b/tests/i18n/territorial_fallback/locale/de/LC_MESSAGES/django.mo new file mode 100644 index 0000000000000000000000000000000000000000..454fef0c7a77968b53b62ff3146d89575672c978 GIT binary patch literal 460 zcmYL_OHRWu5Qf8R6LzdwcnLyNlF~}WJk-#*5Ro)hnpT1prZFL?wJXO(^dQ`X18@?~ z!lbQ~kw49E`S*A{e@FY@7RDZOjI@vgBt)usK@JhV&2!9j$Ff%2{SWHu{1-DWYZs}a zs<)0*l!mzEM95QXt(zM?)apY_4FnlXgf0suDH(dbNAI4I2}?#nJg^h7P})FL=0yf~ z%e;hCQDP6{6na{4gO|YPMo`jp+!i=3Xts&lrWcpsv>gYHkciKsD!%nSF)x8A2HztO zF^z(==Xk*Eke3Eh&1E^`Mrlg=<1i!xFJk1HMP3kgJ>O5*XmpEKnJ;-RAQgO0iI0vj z?9PgY(s_M~O-4b)>Yup{$L=X, 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 \n" +"Language-Team: DE \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)" diff --git a/tests/i18n/territorial_fallback/locale/de_DE/LC_MESSAGES/django.mo b/tests/i18n/territorial_fallback/locale/de_DE/LC_MESSAGES/django.mo new file mode 100644 index 0000000000000000000000000000000000000000..4d014cb1bf6dcd19e024bda1f4f6bd9d77fb98d5 GIT binary patch literal 426 zcmYL_u};G<5QYPSB}fd+3?8ZAN>W;>n1UJ_7b23Tq-iCP7)*17pyE`Hi{L?+csHJf zD+1-@Pv_w~`?tUMwmvPYO=6!oBDRShv92+(L);SQ8RwSlP0iwrJTc?D_7nLUnE7-*D+ zhQOBwIcqs?8=N+@I?V0xlT&ayjzc0O_*SeB|MTvImp~MQ@3HHcN5SEJJQ8*&D+8&P zs#-`>YR-n!Fk~Yy609d8F9`dd?d5`Lom&n)7Kogl_GvGd-aOq2^^)sGPIzV_|IT L|0gqq3>(%D;aF|^ literal 0 HcmV?d00001 diff --git a/tests/i18n/territorial_fallback/locale/de_DE/LC_MESSAGES/django.po b/tests/i18n/territorial_fallback/locale/de_DE/LC_MESSAGES/django.po new file mode 100644 index 0000000000..e28fcd3405 --- /dev/null +++ b/tests/i18n/territorial_fallback/locale/de_DE/LC_MESSAGES/django.po @@ -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 , 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 \n" +"Language-Team: DE-DE \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 "" diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py index afb4ac2ddb..c609e4d40a 100644 --- a/tests/i18n/tests.py +++ b/tests/i18n/tests.py @@ -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()