Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This page is a tutorial for configuring monolingual JSON files.

Table of Contents

Prerequisites

This tutorial uses JSON configurations with:

...

Example 1 - Translate all content

Let’s start with the simple example below. Our objective is to translate all the text content:

...

And we can even make it simpler with this configuration. We put * (putting nothing has the same effect) into the path field (which selects nodes at the root level) and then choose to translate all the children of those root nodes.

...

In both cases we extract these texts:

...

Example 2 - Translate certain nodes only

In this example, we want to translate the “text”, “title” and “options” node but not all the other ones such as the “key”.

...

Our configuration now explicitly states the node names we want to translate:

...

Example 3 - 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 4 - 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 5 - 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 means to

...

Example 6 - 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.

In the JSON below we want to translate the “text” properties and attach to it the meta-information “key” and “catalog”. The “key” is one object level above “text” and the “catalog” is at the root. How do we select those fields?

Code Block
{
	"products": [
	
		{
			"key": "1000",
			"product": { "text": "This is a product" }
		},
		{
			"key": "1000",
			"product": { "text": "This is a product" }
		}
	],
	
	
	"catalog": "Summer products"
}

The configuration is:

...

  • We use the ^ character to tell the system that the property named key is one level further up in the hierarchy relative to the translatable text.

  • We use the $ to start searching for catalog from the root of the document. Hence, $.catalog finds this property in the root.

To move two levels up in the hierarchy we would have typed ^^key.To simply find the first catalog property in the document whatever its level, we would have written $..catalog (two dots).

Info

The ^ character is not part of the JSON-path standard but is a feature we added for the JSON filters.

Final word

We only touched on some of the possibilities of the JSON filter. For more advanced files check out the JSON path links printed in the top.