Robert Lehmann  committed d4d504c

Make locale.init reentrable.

  • Participants
  • Parent commits 13ee063

Comments (0)

Files changed (1)

File sphinx/locale/

     return translators['sphinx'].ugettext(message)
 def init(locale_dirs, language, catalog='sphinx'):
+    """
+    Look for message catalogs in `locale_dirs` and *ensure* that there is at
+    least a NullTranslations catalog set in `translators`. If called multiple
+    times or several ``.mo`` files are found their contents are merged
+    together (thus making `init` reentrable).
+    """
     global translators
     translator = translators.get(catalog)
+    # ignore previously failed attempts to find message catalogs
+    if isinstance(translator, gettext.NullTranslations):
+        translator = None
     # the None entry is the system's default locale path
     has_translation = True
     for dir_ in locale_dirs:
         except Exception:
             # Language couldn't be found in the specified path
+    # guarantee translations[catalog] exists
     if translator is None:
         translator = gettext.NullTranslations()
         has_translation = False