Skip to content

Commit c3b81c2

Browse files
felix-hildencmarqu
andauthored
Support translations and add ES,FI,DE (#178)
* Support translations and add ES+FI * Add de_DE translation (#179) --------- Co-authored-by: Colin Marquardt <[email protected]>
1 parent eecb9a2 commit c3b81c2

File tree

12 files changed

+128
-2
lines changed

12 files changed

+128
-2
lines changed

contributing.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ upload manually to `TestPyPI <https://test.pypi.org>`_ instead.
8585
$ twine upload --repository testpypi dist/*
8686
$ pip install --index-url https://test.pypi.org/simple/ sphinx-codeautolink
8787
88+
Translations
89+
------------
90+
You are also welcome to contribute translations!
91+
Use the following Babel commands to add new translations and locales.
92+
93+
.. code:: sh
94+
95+
$ cd src/sphinx_codeautolink
96+
$ pybabel init --input-file=locale/sphinx-codeautolink.pot --domain=sphinx-codeautolink --output-dir=locale --locale=fi_FI
97+
$ pybabel update --input-file=locale/sphinx-codeautolink.pot --domain=sphinx-codeautolink --output-dir=locale
98+
$ pybabel compile --directory=locale --domain=sphinx-codeautolink
99+
88100
.. |issue_resolution| image:: http://isitmaintained.com/badge/resolution/felix-hilden/sphinx-codeautolink.svg
89101
:target: https://isitmaintained.com/project/felix-hilden/sphinx-codeautolink
90102
:alt: issue resolution time

docs/src/release_notes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ sphinx-codeautolink adheres to
1010

1111
Unreleased
1212
----------
13+
- Add translations via i18n (:issue:`164`)
1314
- Fix attribute and call after walrus leading parser error (:issue:`174`)
1415
- Fix parsing error in doctest blocks with empty lines (:issue:`176`)
1516
- Improve error message on uncaught parsing errors (:issue:`177`)

src/sphinx_codeautolink/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
"""Sphinx extension for linking code examples to reference documentation."""
22

3+
from pathlib import Path
4+
35
from sphinx.application import Sphinx
46

57
from .extension import SphinxCodeAutoLink, backref, directive
68
from .extension.block import clean_ipython, clean_pycon
9+
from .extension.translation import MESSAGE_CATALOG_NAME
710

811
__version__ = "0.17.0"
912

@@ -76,4 +79,8 @@ def setup(app: Sphinx):
7679
app.add_node(
7780
backref.SummaryNode, html=(backref.visit_summary, backref.depart_summary)
7881
)
82+
83+
locale_dir = Path(__file__).resolve().parent / "locale"
84+
app.add_message_catalog(MESSAGE_CATALOG_NAME, locale_dir)
85+
7986
return {"version": __version__, "env_version": 1, "parallel_read_safe": True}

src/sphinx_codeautolink/extension/backref.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from sphinx_codeautolink.warn import logger, warn_type
88

99
from .directive import DeferredExamples
10+
from .translation import tr
1011

1112

1213
@dataclass
@@ -112,7 +113,7 @@ def unknown_visit(self, node) -> None:
112113
entry = nodes.entry()
113114
row += entry
114115
title = nodes.paragraph()
115-
title += nodes.Text("References to ")
116+
title += nodes.Text(tr("References to") + " ")
116117
title += orig_ref
117118
entry += title
118119

@@ -132,7 +133,7 @@ def unknown_visit(self, node) -> None:
132133
if node.collapse:
133134
details = DetailsNode()
134135
summary = SummaryNode()
135-
summary += nodes.Text("Expand for references to ")
136+
summary += nodes.Text(tr("Expand for references to") + " ")
136137
summary += orig_ref
137138
details += summary
138139
details += table
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""Translation utilities."""
2+
3+
from sphinx.locale import get_translation
4+
5+
MESSAGE_CATALOG_NAME = "sphinx-codeautolink"
6+
tr = get_translation(MESSAGE_CATALOG_NAME)
Binary file not shown.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# German (Germany) translations for sphinx-codeautolink.
2+
# Copyright (C) 2025 ORGANIZATION
3+
# This file is distributed under the same license as the sphinx-codeautolink project.
4+
# Colin Marquardt <[email protected]>, 2025.
5+
#
6+
msgid ""
7+
msgstr ""
8+
"Project-Id-Version: 1\n"
9+
"Report-Msgid-Bugs-To: [email protected]\n"
10+
"POT-Creation-Date: 2025-02-23 17:30+0200\n"
11+
"PO-Revision-Date: 2025-02-23 18:42+0100\n"
12+
"Last-Translator: Colin Marquardt <[email protected]>\n"
13+
"Language: de_DE\n"
14+
"Language-Team: Colin Marquardt <[email protected]>\n"
15+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
16+
"MIME-Version: 1.0\n"
17+
"Content-Type: text/plain; charset=utf-8\n"
18+
"Content-Transfer-Encoding: 8bit\n"
19+
"Generated-By: Babel 2.17.0\n"
20+
21+
msgid "References to"
22+
msgstr "Referenzen auf"
23+
24+
msgid "Expand for references to"
25+
msgstr "Aufklappen für Referenzen auf"
Binary file not shown.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Spanish (Spain) translations for sphinx-codeautolink.
2+
# Copyright (C) 2025 ORGANIZATION
3+
# This file is distributed under the same license as the sphinx-codeautolink project.
4+
# Felix Hildén <[email protected]>, 2025.
5+
#
6+
msgid ""
7+
msgstr ""
8+
"Project-Id-Version: 1\n"
9+
"Report-Msgid-Bugs-To: [email protected]\n"
10+
"POT-Creation-Date: 2025-02-23 17:30+0200\n"
11+
"PO-Revision-Date: 2025-02-23 18:05+0200\n"
12+
"Last-Translator: Felix Hildén <[email protected]>\n"
13+
"Language: es_ES\n"
14+
"Language-Team: Felix Hildén <[email protected]>\n"
15+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
16+
"MIME-Version: 1.0\n"
17+
"Content-Type: text/plain; charset=utf-8\n"
18+
"Content-Transfer-Encoding: 8bit\n"
19+
"Generated-By: Babel 2.17.0\n"
20+
21+
msgid "References to"
22+
msgstr "Referencias a"
23+
24+
msgid "Expand for references to"
25+
msgstr "Amplíe para referencias a"
Binary file not shown.

0 commit comments

Comments
 (0)