Skip to content

Commit 18d3034

Browse files
i18n: Fix loading custom template translations for en (#12220)
Co-authored-by: Chris Sewell <chrisj_sewell@hotmail.com>
1 parent 71d50a8 commit 18d3034

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

sphinx/application.py

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -271,29 +271,26 @@ def _init_i18n(self) -> None:
271271
"""Load translated strings from the configured localedirs if enabled in
272272
the configuration.
273273
"""
274-
if self.config.language == 'en':
275-
self.translator, _ = locale.init([], None)
274+
logger.info(bold(__('loading translations [%s]... ')), self.config.language,
275+
nonl=True)
276+
277+
# compile mo files if sphinx.po file in user locale directories are updated
278+
repo = CatalogRepository(self.srcdir, self.config.locale_dirs,
279+
self.config.language, self.config.source_encoding)
280+
for catalog in repo.catalogs:
281+
if catalog.domain == 'sphinx' and catalog.is_outdated():
282+
catalog.write_mo(self.config.language,
283+
self.config.gettext_allow_fuzzy_translations)
284+
285+
locale_dirs: list[str | None] = list(repo.locale_dirs)
286+
locale_dirs += [None]
287+
locale_dirs += [path.join(package_dir, 'locale')]
288+
289+
self.translator, has_translation = locale.init(locale_dirs, self.config.language)
290+
if has_translation or self.config.language == 'en':
291+
logger.info(__('done'))
276292
else:
277-
logger.info(bold(__('loading translations [%s]... ')), self.config.language,
278-
nonl=True)
279-
280-
# compile mo files if sphinx.po file in user locale directories are updated
281-
repo = CatalogRepository(self.srcdir, self.config.locale_dirs,
282-
self.config.language, self.config.source_encoding)
283-
for catalog in repo.catalogs:
284-
if catalog.domain == 'sphinx' and catalog.is_outdated():
285-
catalog.write_mo(self.config.language,
286-
self.config.gettext_allow_fuzzy_translations)
287-
288-
locale_dirs: list[str | None] = list(repo.locale_dirs)
289-
locale_dirs += [None]
290-
locale_dirs += [path.join(package_dir, 'locale')]
291-
292-
self.translator, has_translation = locale.init(locale_dirs, self.config.language)
293-
if has_translation:
294-
logger.info(__('done'))
295-
else:
296-
logger.info(__('not available for built-in messages'))
293+
logger.info(__('not available for built-in messages'))
297294

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

0 commit comments

Comments
 (0)