summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2020-08-14 14:21:43 +0900
committerGitHub <noreply@github.com>2020-08-14 14:21:43 +0900
commitdab15e2857464080bb88aa37d82c467f96cbd333 (patch)
tree63fd031b275757f274ee75318a938df3f2489cb2
parent5f420a4d8fd0a97faddcad5a46b9048563a66239 (diff)
parent1bf7fe424e16625f2ab4ad5824ca4aab6cf0ae65 (diff)
downloadsphinx-git-dab15e2857464080bb88aa37d82c467f96cbd333.tar.gz
Merge pull request #8058 from nijel/single-domain
i18n: Add support for having single text domain
-rw-r--r--doc/usage/configuration.rst6
-rw-r--r--sphinx/builders/gettext.py2
-rw-r--r--sphinx/util/i18n.py6
-rw-r--r--tests/test_build_gettext.py18
4 files changed, 29 insertions, 3 deletions
diff --git a/doc/usage/configuration.rst b/doc/usage/configuration.rst
index add78326b..3fc3a5306 100644
--- a/doc/usage/configuration.rst
+++ b/doc/usage/configuration.rst
@@ -756,9 +756,15 @@ documentation on :ref:`intl` for details.
If true, a document's text domain is its docname if it is a top-level
project file and its very base directory otherwise.
+ If set to string, all document's text domain is this string, making all
+ documents use single text domain.
+
By default, the document ``markup/code.rst`` ends up in the ``markup`` text
domain. With this option set to ``False``, it is ``markup/code``.
+ .. versionchanged:: 3.3
+ The string value is now accepted.
+
.. confval:: gettext_uuid
If true, Sphinx generates uuid information for version tracking in message
diff --git a/sphinx/builders/gettext.py b/sphinx/builders/gettext.py
index 8e30762e9..f8a19c57a 100644
--- a/sphinx/builders/gettext.py
+++ b/sphinx/builders/gettext.py
@@ -316,7 +316,7 @@ class MessageCatalogBuilder(I18nBuilder):
def setup(app: Sphinx) -> Dict[str, Any]:
app.add_builder(MessageCatalogBuilder)
- app.add_config_value('gettext_compact', True, 'gettext')
+ app.add_config_value('gettext_compact', True, 'gettext', Any)
app.add_config_value('gettext_location', True, 'gettext')
app.add_config_value('gettext_uuid', False, 'gettext')
app.add_config_value('gettext_auto_build', True, 'env')
diff --git a/sphinx/util/i18n.py b/sphinx/util/i18n.py
index 2177fc7b7..41407f4e1 100644
--- a/sphinx/util/i18n.py
+++ b/sphinx/util/i18n.py
@@ -14,7 +14,7 @@ import warnings
from collections import namedtuple
from datetime import datetime, timezone
from os import path
-from typing import Callable, Generator, List, Set, Tuple
+from typing import Callable, Generator, List, Set, Tuple, Union
import babel.dates
from babel.messages.mofile import write_mo
@@ -128,8 +128,10 @@ def find_catalog(docname: str, compaction: bool) -> str:
return ret
-def docname_to_domain(docname: str, compation: bool) -> str:
+def docname_to_domain(docname: str, compation: Union[bool, str]) -> str:
"""Convert docname to domain for catalogs."""
+ if isinstance(compation, str):
+ return compation
if compation:
return docname.split(SEP, 1)[0]
else:
diff --git a/tests/test_build_gettext.py b/tests/test_build_gettext.py
index 1c86b8daa..074602ea9 100644
--- a/tests/test_build_gettext.py
+++ b/tests/test_build_gettext.py
@@ -174,3 +174,21 @@ def test_gettext_template_msgid_order_in_sphinxpot(app):
'msgid "This is Template 2\\.".*'),
result,
flags=re.S)
+
+
+@pytest.mark.sphinx(
+ 'gettext', srcdir='root-gettext',
+ confoverrides={'gettext_compact': 'documentation'})
+def test_build_single_pot(app):
+ app.builder.build_all()
+
+ assert (app.outdir / 'documentation.pot').isfile()
+
+ result = (app.outdir / 'documentation.pot').read_text()
+ assert re.search(
+ ('msgid "Todo".*'
+ 'msgid "Like footnotes.".*'
+ 'msgid "The minute.".*'
+ 'msgid "Generated section".*'),
+ result,
+ flags=re.S)