Skip to content

Commit

Permalink
Re-allow localisation when SOURCE_DATE_EPOCH is set (follow-up to sph…
Browse files Browse the repository at this point in the history
  • Loading branch information
jayaddison committed Apr 8, 2023
1 parent 2c83af0 commit eded1ff
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 20 deletions.
16 changes: 2 additions & 14 deletions sphinx/locale/__init__.py
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_locale.py
Expand Up @@ -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
8 changes: 4 additions & 4 deletions tests/test_util_inventory.py
Expand Up @@ -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()

0 comments on commit eded1ff

Please sign in to comment.