Georg Brandl avatar Georg Brandl committed 3b65bf9

#528: Observe :confval:`locale_dirs` when looking for the JS translations file.

Comments (0)

Files changed (2)

 Release 1.0.6 (in development)
 ==============================
 
+* #528: Observe :confval:`locale_dirs` when looking for the JS
+  translations file.
+
 * #574: Add special code for better support of Japanese documents
   in the LaTeX builder.
 

sphinx/builders/html.py

             self.link_suffix = self.out_suffix
 
         if self.config.language is not None:
-            jsfile_list = [path.join(package_dir, 'locale',
-                self.config.language, 'LC_MESSAGES', 'sphinx.js'),
-                path.join(sys.prefix, 'share/sphinx/locale',
-                    self.config.language, 'sphinx.js')]
+            if self._get_translations_js():
+                self.script_files.append('_static/translations.js')
 
-            for jsfile in jsfile_list:
-                if path.isfile(jsfile):
-                    self.script_files.append('_static/translations.js')
-                    break
+    def _get_translations_js(self):
+        candidates = [path.join(package_dir, 'locale', self.config.language,
+                                'LC_MESSAGES', 'sphinx.js'),
+                      path.join(sys.prefix, 'share/sphinx/locale',
+                                self.config.language, 'sphinx.js')] + \
+                     [path.join(dir, self.config.language,
+                                'LC_MESSAGES', 'sphinx.js')
+                      for dir in self.config.locale_dirs]
+        for jsfile in candidates:
+            if path.isfile(jsfile):
+                return jsfile
+        return None
 
     def get_theme_config(self):
         return self.config.html_theme, self.config.html_theme_options
         f.close()
         # then, copy translations JavaScript file
         if self.config.language is not None:
-            jsfile_list = [path.join(package_dir, 'locale',
-                self.config.language, 'LC_MESSAGES', 'sphinx.js'),
-                path.join(sys.prefix, 'share/sphinx/locale',
-                    self.config.language, 'sphinx.js')]
-            for jsfile in jsfile_list:
-                if path.isfile(jsfile):
-                    copyfile(jsfile, path.join(self.outdir, '_static',
-                                               'translations.js'))
-                    break
+            jsfile = self._get_translations_js()
+            if jsfile:
+                copyfile(jsfile, path.join(self.outdir, '_static',
+                                           'translations.js'))
         # then, copy over theme-supplied static files
         if self.theme:
             themeentries = [path.join(themepath, 'static')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.