mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Closes #561: Add configuration option to prevent catalog bundling.
This commit is contained in:
@@ -406,11 +406,20 @@ documentation on :ref:`intl` for details.
|
|||||||
add the directory :file:`./locale` to this settting, the message catalogs
|
add the directory :file:`./locale` to this settting, the message catalogs
|
||||||
(compiled from ``.po`` format using :program:`msgfmt`) must be in
|
(compiled from ``.po`` format using :program:`msgfmt`) must be in
|
||||||
:file:`./locale/{language}/LC_MESSAGES/sphinx.mo`. The text domain of
|
:file:`./locale/{language}/LC_MESSAGES/sphinx.mo`. The text domain of
|
||||||
individual documents depends on their docname if they are top-level project
|
individual documents depends on :confval:`gettext_compact`.
|
||||||
files and on their base directory otherwise.
|
|
||||||
|
|
||||||
The default is ``[]``.
|
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:
|
.. _html-options:
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ from collections import defaultdict
|
|||||||
|
|
||||||
from sphinx.builders import Builder
|
from sphinx.builders import Builder
|
||||||
from sphinx.util.nodes import extract_messages
|
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
|
from sphinx.util.console import darkgreen
|
||||||
|
|
||||||
POHEADER = ur"""
|
POHEADER = ur"""
|
||||||
@@ -76,7 +76,7 @@ class I18nBuilder(Builder):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def write_doc(self, docname, doctree):
|
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):
|
for node, msg in extract_messages(doctree):
|
||||||
catalog.add(msg, node)
|
catalog.add(msg, node)
|
||||||
@@ -97,11 +97,14 @@ class MessageCatalogBuilder(I18nBuilder):
|
|||||||
# XXX should supply tz
|
# XXX should supply tz
|
||||||
ctime = datetime.now().strftime('%Y-%m-%d %H:%M%z'),
|
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... ",
|
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')
|
pofile = open(pofn, 'w', encoding='utf-8')
|
||||||
try:
|
try:
|
||||||
pofile.write(POHEADER % data)
|
pofile.write(POHEADER % data)
|
||||||
|
|||||||
@@ -176,6 +176,9 @@ class Config(object):
|
|||||||
linkcheck_ignore = ([], None),
|
linkcheck_ignore = ([], None),
|
||||||
linkcheck_timeout = (None, None),
|
linkcheck_timeout = (None, None),
|
||||||
linkcheck_workers = (5, None),
|
linkcheck_workers = (5, None),
|
||||||
|
|
||||||
|
# gettext options
|
||||||
|
gettext_compact = (True, 'gettext'),
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, dirname, filename, overrides, tags):
|
def __init__(self, dirname, filename, overrides, tags):
|
||||||
|
|||||||
@@ -140,3 +140,6 @@ def safe_relpath(path, start=None):
|
|||||||
return os.path.relpath(path, start)
|
return os.path.relpath(path, start)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
def find_catalog(docname, config):
|
||||||
|
return docname.split(SEP, 1)[0] if config.gettext_compact else docname
|
||||||
|
|||||||
Reference in New Issue
Block a user