Difference between revisions of "JSON Resource Bundles"

From Lingoport Wiki
Jump to: navigation, search
Line 58: Line 58:
 
"key1":0,
 
"key1":0,
 
"key1": true
 
"key1": true
  +
</pre>
  +
  +
== Example of LRM Supported JSON Files ==
  +
  +
=== Typical ===
  +
This file, named resources_en.json, looks similar to a .properties file, with a key/value pair on each line. This is the most common and simple file to handle:
  +
<pre>
  +
{
  +
"access-groupAccess.Open": "Open",
  +
"access-groupAccess.InvitationOnly": "Invitation Only",
  +
"access-groupAccess.RequestToJoin": "Request To Join",
  +
"title-GET-REQUESTED-INVITATIONS-FAILED": "Get request status failed",
  +
"message-GET-REQUESTED-INVITATIONS-FAILED": "Could not get the status of request to join group",
  +
"title-REQUEST-JOIN-GROUP-FAIL": "Request to join failed",
  +
"message-REQUEST-JOIN-GROUP-FAIL": "Could not send request to join. Please try again",
  +
"all_volunteers" : "All Volunteers",
  +
"access-OPEN" : "Open",
  +
"access-INVITATION_ONLY" : "Invitation Only",
  +
"access-REQUEST_TO_JOIN" : "Request To Join"
  +
}
  +
</pre>
  +
  +
=== Typical with Keys for Comments===
  +
This file, named resources_en.json, looks similar to a .properties file, with a key/value pair on each line. This is the most common and simple file to handle:
  +
<pre>
  +
{
  +
"_description_groupAccess.Open", "To help users with the Open in the top window",
  +
"access-groupAccess.Open": "Open",
  +
"access-groupAccess.InvitationOnly": "Invitation Only",
  +
"access-groupAccess.RequestToJoin": "Request To Join",
  +
"title-GET-REQUESTED-INVITATIONS-FAILED": "Get request status failed",
  +
"message-GET-REQUESTED-INVITATIONS-FAILED": "Could not get the status of request to join group",
  +
"title-REQUEST-JOIN-GROUP-FAIL": "Request to join failed",
  +
"message-REQUEST-JOIN-GROUP-FAIL": "Could not send request to join. Please try again",
  +
"all_volunteers" : "All Volunteers",
  +
"access-OPEN" : "Open",
  +
"access-INVITATION_ONLY" : "Invitation Only",
  +
"access-REQUEST_TO_JOIN" : "Request To Join"
  +
}
 
</pre>
 
</pre>

Revision as of 19:41, 6 May 2016

JSON Resource Bundles

Well-formed JSON is required and specified by http://www.ietf.org/rfc/rfc4627.txt. JSON can in effect have any 'schema' and only some subset of JSON makes sense for Localization. JSON resource bundles are supported starting with LRM 2.1. The details of the LRM supported format is provided below.

JSON files are increasingly used with JavaScript as a means to capture strings to be translated.

JSON File Naming

In order to detect and import changes, LRM 2.1 requires JSON files to also adhere to the following standards. The json files must follow this naming convention: filename_<locale>.json or filename_<locale>_<country>.json. For example,

  • resources_en.json or resources_en_US.json,
  • resources_fr.json or resources_fr_FR.json, etc.

We strongly recommend file names should be unique, even if they are in different directories. LRM sends unique file names per prep kits. For example, if you have two JSON files under locales/ and under module1/locales, you could name them:

  • locales/common_resources_en.json
  • modules1/locales/module1_messages_en.json

JSON File Format

JSON files are like XML files: They can have complex schemas to represent complex objects. For translation purposes, LRM supports a restricted subset of the overall JSON format.


Arrays are not allowed in the context of JSON files as resource bundles

String references in the code, from an i18n point of view, is unmanageable for JSON arrays. In addition, many L10n vendors do not support JSON arrays. (Sample JSON files are located in LRM-Server-2.1/samples/JSON_Examples)

There is only one key/value per line.

  • Valid
      "key1":"This is my value for key1",
      "key2":"This is my value for key2"
  • Invalid
      "key1":"This is my value for key1","key2":"This is my value for key2"

End-object character (curly bracket) may not exist on the same line as a key/value

  • Valid
      "keys": {
         "key1":"This is my value for key1"
       }
  • Invalid
      "keys": {
         "key1":"This is my value for key1"}

Values associated with a key must be a string

Numeric and boolean values are not allowed.

  • Valid
      "key1":"0"
    • Invalid
      "key1":0,
      "key1": true

Example of LRM Supported JSON Files

Typical

This file, named resources_en.json, looks similar to a .properties file, with a key/value pair on each line. This is the most common and simple file to handle:

{
  "access-groupAccess.Open": "Open",
  "access-groupAccess.InvitationOnly": "Invitation Only",
  "access-groupAccess.RequestToJoin": "Request To Join",
  "title-GET-REQUESTED-INVITATIONS-FAILED": "Get request status failed",
  "message-GET-REQUESTED-INVITATIONS-FAILED": "Could not get the status of request to join group",
  "title-REQUEST-JOIN-GROUP-FAIL": "Request to join failed",
  "message-REQUEST-JOIN-GROUP-FAIL": "Could not send request to join. Please try again",
  "all_volunteers" : "All Volunteers",
  "access-OPEN" : "Open",
  "access-INVITATION_ONLY" : "Invitation Only",
  "access-REQUEST_TO_JOIN" : "Request To Join"
}

Typical with Keys for Comments

This file, named resources_en.json, looks similar to a .properties file, with a key/value pair on each line. This is the most common and simple file to handle:

{
  "_description_groupAccess.Open", "To help users with the Open in the top window",
  "access-groupAccess.Open": "Open",
  "access-groupAccess.InvitationOnly": "Invitation Only",
  "access-groupAccess.RequestToJoin": "Request To Join",
  "title-GET-REQUESTED-INVITATIONS-FAILED": "Get request status failed",
  "message-GET-REQUESTED-INVITATIONS-FAILED": "Could not get the status of request to join group",
  "title-REQUEST-JOIN-GROUP-FAIL": "Request to join failed",
  "message-REQUEST-JOIN-GROUP-FAIL": "Could not send request to join. Please try again",
  "all_volunteers" : "All Volunteers",
  "access-OPEN" : "Open",
  "access-INVITATION_ONLY" : "Invitation Only",
  "access-REQUEST_TO_JOIN" : "Request To Join"
}