Certain JSON files can be imported via eclypse's import functionality. This article details how your JSON file needs to be structured for eclypse to recognize it.
Drag and drop or select a json file within the import interface. Click the "Configure" button to specify your JSON file structure. If the file type is not recognized automatically, you can manually select the file type as well.
You will see some configurable options:
Basic JSON file
Your JSON file has to be a dictionary of key/value pairs as shown below.
{ "key_1": "translation_1", "key_2": "translation_2" }
File Encoding
When importing a JSON file, eclypse accepts UTF-8 or UTF-16 encoding. UTF-16 encoded files can be encoded with big-endian or little-endian byte order mark. Choose the appropriate file encoding for your file. To learn more about UTF encoding, read here.
Plural Handling
The JSON file can contain plural keys. Eclypse recognizes two types of plural formatting for JSON files.
ICU Style
Full specifications of ICU message formatting can be found here. However, eclypse supports a limited set of ICU capabilities. This is because only a portion of the ICU message formatting is applicable to the translation context. Your plurals can be encoded in a few different ways.
Supported Variation: 1
{ "key_1": "translation_1", "plural_key_2": "{count, plural, one {Delete item} other {Delete items}}" }
Supported Variation: 2
{ "key_1": "translation_1", "plural_key_2": "{count, plural, one {Delete {count} item} other {Delete {count} items}}" }
Supported Variation: 3
{ "key_1": "translation_1", "plural_key_2": "Delete {count, plural, one {{count} item} other {{count} items}}" }
Supported Variation: 4
{ "key_1": "translation_1", "plural_key_2": "Delete {count, number} {count, plural, one {{count} item} other {{count} items}}" }
JSON style
A JSON file with JSON plurals looks like this:
{ "key_1": "translation_1", "plural_key_2": { "one": "Delete item", "other": "Delete %d items" } }
Placeholder Pattern
Placeholder pattern depends on which plural handling method you choose. If your JSON file is encoded with ICU plurals, then you have to use the ICU Placeholder pattern. This is because, ICU Style format specifiers are tightly integrated with the ICU plural handling. On the other hand, if your file is using JSON to encode the plurals, then you have 2 options for specifying the placeholder pattern.
Printf Style
Printf refers to a control parameter used by a class of functions in the input/output libraries of C and many other programming languages. In the simplest form, your placeholders should be encoded as shown below:
Hello %s! You have %d new messages.
Read the full list of recognized printf format specifiers here.
Eclypse Style
Eclypse employs a propriety pattern that is similar to printf. This pattern needs to be enclosed in square brackets and can contain a label. The label information is optional; however, if you are planning to export data from eclypse in ICU format, then using labels can make your output more readable. In the simplest form, your placeholders should be encoded as shown below:
Hello [%s]! You have [%d] new messages.
or optionally including labels:
Hello [%s:person_name]! You have [%d:number_of_messages] new messages.
Read the full list of recognized printf format specifiers here.