JSON - Multi Language

Last updated: June 17, 2022Author: Jakub Pomykała

One of the most common JSON format for apps and software localization is JSON file with all translations as shown below. It's easy to use because you can fetch only one file and use all translations.

File format example

{
  "en": {
    "home.interface.signup": "Signup",
    "home.interface.email": "Email",
    "home.interface.password": "Password"
  },
  "pl": {
    "home.interface.signup": "Zarejestruj się",
    "home.interface.email": "Adres email",
    "home.interface.password": "Hasło"
  }
}

You can also use single-language-json format to download only needed translation messages for the requested language key.

SimpleLocalize also recognizes nested JSON keys, as shown below.

{
  "en": {
    "home": {
      "interface": {
        "signup": "Signup",
        "email": "Email address",
        "password": "Password"
      }
    }
  },
  "pl": {
    "home": {
      "interface": {
        "signup": "Zarejestruj się",
        "email": "Adres email",
        "password": "Hasło"
      }
    }
  }
}

Above JSON will result with:

  • home.interface.signup,
  • home.interface.email,
  • home.interface.password translation keys in Translation Editor.

Message interpolation

Pluralization and variables formatting is done by your translation library (e.g. FormatJS) You can use a {key} argument for placing a value into the message. The key is looked up in the input data, and the string is interpolated with its value.

Formatting

{
  "en": {
    "home": {
        "welcome": "Hello, {name}!"
      }
  }
}

Your variable: name.

Pluralization

{
  "en": {
    "home": {
        "message": "I have {numCats, number} cats.",
        "notifications": "You have {itemCount, plural, =0 {no items} one {1 item} other {{itemCount} items}}."
      }
  }
}

Learn more about ICU message syntax.

Upload translation files

Upload with command-line tool

simplelocalize upload --apiKey <PROJECT_KEY> \
  --uploadFormat multi-language-json \
  --uploadPath ./translations.json

Learn more about uploading translations with CLI.

Import with REST API

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

Learn more about importing translations with API.

Download translation files

Download with command-line tool

simplelocalize download --apiKey <PROJECT_KEY> \
  --downloadFormat multi-language-json \
  --downloadPath ./translations.json

To download translations with nested keys use option WRITE_NESTED. See all download options.

simplelocalize download --apiKey <PROJECT_KEY> \
  --downloadFormat multi-language-json \
  --downloadPath ./translations.json \
  --downloadOptions WRITE_NESTED

Learn more about downloading translations with CLI.

Export with REST API

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

Learn more about exporting translations with API.