...
Our configuration now explicitly states the node names we want to translate:
...
Example 3 - Translate nodes in arrays
In this example, we have the translatable nodes in an array below “data”.
Code Block |
---|
{
"data": [
{
"id": 1002,
"description": "Please review the conditions above.",
"text": "The conditions need to be accepted."
"fontSize": "11px",
"action": "none",
},
{
"id": 1019,
"description": "Thank you for submitting your request.",
"text": "Your request is submitted."
"fontSize": "11px",
"action": "none",
}
} |
Our configuration requires an array selector:
...
The [*] means that we want to select every element of the “data” array. Then we specify the nodes in each array object we want to translate.
Example 4 - Extract meta-information with texts
Let’s look at a JSON file that contains product descriptions. With each product there is a title, a description, an identifier and some more meta-information.
...
You can also pull data and save to each segment’s custom fields like this:
...
Example
...
5 - Handling plain text and HTML content
JSON files may contain HTML formatted content. Our file contains “text” nodes that are not html and “html” nodes that are, well, HTML.
...
We achieve this by simply defining two JSON paths. One for our plain text nodes and one for our HTML formatted nodes:
...
Example
...
6 - Using advanced node selectors
Check out the file below. Each product has “status” field. We only want to translate if its value is “yes”!
...
It checks that the product object has a “translate” property with value “yes”: @.translate == 'yes'
. The @
character represents the object in the array we look at.
...
Example
...
7 - Extract meta-data from any location in the file
We already discussed an example earlier on how to extract meta-information. These examples were simple in that the meta-information was on the same object level as the actual text to translate.
...