Skip to content
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

Internationalisierung / Lokalisierung mit gettext #154

Open
wants to merge 25 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d5a88f2
feat(i18n): implement loading and installing of translations
MHajoha Jan 20, 2025
8baa1b1
feat(i18n): add commands to manage .po(t) files
MHajoha Jan 23, 2025
8d36fe0
feat(i18n): compile .po files during package build
MHajoha Jan 23, 2025
d38c7e2
fix(i18n): use a ContextVar for the current state
MHajoha Jan 27, 2025
aba75ea
feat(i18n): add german translations to the example
MHajoha Jan 27, 2025
ce56c22
feat(i18n): warn when .mo files already exist
MHajoha Jan 27, 2025
9c6376b
feat(i18n): separate state by domain
MHajoha Feb 19, 2025
3f8167a
refactor: introduce NewTypes for domain and BCP 47 lang
MHajoha Feb 20, 2025
b78f287
feat: improve i18n update command
MHajoha Feb 20, 2025
0c82e64
feat(i18n): implement deferred translation
MHajoha Feb 21, 2025
b4ffe06
feat(i18n): implement n-, p- and npgettext as well as d- variants
MHajoha Feb 21, 2025
6c15bc1
feat(i18n): support TranslatableString in form DSL and attempt ui
MHajoha Feb 24, 2025
bfd5370
chore: remove unused AttemptUiPart and _merge_uis
MHajoha Feb 24, 2025
9fae66f
feat: support calling .format() on deferred strings
MHajoha Feb 24, 2025
209a4aa
docs: make i18n example more exhaustive
MHajoha Feb 24, 2025
65e6a17
test: ignore examples during collection
MHajoha Feb 25, 2025
1871129
chore: silence S603 and S607 in builder
MHajoha Feb 25, 2025
675a443
docs(i18n): add i18n to mkdocs and improve docstrings
MHajoha Feb 25, 2025
932e143
refactor(i18n): default loglevel to INFO
MHajoha Feb 25, 2025
4832459
refactor(i18n): dedupe _get_package_owning_module now that #152 is in…
MHajoha Feb 25, 2025
37cba5f
docs: add and improve i18n cli help
MHajoha Mar 3, 2025
98d73a2
refactor: translate ui parts in _export_attempt
MHajoha Mar 4, 2025
12cb709
refactor: disallow TranslatableStrings in form element and condition …
MHajoha Mar 4, 2025
409bfe5
refactor: rethink i18n function names
MHajoha Mar 4, 2025
c2e75e1
chore: increment version number
MHajoha Mar 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/i18n.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: questionpy.i18n
2 changes: 2 additions & 0 deletions examples/i18n/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__pycache__
/dist
146 changes: 146 additions & 0 deletions examples/i18n/locale/de.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# German translations for @local/i18n.
# Copyright (C) 2025 ORGANIZATION
# This file is distributed under the same license as the @local/i18n
# project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2025.
#
msgid ""
msgstr ""
"Project-Id-Version: @local/i18n 0.1.0\n"
"Report-Msgid-Bugs-To: Jane Doe <[email protected]>\n"
"POT-Creation-Date: 2025-02-24 15:42+0100\n"
"PO-Revision-Date: 2025-02-24 15:56+0100\n"
"Last-Translator: \n"
"Language-Team: de <[email protected]>\n"
"Language: de\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"Generated-By: Babel 2.17.0\n"
"X-Generator: Poedit 3.5\n"

#: python/local/i18n/__init__.py:14
msgid "Status of the file"
msgstr "Status der Datei"

#: python/local/i18n/__init__.py:14
msgctxt "File"
msgid "Opened"
msgstr "Geöffnet"

#: python/local/i18n/__init__.py:16
msgid "Status of the amusement park"
msgstr "Status des Freizeitparks"

#: python/local/i18n/__init__.py:16
msgctxt "Amusement Park"
msgid "Opened"
msgstr "Eröffnet"

#: python/local/i18n/__init__.py:20
msgid "npgettext combines pluralization support and contextualization."
msgstr "npgettext erlaubt sowohl Pluralisierung als auch Kontextualisierung."

#: python/local/i18n/__init__.py:21
#, python-brace-format
msgctxt "Home Depot"
msgid "There is a light."
msgid_plural "There are {} lights!"
msgstr[0] "Da ist eine Lampe."
msgstr[1] "Da sind {} Lampen!"

#: python/local/i18n/__init__.py:23
#, python-brace-format
msgctxt "Picard"
msgid "There is a light."
msgid_plural "There are {} lights!"
msgstr[0] "Da ist ein Licht."
msgstr[1] "Da sind {} Lichter!"

#: python/local/i18n/__init__.py:27
msgid "First Option"
msgstr "Erste Option"

#: python/local/i18n/__init__.py:28
msgid "Second Option"
msgstr "Zweite Option"

#: python/local/i18n/__init__.py:29
msgid "Third Option"
msgstr "Dritte Option"

#. This comment will be shown in the .pot file.
#: python/local/i18n/__init__.py:35
msgid "This is a localized FormModel."
msgstr "Das ist ein lokalisiertes FormModel."

#: python/local/i18n/__init__.py:36
msgid ""
"The FormModel is defined before any initialization, so message translation "
"needs to be deferred!"
msgstr ""
"Das FormModel wird vor jeder Initialisierung definiert, deshalb müssen "
"Übersetzungen später geschehen!"

#: python/local/i18n/__init__.py:40
msgid "This is a text_input, and its label is localized!"
msgstr "Das ist ein text_input, und sein Label ist lokalisiert!"

#: python/local/i18n/__init__.py:42
msgid "Even this placeholder is localized!"
msgstr "Selbst dieser Platzhalter ist lokalisiert!"

#: python/local/i18n/__init__.py:43
msgid "Now you can get help in your language!"
msgstr "Jetzt kannst du in deiner Sprache Hilfe erhalten!"

#: python/local/i18n/__init__.py:47
#, python-brace-format
msgid "Choose exactly one option."
msgid_plural "Choose exactly {} options."
msgstr[0] "Wähle genau eine Option."
msgstr[1] "Wähle genau {} Optionen."

#: python/local/i18n/__init__.py:50
msgid "This section shows contextualized messages."
msgstr "Dieser Abschnitt zeigt kontextualisierte Übersetzungen."

#: python/local/i18n/__init__.py:63
msgid "Programmatic translation!"
msgstr "Programmatische Übersetzung!"

#. This comment will be shown in the .pot file.
#: templates/formulation.xhtml.j2:4
msgid "This string should be localized!"
msgstr "Diese Zeichenkette sollte lokalisiert sein!"

#: templates/formulation.xhtml.j2:5
msgid "One Thing"
msgid_plural "More Things"
msgstr[0] "Eine Sache"
msgstr[1] "Mehrere Sachen"

#: templates/formulation.xhtml.j2:7
msgctxt "Context 1"
msgid "My Message"
msgstr "Meine Nachricht in Kontext 1"

#: templates/formulation.xhtml.j2:7
msgctxt "Context 2"
msgid "My Message"
msgstr "Meine Nachricht in Kontext 2"

#: templates/formulation.xhtml.j2:10 templates/formulation.xhtml.j2:11
msgctxt "Context 1"
msgid "One Thing"
msgid_plural "More Things"
msgstr[0] "Eine Sache in Kontext 1"
msgstr[1] "Mehrere Sachen in Kontext 1"

#: templates/formulation.xhtml.j2:12 templates/formulation.xhtml.j2:13
msgctxt "Context 2"
msgid "One Thing"
msgid_plural "More Things"
msgstr[0] "Eine Sache in Kontext 2"
msgstr[1] "Mehrere Sachen in Kontext 2"
145 changes: 145 additions & 0 deletions examples/i18n/locale/en.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# English translations for @local/i18n.
# Copyright (C) 2025 ORGANIZATION
# This file is distributed under the same license as the @local/i18n
# project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2025.
#
msgid ""
msgstr ""
"Project-Id-Version: @local/i18n 0.1.0\n"
"Report-Msgid-Bugs-To: Jane Doe <[email protected]>\n"
"POT-Creation-Date: 2025-02-24 15:42+0100\n"
"PO-Revision-Date: 2025-02-24 15:34+0100\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: en\n"
"Language-Team: en <[email protected]>\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.17.0\n"

#: python/local/i18n/__init__.py:14
msgid "Status of the file"
msgstr ""

#: python/local/i18n/__init__.py:14
msgctxt "File"
msgid "Opened"
msgstr ""

#: python/local/i18n/__init__.py:16
msgid "Status of the amusement park"
msgstr ""

#: python/local/i18n/__init__.py:16
msgctxt "Amusement Park"
msgid "Opened"
msgstr ""

#: python/local/i18n/__init__.py:20
msgid "npgettext combines pluralization support and contextualization."
msgstr ""

#: python/local/i18n/__init__.py:21
#, python-brace-format
msgctxt "Home Depot"
msgid "There is a light."
msgid_plural "There are {} lights!"
msgstr[0] ""
msgstr[1] ""

#: python/local/i18n/__init__.py:23
#, python-brace-format
msgctxt "Picard"
msgid "There is a light."
msgid_plural "There are {} lights!"
msgstr[0] ""
msgstr[1] ""

#: python/local/i18n/__init__.py:27
msgid "First Option"
msgstr ""

#: python/local/i18n/__init__.py:28
msgid "Second Option"
msgstr ""

#: python/local/i18n/__init__.py:29
msgid "Third Option"
msgstr ""

#. This comment will be shown in the .pot file.
#: python/local/i18n/__init__.py:35
msgid "This is a localized FormModel."
msgstr ""

#: python/local/i18n/__init__.py:36
msgid ""
"The FormModel is defined before any initialization, so message "
"translation needs to be deferred!"
msgstr ""

#: python/local/i18n/__init__.py:40
msgid "This is a text_input, and its label is localized!"
msgstr ""

#: python/local/i18n/__init__.py:42
msgid "Even this placeholder is localized!"
msgstr ""

#: python/local/i18n/__init__.py:43
msgid "Now you can get help in your language!"
msgstr ""

#: python/local/i18n/__init__.py:47
#, python-brace-format
msgid "Choose exactly one option."
msgid_plural "Choose exactly {} options."
msgstr[0] ""
msgstr[1] ""

#: python/local/i18n/__init__.py:50
msgid "This section shows contextualized messages."
msgstr ""

#: python/local/i18n/__init__.py:63
msgid "Programmatic translation!"
msgstr ""

#. This comment will be shown in the .pot file.
#: templates/formulation.xhtml.j2:4
msgid "This string should be localized!"
msgstr ""

#: templates/formulation.xhtml.j2:5
msgid "One Thing"
msgid_plural "More Things"
msgstr[0] ""
msgstr[1] ""

#: templates/formulation.xhtml.j2:7
msgctxt "Context 1"
msgid "My Message"
msgstr ""

#: templates/formulation.xhtml.j2:7
msgctxt "Context 2"
msgid "My Message"
msgstr ""

#: templates/formulation.xhtml.j2:10 templates/formulation.xhtml.j2:11
#, fuzzy
msgctxt "Context 1"
msgid "One Thing"
msgid_plural "More Things"
msgstr[0] ""
msgstr[1] ""

#: templates/formulation.xhtml.j2:12 templates/formulation.xhtml.j2:13
#, fuzzy
msgctxt "Context 2"
msgid "One Thing"
msgid_plural "More Things"
msgstr[0] ""
msgstr[1] ""
Loading
Loading