JSON localizations in Respresso

Many web based localization tools use JSON files as the source of the localizations. Thus, there are many approaches to store localizations in one or multiple JSON files. Respresso takes a fairly simple one by using a separate JSON file for each localization language.

The internal structure of the JSON is defined by two factors:

  1. The localization key
  2. and the Flow config

Respresso's JSON generator will split the localization key along the delimiters configured in the Flow and the parts will be used to generate a nested structure in the JSON. By default, the Flow is configured in a way to generate a structured JSON using the . character as the delimiter and another one with a flat key-value variant. The prior is placed in the json sync group while the latter is placed jsonflat group.

Handling variables using custom placeholders

Respresso supports cross-platform localization variables, although JSON does not, as it is not a localization format.
This is why you need to define the desired placeholder format , to match the localization tool you are using.
If you do not specify a custom placeholder, Respresso's default {{ variable_name }} will be used, that is equivalent to the {{ {{key}} }} placeholder pattern. Please check the common placeholders section for common examples.

Please note that if you don't add a variable to Respresso, just type it in the translation, it won't be modified or transformed. It will be passed through as plain text. (You are free to use any variable format this way, but you won't be able to take advantage of some features, like formatted localization access with type specific argument list in Swift or cross-platform variable transformation.)

Configure global placeholders

Your localization library of choice - e.g. i18next - may require a different variable placeholder format. You can easily change the global placeholder pattern by following the instructions in the global variable placeholder overrides section. Just make sure, you use the json, web or the all format key, otherwise it won't have any effect on the generated JSON files.

Configure single variable placeholder

Most of the time, you will be fine using the global placeholder override, but in some cases you may want to signal something extra to the localization lib you are using. E.g. use a custom formatting function or ask the tool to skip sanitization of the localized string as it contains HTML elements.

Respresso lets you do this by overriding a single variable's placeholder pattern. To do so, follow the instructions in the single variable placeholder overrides section. Similarly to the global config you need to make sure, you use the json, web or the all format key, otherwise it won't have any effect on the generated JSON files.
E.g. when using i18next, you can use the {- {{key}} } placeholder pattern to skip escaping or use a custom formatter function with the { {{key}}, myFormattingFunction } pattern.

Example for the generated JSON files

Let's assume you have a single localization with two registered variables in Respresso, and you set the web: { {{key}} } global placeholder pattern override:
mainScreen.accountBalance: Current balance: {{ balance }} ({{ currency }})

It will output 1 file for each language like this in the json sync group:

  "mainScreen" : {
    "accountBalance" : "Current balance: { balance } ({ currency })"

It will also output 1 file for each language like this in the jsonflat sync group:

  "mainScreen.accountBalance" : "Current balance: { balance } ({ currency })"

Importing JSON files

If you want to import existing JSON localization files, you can drag and drop it to the desired language. To do this, follow the steps described in the localization import section.
Please note that the imported JSON must contain only one language. All values will be imported as translations of the currently selected language.

Importing structured JSON files

As mentioned before, JSON localizations can have multiple forms, so it's really hard to import all of them. Thus, currently, Respresso has the following limitations:

  • Array values will raise an error. Make sure, you remove them before importing the JSON file.
  • As plurals are currently not supported, they will be imported as separate localization keys.
  • Imported keys will be generated from the JSON structure where the value is found, nested keys are joined with the separator provided in the import dialog. Leaving it empty will result in the . character being used as the default separator.