Skip to content

Commit c1ca056

Browse files
committed
gh-142714: Keep the PEG grammar out of the translation catalogs
The grammar in reference/grammar.rst was extracted into the .pot files verbatim, including the parts that PEGLexer hides from the rendered page. There is nothing to translate there, so mark PEG literal blocks as not translatable.
1 parent c04ad8c commit c1ca056

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

‎Doc/tools/extensions/lexers/__init__.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
1+
from docutils import nodes
2+
from sphinx.transforms import SphinxTransform
3+
14
from .asdl_lexer import ASDLLexer
25
from .peg_lexer import PEGLexer
36

47

8+
class UntranslatablePEGBlocks(SphinxTransform):
9+
# The grammar has nothing to translate, so keep it out of the
10+
# message catalogs. Must run before the i18n Locale transform (20).
11+
default_priority = 10
12+
13+
def apply(self):
14+
for node in self.document.findall(nodes.literal_block):
15+
if node.get("language") == "peg":
16+
node["translatable"] = False
17+
18+
519
def setup(app):
620
# Used for highlighting Parser/Python.asdl in library/ast.rst
721
app.add_lexer("asdl", ASDLLexer)
822
# Used for highlighting Grammar/python.gram in reference/grammar.rst
923
app.add_lexer("peg", PEGLexer)
24+
app.add_transform(UntranslatablePEGBlocks)
1025

1126
return {
1227
"version": "1.0",

0 commit comments

Comments
 (0)