summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2020-08-14 16:11:23 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2020-10-04 13:31:37 +0900
commit37235c71e04aff3b93ae98f12456a34666635a9d (patch)
tree9d1f0ad545fdf33c7a3705c7e0c4842a2b1f48c0 /tests
parentb428cd2404675475a5c3dc2a2b0790ba57676202 (diff)
downloadsphinx-git-37235c71e04aff3b93ae98f12456a34666635a9d.tar.gz
Fix #6640: i18n: Failed to override system message translation
Our document describes that users can override system messages via their own message catalog named `sphinx.mo` under the locale_dirs. But it has not been used since its beginning of i18n mechanism because the priority of users' message catalog is lower than system's. This makes the priority of users' message catalog higher than system's.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_intl.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/test_intl.py b/tests/test_intl.py
index 1d1282baa..c0b87d5ce 100644
--- a/tests/test_intl.py
+++ b/tests/test_intl.py
@@ -14,8 +14,10 @@ import re
import pytest
from babel.messages import pofile, mofile
+from babel.messages.catalog import Catalog
from docutils import nodes
+from sphinx import locale
from sphinx.testing.util import (
path, etree_parse, strip_escseq,
assert_re_search, assert_not_re_search, assert_startswith, assert_node
@@ -1289,3 +1291,30 @@ def test_image_glob_intl_using_figure_language_filename(app):
def getwarning(warnings):
return strip_escseq(warnings.getvalue().replace(os.sep, '/'))
+
+
+@pytest.mark.sphinx('html', testroot='basic', confoverrides={'language': 'de'})
+def test_customize_system_message(make_app, app_params, sphinx_test_tempdir):
+ try:
+ # clear translators cache
+ locale.translators.clear()
+
+ # prepare message catalog (.po)
+ locale_dir = sphinx_test_tempdir / 'basic' / 'locales' / 'de' / 'LC_MESSAGES'
+ locale_dir.makedirs()
+ with (locale_dir / 'sphinx.po').open('wb') as f:
+ catalog = Catalog()
+ catalog.add('Quick search', 'QUICK SEARCH')
+ pofile.write_po(f, catalog)
+
+ # construct application and convert po file to .mo
+ args, kwargs = app_params
+ app = make_app(*args, **kwargs)
+ assert (locale_dir / 'sphinx.mo').exists()
+ assert app.translator.gettext('Quick search') == 'QUICK SEARCH'
+
+ app.build()
+ content = (app.outdir / 'index.html').read_text()
+ assert 'QUICK SEARCH' in content
+ finally:
+ locale.translators.clear()