Skip to content

Commit

Permalink
Fix loading custom template translations for en
Browse files Browse the repository at this point in the history
The English language was hardcoded to load empty translations for
templates as part of sphinx-doc#10067,
but the rest of the code is already capable of handling missing
translations just fine, so we can simply drop the first if block.

This allows to use translations for English in custom templates, as for
all the other languages.

Fixes sphinx-doc#12214
  • Loading branch information
n-peugnet committed Apr 1, 2024
1 parent d5baa46 commit e52038f
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions sphinx/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,29 +271,26 @@ def _init_i18n(self) -> None:
"""Load translated strings from the configured localedirs if enabled in
the configuration.
"""
if self.config.language == 'en':
self.translator, _ = locale.init([], None)
logger.info(bold(__('loading translations [%s]... ') % self.config.language),
nonl=True)

# compile mo files if sphinx.po file in user locale directories are updated
repo = CatalogRepository(self.srcdir, self.config.locale_dirs,
self.config.language, self.config.source_encoding)
for catalog in repo.catalogs:
if catalog.domain == 'sphinx' and catalog.is_outdated():
catalog.write_mo(self.config.language,
self.config.gettext_allow_fuzzy_translations)

locale_dirs: list[str | None] = list(repo.locale_dirs)
locale_dirs += [None]
locale_dirs += [path.join(package_dir, 'locale')]

self.translator, has_translation = locale.init(locale_dirs, self.config.language)
if has_translation:
logger.info(__('done'))
else:
logger.info(bold(__('loading translations [%s]... ') % self.config.language),
nonl=True)

# compile mo files if sphinx.po file in user locale directories are updated
repo = CatalogRepository(self.srcdir, self.config.locale_dirs,
self.config.language, self.config.source_encoding)
for catalog in repo.catalogs:
if catalog.domain == 'sphinx' and catalog.is_outdated():
catalog.write_mo(self.config.language,
self.config.gettext_allow_fuzzy_translations)

locale_dirs: list[str | None] = list(repo.locale_dirs)
locale_dirs += [None]
locale_dirs += [path.join(package_dir, 'locale')]

self.translator, has_translation = locale.init(locale_dirs, self.config.language)
if has_translation:
logger.info(__('done'))
else:
logger.info(__('not available for built-in messages'))
logger.info(__('not available for built-in messages'))

def _init_env(self, freshenv: bool) -> BuildEnvironment:
filename = path.join(self.doctreedir, ENV_PICKLE_FILENAME)
Expand Down

0 comments on commit e52038f

Please sign in to comment.