mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Rebuild i18n target document when catalog updated
This commit is contained in:
5
CHANGES
5
CHANGES
@@ -1,6 +1,11 @@
|
||||
Release 1.2 (in development)
|
||||
============================
|
||||
|
||||
Features added
|
||||
--------------
|
||||
|
||||
* Builders: rebuild i18n target document when catalog updated.
|
||||
|
||||
Bugs fixed
|
||||
----------
|
||||
|
||||
|
@@ -37,7 +37,7 @@ from sphinx import addnodes
|
||||
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
|
||||
@@ -343,6 +343,17 @@ class BuildEnvironment:
|
||||
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
|
||||
|
@@ -16,6 +16,7 @@ import time
|
||||
import errno
|
||||
import locale
|
||||
import shutil
|
||||
import gettext
|
||||
from os import path
|
||||
|
||||
# Errnos that we need.
|
||||
@@ -161,4 +162,17 @@ def find_catalog(docname, compaction):
|
||||
|
||||
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()
|
||||
|
@@ -462,3 +462,15 @@ def test_gettext_template(app):
|
||||
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
|
||||
|
Reference in New Issue
Block a user