Yaml

Last updated: April 11, 2024Author: Jakub Pomykała

YAML is a human-readable data serialization format commonly used for configuration files and data exchange. SimpleLocalize supports importing and exporting translations in YAML format with various options to structure the file. By default, the system recognizes nested keys in YAML files for importing translations.

File format example

Basic YAML file example with translations in English.

hello-world: Hello world!
home.interface.signup: Signup
home.interface.email: Email address
home.interface.password: Password

Nested keys in YAML file example:

hello-world: Hello world!
home:
  interface:
    signup: Signup
    email: Email address
    password: Password

Importing both files will create the following keys:

  • hello-world
  • home.interface.signup
  • home.interface.email
  • home.interface.password

Nested keys are automatically recognized and joined with a dot to create a key name.

Multi-language file

Use MULTI_LANGUAGE option to import or export a translation file with multiple languages, where each language is separated by a language code. In the example below, translations are grouped by language code en and pl.

en:
  hello-world: Hello world!
  home.interface.signup: Signup
  home.interface.email: Email address
  home.interface.password: Password
pl:
  hello-world: Witaj świecie!
  home.interface.signup: Zarejestruj się
  home.interface.email: Adres email
  home.interface.password: Hasło

Nested translation keys

Use WRITE_NESTED option to export translations as nested keys in YAML files.

hello-world: Hello world!
home:
  interface:
    signup: Signup
    email: Email address
    password: Password

Nested language keys

Combine LANGUAGES_NESTED, MULTI_LANGUAGE, WRITE_NESTED as import or export options resulting in nested translations and language keys in one file. In the example below, en and pl are nested under translations.

hello-world:
  en: Hello world!
  pl: Witaj świecie!
home:
  interface:
    signup:
      en: Signup
      pl: Zarejestruj się
    email:
      en: Email address
      pl: Adres email
    password:
      en: Password
      pl: Hasło

Upload with CLI

Upload YAML files with CLI using the following command:

simplelocalize upload --apiKey <PROJECT_KEY> \
  --uploadFormat yaml \
  --uploadPath ./translations_{lang}.yaml

CLI will find all files matching the pattern ./translations_*.yaml and upload them to the SimpleLocalize project. Language code is extracted from the {lang} placeholder and used to set the language of the translations.

Learn more about uploading translations with CLI.

Upload with API

curl
    --request POST \
    --url 'https://api.simplelocalize.io/api/v2/import?uploadFormat=yaml' \
    --header 'x-simplelocalize-token: <API_KEY>' \
    --form file=@/path/to/your/file.yaml

Learn more about importing translations with API.

Download with CLI

simplelocalize download --apiKey <PROJECT_KEY> \
  --downloadFormat yaml \
  --downloadPath ./translations_{lang}.yaml

Learn more about downloading translations with CLI.

Download with API

curl
    --request GET \
    --url https://api.simplelocalize.io/api/v4/export?downloadFormat=yaml \
    --header 'x-simplelocalize-token: <API_KEY>'

Learn more about exporting translations with API