YAML Translation
YAML is a popular format for storing translations, especially in backend frameworks. Replexica handles YAML files with ease, whether they're flat or nested.
Setting Up
First, set up your i18n.json
config file:
{
"version": 1,
"locale": {
"source": "en",
"targets": ["ja", "ko", "zh"]
},
"buckets": {
"yaml": {
"include": ["locales/[locale].yml"]
}
}
}
This config tells Replexica:
- Your source language is English;
- You want to translate to Japanese, Korean, and Chinese;
- Your YAML files are in the
locales
folder, named by locale (e.g.,en.yml
,ja.yml
).
Translating
With your config set, run:
npx replexica@latest i18n
Replexica will process your YAML files: it'll read your source file, translate new or changed strings, and update your target files.
Root Key Option
Some projects use a root key in their YAML files to namespace all translations. Ruby on Rails, for example, uses the locale code as the root key. Replexica supports this with the yaml-root-key
bucket type.
Here's how to set it up:
{
"version": 1,
"locale": {
"source": "en",
"targets": ["fr", "de", "it"]
},
"buckets": {
"yaml-root-key": {
"include": ["locales/[locale].yml"]
}
}
}
With this setup, Replexica expects your YAML files to look like this:
en:
greeting: "Hello"
farewell: "Goodbye"
Replexica will maintain this structure in all translations:
fr:
greeting: "Bonjour"
farewell: "Au revoir"
Replexica preserves these YAML-specific features during translation, ensuring your files remain clean and maintainable.
Pro Tips
Nested Structures: Replexica handles nested YAML structures with ease:
yamlnavigation: home: Home about: team: Our Team mission: Our Mission
Multi-line Strings: YAML's multi-line string support is preserved:
yamllong_text: | This is a long piece of text that spans multiple lines. Replexica will translate it while maintaining the format.
Placeholders: Replexica understands and preserves placeholders in your strings:
yamlwelcome: "Welcome, %{name}!"
By leveraging these features, you can maintain a clean, readable, and easily translatable i18n infrastructure for your project, regardless of the framework you're using.