A super easy way of processing JSON in Trados Studio

Supertext has developed a JSON file type plugin for Trados Studio 2022 with support for bilingual files!

What can you do with it?

  • Translate JSON files (*.json) directly in Trados Studio
  • Translate all texts
  • Use a path filter to:
    • Translate only specific texts
    • Translate bilingual JSON files
  • Process embedded content such as HTML tags

Download and installation


Download the plugin here and double click on the .sdlplugin file to start the plugin installer.

Troubles finding the installed plugin in Trados?

  1. Please verify whether our plugin has in fact been installed correctly and is active in the Studio version you’re using. For this, let’s run the Trados plugin management tool. You can find it either by clicking the start button in Windows and type “sdl plugin”. A window will open and you should see an entry for the JSON plugin (Supertext.Sdl.Trados.FileType.JsonFile)
  2. If you’re sure the plugin has been installed, fire up Trados. If the file type doesn’t appear in your file type list, click the blue link above the list (“Additional installed File Types exist”). Tick the box next to JSON-File, and hit OK.

JSON format

JSON stands for JavaScript Object Notation and is a data-interchange format for storing and exchanging data. It has an easy-to-read syntax and may contain text which needs to be translated.

{
   "header": {
      "title": "The JSON example",
      "descriptionText": "This is some title text."
   },
   "content": {
      "title": "The content example text",
      "elements": [
         {
            "title": "The first element", 
            "mainText": "First element main text",
            "additionalText": "First element additional text"
         },
         {
            "title": "The second element",
            "mainText": "Second element main text",
            "additionalText": "Second element additional text"
         }
      ]
   }
}

There is already a lot of information about the JSON format out there, so we won’t go into any specific details here.

JSON path

A JSON document can be represented as a tree.  The example above:

A path describes how to get to a node of the tree. We are only interested in paths that lead to properties with a string as value (represented as leaves in the tree above).

Example path that leads to the property with the value “The JSON example”: header.title

Example path that leads to the property with the value “First element additional text”: content.elements[0].additionalText

Translate all JSON file texts

By default, the parser will extract all texts and no setting changes are required.

Use a path filter

The path filter setting can be found in the project settings under File Types -> JSON file -> Parsing settings. The filter rules are defined using regular expression. Each rule defines two expressions.

The source path expression is used to describe the pattern a path must match to be used as source, and therefore the property’s value as source text. If a path does not match any source path expressions, it is ignored. This way you can control what is used as translatable text.

The target path expression is used to describe the pattern of the path that should be used as target, and therefore the property’s content as target text. This expression needs to be the same as the source expression if the source text is to be replaced with the target text. However, if the JSON document is bilingual and therefore contains source as well as target text, it will be different from the source expression.

Translate only specific texts

You can either add filter rules yourself or extract all existing rules from a JSON file and then remove the rules matching the unwanted texts.

Example settings to get the header title and all “additionalText” properties of the above JSON document:

You could use “content\.elements\[0\]\.additionalText” instead of “content\.elements\[\d+\]\.additionalText” as the path expression to get only the first “additionalText”.

It is possible to use only “title” instead of “header\.title” and “content\.title” if both title properties should be translated, since the parser checks if the path contains the described pattern.

Translate bilingual JSON files

It is possible to specify a target path expression if the JSON document to translate is bilingual.

{
	"sourceLang": "en",
	"targetLang": "de",
	"texts": [
		{
			"source": "This is an example",
			"target": "Das ist ein Beispiel"
		},
		{
			"source": "This is a second example",
			"target": "Das ist ein zweites Beispiel"
		}
	]
}

In this case you need to mark the rule as bilingual and define the target path expression.

Select “Apply target text from JSON file” to extract any existing target text from the JSON file.

The extraction feature does not recognize source and target. The path expressions for source and target will be defined in separate rules; however, it is possible to join the rules:

  1. Hold down the Ctrl key on your keyboard
  2. Click on the first rule to select it
  3. Click on the second rule to select it
  4. Release the Ctrl key and click on the Join button

Process embedded content like HTML tags

The plugin supports embedded content replacement with tags. The default settings already contain common placeholders and tag pairs for HTML. This setting can be found under File Types -> JSON file -> Embedded Content.

Tips & Tricks

You want to catch description, but not descriptionTitle?

Change this:
\[\d+\]\.description
to this:
\[\d+\]\.description\b
The \b kinda signals the end of the word.

Error: The document cannot be processed since it contains unexpected contents.
or
The target text contains more HTML tags than the source text (tags duplication)

Likely the HTML tags in your content are not matched or Trados is just having troubles with them.

  1. Remove all entries in the “Embedded Content” configuration.
  2. Add a placeholder with following “Start Tag”: </?[\p{Ll}\p{Lu}]\w*[^<>]*>

Don’t forget to add your custom placeholders (e.g. {?{\d+}}?).

You need help?

Please write your question in the SDL Forum first:
https://community.sdl.com/developers-more/developers/language-developers/
Drop us a mail too with a link to the post, we don’t always monitor the group: development AT supertext DOT com.
Make sure you include the json and the sdlfiletype settings file.

We are giving this plugin away for free and we will try to help you nevertheless. But we do have other issues to work on sometimes.



Related posts


7 Kommentare zu “A super easy way of processing JSON in Trados Studio”



  • Evzen am 29. November 2016 20:54 Uhr

    Hi, I’m having problem with the plugin – it keeps throwing error when trying to generate target file:
    Unable to cast object of type ‘Newtonsoft.Json.Linq.JArray’ to type ‘Newtonsoft.Json.Linq.JProperty’.

    Here is the complete Trados Studio error XML: http://pastebin.com/0sStkASV
    And here is the test JSON file: http://pastebin.com/Ebshhtsx
    This is the simple filter rule used: \.textMessages\[\d+\]


  • Rémy Blättler am 5. December 2016 16:48 Uhr

    Hey Evzen
    We can reproduce your issue. We will have a look at this as soon as possible, but since we are providing this Plugin for free, it’s not a top priority.


  • Lierni Otamendi am 23. February 2018 19:42 Uhr

    We had tried the new plug-in after having reported some issues with a couple of json files we had to translate, and the result has been phantastic. Great product and service! Thank you all.


  • Verona am 24. May 2019 22:42 Uhr

    Ich bin gerade zufaellig auf Ihrer Seite gelandet (war eigentlich
    auf der Suche nach einer anderen Websiete).
    Ich moechte diese Seite nicht verlassen, ohne Euch ein Lob zu dieser gut strukturierten und schick
    designten Page zu hinterlassen!


  • Angela Mariani am 28. June 2019 17:44 Uhr

    Liebe Verona
    Vielen Dank für dein Lob, das uns natürlich sehr freut!
    Supergrüsse
    Angela


  • Mery Martinelli am 28. February 2024 14:24 Uhr

    Hi,
    How can I see in Trados Studio the “id” content of the json structure below? The problem is that your filetype allows to extract only what appears between quotes.
    Thanks in advance for your kind help.
    Regrads,
    Mery

    {
    “id”: 73594,
    “annotations”: [],
    “file_upload”: “73f6a598-openqa_de_25-50_n100_-_openqa_de_25-50_n100_3.csv”,
    “drafts”: [],
    “predictions”: [],
    “data”: {
    “meta”: “”,
    “skill”: “open_qa”,
    “domain”: “General”,
    “prompt”: “Wie verfolgt ein Unternehmen die Zeit? Wie sieht der Prozess aus?”,
    “context”: “”,
    “new_prompt”: “”
    },


  • Angela Lanza-Mariani am 11. March 2024 11:16 Uhr

    Hey Mery
    Thank you for your question.

    Unfortunately, Trados does not offer the option of displaying IDs unless you create them as a translatable text segment.

    Super regards


Leave a Reply

Your email address will not be published. Required fields are marked *