Robert Lehmann committed f3b2739

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

Comments (0)

Files changed (4)

    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/`.  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:


 from 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"""
     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)
             # XXX should supply tz
             ctime ='%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')
                 pofile.write(POHEADER % data)
         linkcheck_ignore = ([], None),
         linkcheck_timeout = (None, None),
         linkcheck_workers = (5, None),
+        # gettext options
+        gettext_compact = (True, 'gettext'),
     def __init__(self, dirname, filename, overrides, tags):


         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