Warning:
This wiki has been archived and is now read-only.

JSON+ITS

From ITS
Jump to: navigation, search

With the availability of Web services growing fast, and the use of REST becoming widespread in many areas, there is a need for a mechanism to allow the description of localization and internationalization features in JSON.

In many aspects JSON is comparable to XML, and it offers similar patterns of access.

ITS in JSON can be implemented using JSONPath (See http://goessner.net/articles/JsonPath/) expressions to specify the selector of an ITS rule. Note that the selectors could be implemented with other type of syntax like like JSONSelect (See http://jsonselect.org).

Prototype/Provisional Specifications

The prototype/provisional specifications for ITS in JSON are as follow:

  • Only the string values of the name/value pairs (string nodes) are affected by the ITS rules
  • By default, for the Translate data category:
    • The selectors are in JSONPath.
    • All the string nodes are translatable.
    • The itsRules object content is never translatable (i.e. even adding a rule to make itsRules translatable has no effect).

Rules can be embedded anywhere inside the JSON object. They must be define as an array named "itsRules". Each object in the array is composed of a selector object which holds the JSONPath expression for that rule, and a translate boolean object indicating whether the nodes for the given selector are translatable or not.

Example

The default behavior for the Translate data category on a JSON document is to translate the values of all text nodes.

{ "store": {
    "book": [ 
      { "category": "fiction",            <-- translate
        "author": "Herman Melville",      <-- translate
        "title": "Moby Dick",             <-- translate
        "isbn": "0-553-21311-3",          <-- translate
        "price": 8.99
      },
      { "category": "fiction",            <-- translate
        "author": "J. R. R. Tolkien",     <-- translate
        "title": "The Lord of the Rings", <-- translate
        "isbn": "0-395-19395-8",          <-- translate
        "price": 22.99
      }
    ],
    "bicycle": {
      "color": "red",                     <-- translate
      "price": 19.95
    }
  }
}

If a set of rules is given, they need to override the default. For example, below the first rule specifies that no node is translatable (overrides the default), then the second rule specify which nodes are translatable.

{ "itsRules": [
      {"selector":"$..*", "translate":false},
      {"selector":"$.store.book[*].title", "translate":true}
    ],
  "store": {
    "book": [ 
      { "category": "fiction",
        "author": "Herman Melville",
        "title": "Moby Dick",             <-- translate
        "isbn": "0-553-21311-3",
        "price": 8.99
      },
      { "category": "fiction",
        "author": "J. R. R. Tolkien",
        "title": "The Lord of the Rings", <-- translate
        "isbn": "0-395-19395-8",
        "price": 22.99
      }
    ],
    "bicycle": {
      "color": "red",
      "price": 19.95
    }
  }
}

Implementation

You can found a test implementation of a filter for JSON+ITS in the Okapi Acorn project: https://bitbucket.org/okapiframework/acorn/src