Skip to content

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:

json
{
  "version": 1,
  "locale": {
    "source": "en",
    "targets": ["ja", "ko", "zh"]
  },
  "buckets": {
    "yaml": {
      "include": ["locales/[locale].yml"]
    }
  }
}

This config tells Replexica:

  1. Your source language is English;
  2. You want to translate to Japanese, Korean, and Chinese;
  3. Your YAML files are in the locales folder, named by locale (e.g., en.yml, ja.yml).

Translating

With your config set, run:

bash
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:

json
{
  "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:

yaml
en:
  greeting: "Hello"
  farewell: "Goodbye"

Replexica will maintain this structure in all translations:

yaml
fr:
  greeting: "Bonjour"
  farewell: "Au revoir"

Replexica preserves these YAML-specific features during translation, ensuring your files remain clean and maintainable.

Pro Tips

  1. Nested Structures: Replexica handles nested YAML structures with ease:

    yaml
    navigation:
      home: Home
      about:
        team: Our Team
        mission: Our Mission
  2. Multi-line Strings: YAML's multi-line string support is preserved:

    yaml
    long_text: |
      This is a long piece of text
      that spans multiple lines.
      Replexica will translate it
      while maintaining the format.
  3. Placeholders: Replexica understands and preserves placeholders in your strings:

    yaml
    welcome: "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.