Translations¶
MkDocs Quiz supports internationalization (i18n) with multiple languages for all user-facing text. Language codes follow MkDocs Material conventions: 2-letter ISO 639-1 codes (e.g., fr, de) with hyphens for regional variants (e.g., pt-BR, zh-TW).
For example, this page uses French:
Info
Les résultats du quiz sont enregistrés dans le stockage local de votre navigateur et persisteront entre les sessions.
Progression du quiz
0 / 0 questions répondues (0%)
0 correctes
Built-in Languages¶
- English (
en) - Default - Chinese (Simplified) (
zh) - Esperanto (
eo) - French (
fr) - German (
de) - Hindi (
hi) - Indonesian (
id) - Japanese (
ja) - Korean (
ko) - Norwegian (
no) - Portuguese (Brazilian) (
pt-BR) - Spanish (
es) - Swedish (
sv)
Want to add a language?
See Contributing Translations to add a new language.
Configuration¶
Language Resolution Order¶
MkDocs Quiz automatically detects the language (later overrides earlier):
- Default:
en - Theme language:
theme.language - Language selector: Active language from
extra.alternate(Material multi-language sites) - Plugin config:
mkdocs_quiz.language - Pattern matching:
mkdocs_quiz.language_patterns - Page frontmatter:
quiz.language(highest priority)
If using Material's theme language or language selector, MkDocs Quiz automatically uses the correct language.
Use Theme Language¶
theme:
name: material
language: fr # MkDocs Quiz uses this automatically
plugins:
- mkdocs_quiz # No language config needed
Use Theme Language Selector¶
See the mkdocs material docs for more information.
theme:
name: material
extra:
alternate: # MkDocs Quiz uses this automatically
- name: English
link: /en/
lang: en
- name: Français
link: /fr/
lang: fr
plugins:
- mkdocs_quiz # No language config needed
Set Global Language via Plugin Config¶
plugins:
- mkdocs_quiz:
language: fr
Set Plugin Language by Path¶
plugins:
- mkdocs_quiz:
language_patterns:
- pattern: "fr/**/*"
language: fr
- pattern: "pt/**/*"
language: pt-BR
Set Per-Page Language¶
---
quiz:
language: fr
---
Custom Translations¶
Add a New Language¶
- Create translation file:
mkdocs-quiz translations init ja
This creates ja.po with all strings to translate.
- Translate the strings:
Edit the .po file using a text editor or Poedit:
msgid "Submit"
msgstr "送信"
msgid "Correct answer!"
msgstr "正解!"
- Configure it:
plugins:
- mkdocs_quiz:
language: ja
custom_translations:
ja: translations/ja.po
Override Built-in Text¶
plugins:
- mkdocs_quiz:
language: en
custom_translations:
en: translations/custom.po
# translations/custom.po
msgid "Submit"
msgstr "Check Answer"
msgid "Outstanding! You aced it!"
msgstr "Perfect score! You're a quiz master!"
Troubleshooting¶
Translation not loading¶
- Check file path in
custom_translationsis relative tomkdocs.yml - Verify
.pofile format is valid - Run
mkdocs serve -vfor verbose output
English text appears¶
- Verify language code is correct
- Check pattern matching if using
language_patterns - Ensure all strings in
.pofile have translations (non-emptymsgstr)
Special characters not displaying¶
Ensure your .po file has UTF-8 encoding:
"Content-Type: text/plain; charset=UTF-8\n"
Technical Details¶
- Format: Standard gettext
.pofiles compatible with Poedit, Weblate, Crowdin - Loading: Translations load at build time (no runtime overhead)
- Fallback: Missing translations fall back to English
- JavaScript: Translations embedded as JSON in generated HTML
Contributing¶
Want to add support for your language? See Contributing Translations for the complete guide.