From eded1ff4602de2e53f7f3e5150b2c66dbb144b55 Mon Sep 17 00:00:00 2001 From: James Addison Date: Sat, 8 Apr 2023 14:50:45 +0100 Subject: [PATCH] Re-allow localisation when SOURCE_DATE_EPOCH is set (follow-up to #10949) --- sphinx/locale/__init__.py | 16 ++-------------- tests/test_locale.py | 4 ++-- tests/test_util_inventory.py | 8 ++++---- 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/sphinx/locale/__init__.py b/sphinx/locale/__init__.py index 8bc7a267320..8706f6cd29b 100644 --- a/sphinx/locale/__init__.py +++ b/sphinx/locale/__init__.py @@ -105,22 +105,10 @@ def init( if translator.__class__ is NullTranslations: translator = None - if getenv('SOURCE_DATE_EPOCH') is not None: - # Disable localization during reproducible source builds - # See https://reproducible-builds.org/docs/source-date-epoch/ - # - # Note: Providing an empty/none value to gettext.translation causes - # it to consult various language-related environment variables to find - # locale(s). We don't want that during a reproducible build; we want - # to run through the same code path, but to return NullTranslations. - # - # To achieve that, specify the ISO-639-3 'undetermined' language code, - # which should not match any translation catalogs. - languages: list[str] | None = ['und'] - elif language: + if language: if '_' in language: # for language having country code (like "de_AT") - languages = [language, language.split('_')[0]] + languages: list[str] | None = [language, language.split('_')[0]] else: languages = [language] else: diff --git a/tests/test_locale.py b/tests/test_locale.py index 1d90473ca8d..5d056ae7780 100644 --- a/tests/test_locale.py +++ b/tests/test_locale.py @@ -94,5 +94,5 @@ def test_init_reproducible_build_language(rootdir, monkeypatch): _ = _empty_language_translation(rootdir) loc_et_translation = str(_('Hello world')) # str cast to evaluate lazy method - assert sde_en_translation == sde_et_translation - assert sde_et_translation != loc_et_translation + assert sde_en_translation != sde_et_translation + assert sde_et_translation == loc_et_translation diff --git a/tests/test_util_inventory.py b/tests/test_util_inventory.py index 675bba06b77..6959ef82a39 100644 --- a/tests/test_util_inventory.py +++ b/tests/test_util_inventory.py @@ -134,8 +134,8 @@ def test_inventory_reproducible(tempdir, monkeypatch): srcdir_et = _write_appconfig(tempdir, "et", prefix="localized") localized_inventory_et = _build_inventory(srcdir_et) - # Ensure that the reproducible inventory contents are identical - assert reproducible_inventory_et.read_bytes() == reproducible_inventory_en.read_bytes() + # Ensure that each (reproducible) localized inventory is different + assert reproducible_inventory_et.read_bytes() != reproducible_inventory_en.read_bytes() - # Ensure that inventory contents are different between a localized and non-localized build - assert reproducible_inventory_et.read_bytes() != localized_inventory_et.read_bytes() + # Ensure that inventory contents are the same between a reproducible and non-reproducible build + assert reproducible_inventory_et.read_bytes() == localized_inventory_et.read_bytes()