Skip to content

Commit

Permalink
i18n: Fix loading custom template translations for en (#12220)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Sewell <chrisj_sewell@hotmail.com>
  • Loading branch information
n-peugnet and chrisjsewell committed May 15, 2024
1 parent 71d50a8 commit 18d3034
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 or self.config.language == 'en':
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 18d3034

Please sign in to comment.