Closes #561: Add configuration option to prevent catalog bundling.

This commit is contained in:
Robert Lehmann
2011-10-03 13:20:53 +02:00
parent 88af4549d7
commit 77329bf497
4 changed files with 25 additions and 7 deletions

View File

@@ -406,11 +406,20 @@ documentation on :ref:`intl` for details.
add the directory :file:`./locale` to this settting, the message catalogs
(compiled from ``.po`` format using :program:`msgfmt`) must be in
:file:`./locale/{language}/LC_MESSAGES/sphinx.mo`. The text domain of
individual documents depends on their docname if they are top-level project
files and on their base directory otherwise.
individual documents depends on :confval:`gettext_compact`.
The default is ``[]``.
.. confval:: gettext_compact
.. versionadded:: 1.1
If true, a document's text domain is its docname if it is a top-level
project file and its very base directory otherwise.
By default, the document ``markup/code.rst`` ends up in the ``markup`` text
domain. With this option set to ``False``, it is ``markup/code``.
.. _html-options:

View File

@@ -16,7 +16,7 @@ from collections import defaultdict
from sphinx.builders import Builder
from sphinx.util.nodes import extract_messages
from sphinx.util.osutil import SEP, safe_relpath
from sphinx.util.osutil import SEP, safe_relpath, ensuredir, find_catalog
from sphinx.util.console import darkgreen
POHEADER = ur"""
@@ -76,7 +76,7 @@ class I18nBuilder(Builder):
return
def write_doc(self, docname, doctree):
catalog = self.catalogs[docname.split(SEP, 1)[0]]
catalog = self.catalogs[find_catalog(docname, self.config)]
for node, msg in extract_messages(doctree):
catalog.add(msg, node)
@@ -97,11 +97,14 @@ class MessageCatalogBuilder(I18nBuilder):
# XXX should supply tz
ctime = datetime.now().strftime('%Y-%m-%d %H:%M%z'),
)
for section, catalog in self.status_iterator(
for textdomain, catalog in self.status_iterator(
self.catalogs.iteritems(), "writing message catalogs... ",
lambda (section, _):darkgreen(section), len(self.catalogs)):
lambda (textdomain, _):darkgreen(textdomain), len(self.catalogs)):
pofn = path.join(self.outdir, section + '.pot')
# noop if config.gettext_compact is set
ensuredir(path.join(self.outdir, path.dirname(textdomain)))
pofn = path.join(self.outdir, textdomain + '.pot')
pofile = open(pofn, 'w', encoding='utf-8')
try:
pofile.write(POHEADER % data)

View File

@@ -176,6 +176,9 @@ class Config(object):
linkcheck_ignore = ([], None),
linkcheck_timeout = (None, None),
linkcheck_workers = (5, None),
# gettext options
gettext_compact = (True, 'gettext'),
)
def __init__(self, dirname, filename, overrides, tags):

View File

@@ -140,3 +140,6 @@ def safe_relpath(path, start=None):
return os.path.relpath(path, start)
except ValueError:
return path
def find_catalog(docname, config):
return docname.split(SEP, 1)[0] if config.gettext_compact else docname