Internationalization
This document is for contributors and translators.
Public API usage is covered in i18n/doc.go; avoid duplicating info across both files.
Primer for translators¶
If you only want to translate strings without touching code, use Codeberg’s Weblate:
- Project: https://translate.codeberg.org/projects/pixivfe/
- Getting started: https://docs.codeberg.org/codeberg-translate/getting-started/
Placeholders and formatting¶
- Translations may contain placeholders like
{{.Name}}. - Keep these placeholders exactly as written, including the curly braces and the dot.
- You can freely reorder placeholders within the translated text.
- Example:
{{.Count}} items selectedcan become選択されたアイテム: {{.Count}}in Japanese. - Do not include HTML, write plain text.
Formatting uses Go's text/template package. Digits and number separators are not localised automatically.
Style tips¶
- Be clear and concise, match the tone of the UI.
- Prefer consistent terminology across the app. TODO: Create a catalogue for this purpose.
- If a single English word is ambiguous, ask for more context or expect a contextual variant to be added using
TrCorTrNC, for example contextmenuversusstatus.
Extraction workflow¶
We use a Go AST-based extractor. Make sure to regenerate templ code before extracting.
Developer commands via build.sh:
| Text Only | |
|---|---|
Typical flow:
- Regenerate templ code and the POT:
./build.sh i18n_extract - Merge into all locales:
./build.sh i18n_merge - Validate:
./build.sh i18n_validate - Commit changes to the POT and any updated PO files.
Gitlab CI TODO¶
- Add a job that:
- Runs
./build.sh i18n_extractand fails if it produces a git diff to the POT. - Runs
./build.sh i18n_mergeand./build.sh i18n_validate. - Commits updated PO files in a separate MR?
- NOTE: Ensure gettext tools
msgmergeandmsgfmtare available in the runner image.
Notes¶
- We intentionally do not compile or load
.mofiles. Parsing.pois sufficient and keeps the build simpler. If we later measure performance issues attributable to.poparsing, we can revisit. - Tag translations for user-generated content live in
i18n/data/tag_translations.yamland are surfaced viai18n.TrTagName. They are intentionally separate from UI message catalogues and may move to another package later.
References¶
gettext format:
- https://docs.weblate.org/en/latest/formats/gettext.html#example-files
- https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html
- http://ftp.twaren.net/Unix/GNU/old-gnu/Manuals/gettext-0.11.2/html_node/gettext_9.html
templ guides:
- Implicit
ctx context.Contextvariable: https://templ.guide/syntax-and-usage/context/ - Implicit
children templ.Componentvariable: https://templ.guide/syntax-and-usage/template-composition/#children templ.NopComponent: https://pkg.go.dev/github.com/a-h/templ#pkg-variables