JSON - SimpleLocalize

Last updated: October 16, 2024Author: Jakub Pomykała
simplelocalize-json
File format value
simplelocalize-json

SimpleLocalize JSON is a universal format that can be used to import and export translations from different localization programs. It works well with FormatJS CLI and can be used to import translations from different localization programs. Learn more about integrating FormatJS with SimpleLocalize.

File format example

Here is an example of a SimpleLocalize JSON file:

{
  "translation_key": {
    "message": "my localized message"
  },
  "second_translation_key": {
    "defaultMessage": "my localized message from FormatJS CLI output",
    "description": "Your message to translators. It will also show up in the translation editor"
  },
  "translation_key_with_pluralization": {
    "message": "You have {itemCount, plural, =0 {no items} one {1 item} other {{itemCount} items}}."
  }
}

Metadata

The SimpleLocalize JSON format supports the following metadata:

  • message - localized message (optionally defaultMessage can be used instead)
  • description - description of the translation key
  • charactersLimit - character limit for the translation key, use -1 to remove limit
  • tags - tags for the translation key, use [] to remove tags

Example SimpleLocalize JSON with metadata:

{
  "say_hi": {
    "message": "Cześć!",
    "description": "Welcome message",
    "charactersLimit": 21,
    "tags": ["my-tag-1", "my-tag-2"]
  },
  "say_goodbye": {
    "message": "Do widzenia!",
    "description": "Farewell message",
    "charactersLimit": 37,
    "tags": ["my-tag-1"]
  }
}

If you skip any metadata field, it won't remove the existing value in SimpleLocalize. For example, if you want to remove the description field, you need to set it to an empty string.

Import default messages

If you want to import messages into SimpleLocalize using CLI, you need to pass a language key as an argument. The language key is used to determine the language of the imported messages. See an example CLI command below:

simplelocalize upload --apiKey <PROJECT_KEY> \
  --uploadFormat simplelocalize-json \
  --uploadPath ./extracted.json \
  --languageKey en

Add --overwrite argument to update the existing translations, otherwise, only new ones will be added.

Import descriptions

By default, CLI imports descriptions as Code Descriptions. Use --uploadOptions UPDATE_DESCRIPTIONS parameter to push values from 'description' fields as translator descriptions. See an example CLI command below:

simplelocalize upload --apiKey <PROJECT_KEY> \
  --uploadFormat simplelocalize-json \
  --uploadPath ./extracted.json \
  --languageKey en

Code descriptions differ from the descriptions in the translation editor. They are used to provide additional context for translators from the code perspective, and they cannot be edited or cleared in the translation editor. They are updated only by uploading new translations via CLI.

Learn more about uploading translations with CLI.

Resources

Was this helpful?