Skip to content

Commit

Permalink
Partially revert sphinx-docGH-9778
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Apr 20, 2023
1 parent e2f66ce commit 9c86eea
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 27 deletions.
2 changes: 0 additions & 2 deletions CHANGES
Expand Up @@ -97,8 +97,6 @@ Bugs fixed
* #11192: Restore correct parallel search index building.
Patch by Jeremy Maitin-Shepard
* Use the new Transifex ``tx`` client
* #9778: Disable localisation when the ``SOURCE_DATE_EPOCH`` environment
variable is set, to assist with 'reproducible builds'. Patch by James Addison

Testing
--------
Expand Down
2 changes: 1 addition & 1 deletion sphinx/builders/html/__init__.py
Expand Up @@ -502,7 +502,7 @@ def prepare_writing(self, docnames: set[str]) -> None:
# typically doesn't include the time of day
lufmt = self.config.html_last_updated_fmt
if lufmt is not None:
self.last_updated = format_date(lufmt or str(_('%b %d, %Y')),
self.last_updated = format_date(lufmt or _('%b %d, %Y'),
language=self.config.language)
else:
self.last_updated = None
Expand Down
2 changes: 1 addition & 1 deletion sphinx/builders/latex/__init__.py
Expand Up @@ -179,7 +179,7 @@ def init_context(self) -> None:
if self.config.today:
self.context['date'] = self.config.today
else:
self.context['date'] = format_date(self.config.today_fmt or str(_('%b %d, %Y')),
self.context['date'] = format_date(self.config.today_fmt or _('%b %d, %Y'),
language=self.config.language)

if self.config.latex_logo:
Expand Down
4 changes: 2 additions & 2 deletions sphinx/domains/std.py
Expand Up @@ -242,9 +242,9 @@ def add_target_and_index(self, firstname: str, sig: str, signode: desc_signature

# create an index entry
if currprogram:
descr = str(_('%s command line option') % currprogram)
descr = _('%s command line option') % currprogram
else:
descr = str(_('command line option'))
descr = _('command line option')
for option in signode.get('allnames', []):
entry = '; '.join([descr, option])
self.indexnode['entries'].append(('pair', entry, signode['ids'][0], '', None))
Expand Down
25 changes: 9 additions & 16 deletions sphinx/locale/__init__.py
Expand Up @@ -4,7 +4,7 @@

import locale
from gettext import NullTranslations, translation
from os import getenv, path
from os import path
from typing import Any, Callable


Expand Down 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 Expand Up @@ -203,7 +191,12 @@ def setup(app):
.. versionadded:: 1.8
"""
def gettext(message: str) -> str:
return _TranslationProxy(catalog, namespace, message) # type: ignore[return-value]
if not is_translator_registered(catalog, namespace):
# not initialized yet
return _TranslationProxy(catalog, namespace, message) # type: ignore[return-value] # noqa: E501
else:
translator = get_translator(catalog, namespace)
return translator.gettext(message)

return gettext

Expand Down
2 changes: 1 addition & 1 deletion sphinx/transforms/__init__.py
Expand Up @@ -106,7 +106,7 @@ def apply(self, **kwargs: Any) -> None:
text = self.config[refname]
if refname == 'today' and not text:
# special handling: can also specify a strftime format
text = format_date(self.config.today_fmt or str(_('%b %d, %Y')),
text = format_date(self.config.today_fmt or _('%b %d, %Y'),
language=self.config.language)
ref.replace_self(nodes.Text(text))

Expand Down
2 changes: 1 addition & 1 deletion sphinx/writers/manpage.py
Expand Up @@ -93,7 +93,7 @@ def __init__(self, document: nodes.document, builder: Builder) -> None:
if self.config.today:
self._docinfo['date'] = self.config.today
else:
self._docinfo['date'] = format_date(self.config.today_fmt or str(_('%b %d, %Y')),
self._docinfo['date'] = format_date(self.config.today_fmt or _('%b %d, %Y'),
language=self.config.language)
self._docinfo['copyright'] = self.config.copyright
self._docinfo['version'] = self.config.version
Expand Down
2 changes: 1 addition & 1 deletion sphinx/writers/texinfo.py
Expand Up @@ -220,7 +220,7 @@ def init_settings(self) -> None:
'project': self.escape(self.config.project),
'copyright': self.escape(self.config.copyright),
'date': self.escape(self.config.today or
format_date(self.config.today_fmt or str(_('%b %d, %Y')),
format_date(self.config.today_fmt or _('%b %d, %Y'),
language=self.config.language)),
})
# title
Expand Down
4 changes: 2 additions & 2 deletions sphinx/writers/text.py
Expand Up @@ -791,8 +791,8 @@ def visit_acks(self, node: Element) -> None:

def visit_image(self, node: Element) -> None:
if 'alt' in node.attributes:
self.add_text(str(_('[image: %s]') % node['alt']))
self.add_text(str(_('[image]')))
self.add_text(_('[image: %s]') % node['alt'])
self.add_text(_('[image]'))
raise nodes.SkipNode

def visit_transition(self, node: Element) -> None:
Expand Down

0 comments on commit 9c86eea

Please sign in to comment.