Takayuki Shimizukawa avatar Takayuki Shimizukawa committed 4fab3d6

Rebuild i18n target document when catalog updated

Comments (0)

Files changed (4)

 Release 1.2 (in development)
 ============================
 
+Features added
+--------------
+
+* Builders: rebuild i18n target document when catalog updated.
+
 Bugs fixed
 ----------
 

sphinx/environment.py

 from sphinx.util import url_re, get_matching_docs, docname_join, split_into, \
      FilenameUniqDict
 from sphinx.util.nodes import clean_astext, make_refnode, WarningStream
-from sphinx.util.osutil import SEP, fs_encoding
+from sphinx.util.osutil import SEP, fs_encoding, find_catalog_files
 from sphinx.util.matching import compile_matchers
 from sphinx.util.pycompat import class_types
 from sphinx.util.websupport import is_commentable
         self.found_docs = set(get_matching_docs(
             self.srcdir, config.source_suffix, exclude_matchers=matchers))
 
+        # add catalog mo file dependency
+        for docname in self.found_docs:
+            catalog_files = find_catalog_files(
+                docname,
+                self.srcdir,
+                self.config.locale_dirs,
+                self.config.language,
+                self.config.gettext_compact)
+            for filename in catalog_files:
+                self.dependencies.setdefault(docname, set()).add(filename)
+
     def get_outdated_files(self, config_changed):
         """Return (added, changed, removed) sets."""
         # clear all files no longer present

sphinx/util/osutil.py

 import errno
 import locale
 import shutil
+import gettext
 from os import path
 
 # Errnos that we need.
 
     return ret
 
+
+def find_catalog_files(docname, srcdir, locale_dirs, lang, compaction):
+    from sphinx.util.pycompat import relpath
+    if not(lang and locale_dirs):
+        return []
+
+    domain = find_catalog(docname, compaction)
+    files = [gettext.find(domain, path.join(srcdir, dir_), [lang])
+             for dir_ in locale_dirs]
+    files = [relpath(f, srcdir) for f in files if f]
+    return files
+
+
 fs_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding()

tests/test_intl.py

     result = (app.outdir / 'index.html').text(encoding='utf-8')
     assert "WELCOME" in result
     assert "SPHINX 2013.120" in result
+
+
+@with_intl_app(buildername='html')
+def test_rebuild_by_mo_mtime(app):
+    app.builder.build_update()
+    _, count, _ = app.env.update(app.config, app.srcdir, app.doctreedir, app)
+    assert count == 0
+
+    mo = (app.srcdir / 'xx' / 'LC_MESSAGES' / 'bom.mo').bytes()
+    (app.srcdir / 'xx' / 'LC_MESSAGES' / 'bom.mo').write_bytes(mo)
+    _, count, _ = app.env.update(app.config, app.srcdir, app.doctreedir, app)
+    assert count == 1
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.