-
Notifications
You must be signed in to change notification settings - Fork 8
Add i18n support for exercise and solution labels #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ddedc9e
2dab815
e72061c
71ffa4a
b56c535
4e6acbc
6b4548b
3c6c876
d27e055
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| include LICENSE | ||
| include MANIFEST.in | ||
| include README.md | ||
|
|
||
| recursive-include sphinx_exercise *.js | ||
| recursive-include sphinx_exercise *.css | ||
|
|
||
| recursive-include sphinx_exercise *.json | ||
| recursive-include sphinx_exercise *.mo | ||
| recursive-include sphinx_exercise *.po | ||
| recursive-include sphinx_exercise *.py |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -29,6 +29,10 @@ | |||||
|
|
||||||
| logger = logging.getLogger(__name__) | ||||||
|
|
||||||
| from sphinx.locale import get_translation | ||||||
| MESSAGE_CATALOG_NAME = "exercise" | ||||||
| translate = get_translation(MESSAGE_CATALOG_NAME) | ||||||
|
|
||||||
|
|
||||||
| class SphinxExerciseBaseDirective(SphinxDirective): | ||||||
| def duplicate_labels(self, label): | ||||||
|
|
@@ -88,7 +92,7 @@ class : str, | |||||
| } | ||||||
|
|
||||||
| def run(self) -> List[Node]: | ||||||
| self.defaults = {"title_text": "Exercise"} | ||||||
| self.defaults = {"title_text": f"{translate('Exercise')}"} | ||||||
|
||||||
| self.defaults = {"title_text": f"{translate('Exercise')}"} | |
| self.defaults = {"title_text": translate('Exercise')} |
Copilot
AI
Oct 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The f-string formatting is unnecessary when wrapping a single function call. The code can be simplified to self.defaults = {"title_text": translate('Solution to')} for better readability.
| self.defaults = {"title_text": f"{translate('Solution to')}"} | |
| self.defaults = {"title_text": translate('Solution to')} |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -19,6 +19,10 @@ | |||||
| LaTeX = LaTeXMarkup() | ||||||
|
|
||||||
|
|
||||||
| from sphinx.locale import get_translation | ||||||
| MESSAGE_CATALOG_NAME = "exercise" | ||||||
| translate = get_translation(MESSAGE_CATALOG_NAME) | ||||||
|
|
||||||
| # Nodes | ||||||
|
|
||||||
|
|
||||||
|
|
@@ -50,7 +54,7 @@ class solution_end_node(docutil_nodes.Admonition, docutil_nodes.Element): | |||||
| class exercise_title(docutil_nodes.title): | ||||||
| def default_title(self): | ||||||
| title_text = self.children[0].astext() | ||||||
| if title_text == "Exercise" or title_text == "Exercise %s": | ||||||
| if title_text == f"{translate('Exercise')}" or title_text == f"{translate('Exercise')} %s": | ||||||
|
||||||
| if title_text == f"{translate('Exercise')}" or title_text == f"{translate('Exercise')} %s": | |
| if title_text == translate('Exercise') or title_text == translate('Exercise') + " %s": |
Copilot
AI
Oct 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The f-string formatting is unnecessary when wrapping a single function call. The code can be simplified to if title_text == translate('Solution to'): for better readability.
| if title_text == f"{translate('Solution to')}": | |
| if title_text == translate('Solution to'): |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| JSONs created using GitHub Copilot Pro. | ||
|
|
||
| To convert to locale files run `_convert.py` in this folder. |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,58 @@ | ||||||
| import json | ||||||
| import os | ||||||
| from pathlib import Path | ||||||
| import subprocess | ||||||
|
|
||||||
| MESSAGE_CATALOG_NAME = "exercise" | ||||||
|
|
||||||
| def convert_json(folder=None): | ||||||
| folder = folder or Path(__file__).parent | ||||||
|
|
||||||
| # remove exising | ||||||
|
||||||
| # remove exising | |
| # remove existing |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| [ | ||
| {"language":"English","symbol":"en","text":"Exercise"}, | ||
| {"language":"Spanish","symbol":"es","text":"Ejercicio"}, | ||
| {"language":"French","symbol":"fr","text":"Exercice"}, | ||
| {"language":"Bengali","symbol":"bn","text":"অনুশীলনী"}, | ||
| {"language":"Russian","symbol":"ru","text":"Упражнение"}, | ||
| {"language":"Portuguese","symbol":"pt","text":"Exercício"}, | ||
| {"language":"Indonesian","symbol":"id","text":"Latihan"}, | ||
| {"language":"German","symbol":"de","text":"Übung"}, | ||
| {"language":"Vietnamese","symbol":"vi","text":"Bài tập"}, | ||
| {"language":"Tamil","symbol":"ta","text":"பயிற்சி"}, | ||
| {"language":"Italian","symbol":"it","text":"Esercizio"}, | ||
| {"language":"Dutch","symbol":"nl","text":"Opgave"}, | ||
| {"language":"Greek","symbol":"el","text":"Άσκηση"}, | ||
| {"language":"Polish","symbol":"pl","text":"Ćwiczenie"}, | ||
| {"language":"Ukrainian","symbol":"uk","text":"Вправа"}, | ||
| {"language":"Malay","symbol":"ms","text":"Latihan"}, | ||
| {"language":"Romanian","symbol":"ro","text":"Exercițiu"}, | ||
| {"language":"Czech","symbol":"cs","text":"Cvičení"}, | ||
| {"language":"Hungarian","symbol":"hu","text":"Gyakorlat"}, | ||
| {"language":"Swedish","symbol":"sv","text":"Övning"}, | ||
| {"language":"Norwegian","symbol":"no","text":"Øvelse"} | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| [ | ||
| {"language":"English","symbol":"en","text":"Solution to"}, | ||
| {"language":"Spanish","symbol":"es","text":"Solución a"}, | ||
| {"language":"French","symbol":"fr","text":"Solution de"}, | ||
| {"language":"Bengali","symbol":"bn","text":"সমাধান"}, | ||
| {"language":"Russian","symbol":"ru","text":"Решение к"}, | ||
| {"language":"Portuguese","symbol":"pt","text":"Solução para"}, | ||
| {"language":"Indonesian","symbol":"id","text":"Solusi untuk"}, | ||
| {"language":"German","symbol":"de","text":"Lösung zu"}, | ||
| {"language":"Vietnamese","symbol":"vi","text":"Lời giải cho"}, | ||
| {"language":"Tamil","symbol":"ta","text":"தீர்வு"}, | ||
| {"language":"Italian","symbol":"it","text":"Soluzione a"}, | ||
| {"language":"Dutch","symbol":"nl","text":"Oplossing van"}, | ||
| {"language":"Greek","symbol":"el","text":"Λύση στο"}, | ||
| {"language":"Polish","symbol":"pl","text":"Rozwiązanie do"}, | ||
| {"language":"Ukrainian","symbol":"uk","text":"Розв'язок до"}, | ||
| {"language":"Malay","symbol":"ms","text":"Penyelesaian untuk"}, | ||
| {"language":"Romanian","symbol":"ro","text":"Soluția pentru"}, | ||
| {"language":"Czech","symbol":"cs","text":"Řešení k"}, | ||
| {"language":"Hungarian","symbol":"hu","text":"Megoldás a"}, | ||
| {"language":"Swedish","symbol":"sv","text":"Lösning till"}, | ||
| {"language":"Norwegian","symbol":"no","text":"Løsning til"} | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
|
|
||
| msgid "" | ||
| msgstr "" | ||
| "Project-Id-Version: Sphinx-Exercise\n" | ||
| "MIME-Version: 1.0\n" | ||
| "Content-Type: text/plain; charset=UTF-8\n" | ||
| "Content-Transfer-Encoding: 8bit\n" | ||
| "Language: bn\n" | ||
| "Plural-Forms: nplurals=2; plural=(n != 1);\n" | ||
|
|
||
| msgid "Exercise" | ||
| msgstr "অনুশীলনী" | ||
|
|
||
| msgid "Solution to" | ||
| msgstr "সমাধান" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
|
|
||
| msgid "" | ||
| msgstr "" | ||
| "Project-Id-Version: Sphinx-Exercise\n" | ||
| "MIME-Version: 1.0\n" | ||
| "Content-Type: text/plain; charset=UTF-8\n" | ||
| "Content-Transfer-Encoding: 8bit\n" | ||
| "Language: cs\n" | ||
| "Plural-Forms: nplurals=2; plural=(n != 1);\n" | ||
|
|
||
| msgid "Exercise" | ||
| msgstr "Cvičení" | ||
|
|
||
| msgid "Solution to" | ||
| msgstr "Řešení k" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
|
|
||
| msgid "" | ||
| msgstr "" | ||
| "Project-Id-Version: Sphinx-Exercise\n" | ||
| "MIME-Version: 1.0\n" | ||
| "Content-Type: text/plain; charset=UTF-8\n" | ||
| "Content-Transfer-Encoding: 8bit\n" | ||
| "Language: de\n" | ||
| "Plural-Forms: nplurals=2; plural=(n != 1);\n" | ||
|
|
||
| msgid "Exercise" | ||
| msgstr "Übung" | ||
|
|
||
| msgid "Solution to" | ||
| msgstr "Lösung zu" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
|
|
||
| msgid "" | ||
| msgstr "" | ||
| "Project-Id-Version: Sphinx-Exercise\n" | ||
| "MIME-Version: 1.0\n" | ||
| "Content-Type: text/plain; charset=UTF-8\n" | ||
| "Content-Transfer-Encoding: 8bit\n" | ||
| "Language: el\n" | ||
| "Plural-Forms: nplurals=2; plural=(n != 1);\n" | ||
|
|
||
| msgid "Exercise" | ||
| msgstr "Άσκηση" | ||
|
|
||
| msgid "Solution to" | ||
| msgstr "Λύση στο" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
|
|
||
| msgid "" | ||
| msgstr "" | ||
| "Project-Id-Version: Sphinx-Exercise\n" | ||
| "MIME-Version: 1.0\n" | ||
| "Content-Type: text/plain; charset=UTF-8\n" | ||
| "Content-Transfer-Encoding: 8bit\n" | ||
| "Language: es\n" | ||
| "Plural-Forms: nplurals=2; plural=(n != 1);\n" | ||
|
|
||
| msgid "Exercise" | ||
| msgstr "Ejercicio" | ||
|
|
||
| msgid "Solution to" | ||
| msgstr "Solución a" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
|
|
||
| msgid "" | ||
| msgstr "" | ||
| "Project-Id-Version: Sphinx-Exercise\n" | ||
| "MIME-Version: 1.0\n" | ||
| "Content-Type: text/plain; charset=UTF-8\n" | ||
| "Content-Transfer-Encoding: 8bit\n" | ||
| "Language: fr\n" | ||
| "Plural-Forms: nplurals=2; plural=(n != 1);\n" | ||
|
|
||
| msgid "Exercise" | ||
| msgstr "Exercice" | ||
|
|
||
| msgid "Solution to" | ||
| msgstr "Solution de" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
|
|
||
| msgid "" | ||
| msgstr "" | ||
| "Project-Id-Version: Sphinx-Exercise\n" | ||
| "MIME-Version: 1.0\n" | ||
| "Content-Type: text/plain; charset=UTF-8\n" | ||
| "Content-Transfer-Encoding: 8bit\n" | ||
| "Language: hu\n" | ||
| "Plural-Forms: nplurals=2; plural=(n != 1);\n" | ||
|
|
||
| msgid "Exercise" | ||
| msgstr "Gyakorlat" | ||
|
|
||
| msgid "Solution to" | ||
| msgstr "Megoldás a" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
|
|
||
| msgid "" | ||
| msgstr "" | ||
| "Project-Id-Version: Sphinx-Exercise\n" | ||
| "MIME-Version: 1.0\n" | ||
| "Content-Type: text/plain; charset=UTF-8\n" | ||
| "Content-Transfer-Encoding: 8bit\n" | ||
| "Language: id\n" | ||
| "Plural-Forms: nplurals=2; plural=(n != 1);\n" | ||
|
|
||
| msgid "Exercise" | ||
| msgstr "Latihan" | ||
|
|
||
| msgid "Solution to" | ||
| msgstr "Solusi untuk" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
|
|
||
| msgid "" | ||
| msgstr "" | ||
| "Project-Id-Version: Sphinx-Exercise\n" | ||
| "MIME-Version: 1.0\n" | ||
| "Content-Type: text/plain; charset=UTF-8\n" | ||
| "Content-Transfer-Encoding: 8bit\n" | ||
| "Language: it\n" | ||
| "Plural-Forms: nplurals=2; plural=(n != 1);\n" | ||
|
|
||
| msgid "Exercise" | ||
| msgstr "Esercizio" | ||
|
|
||
| msgid "Solution to" | ||
| msgstr "Soluzione a" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
|
|
||
| msgid "" | ||
| msgstr "" | ||
| "Project-Id-Version: Sphinx-Exercise\n" | ||
| "MIME-Version: 1.0\n" | ||
| "Content-Type: text/plain; charset=UTF-8\n" | ||
| "Content-Transfer-Encoding: 8bit\n" | ||
| "Language: ms\n" | ||
| "Plural-Forms: nplurals=2; plural=(n != 1);\n" | ||
|
|
||
| msgid "Exercise" | ||
| msgstr "Latihan" | ||
|
|
||
| msgid "Solution to" | ||
| msgstr "Penyelesaian untuk" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The f-string can be simplified by removing unnecessary braces. Change to
numfig_format = {"exercise": f"{translate('Exercise')} %s"}or use string concatenation:numfig_format = {"exercise": translate('Exercise') + " %s"}for better readability.