Before building a script, you must understand the basics of Codex profiles. You can find all the information about Codex and the profiles here.


Basics


When extracting a .json file with scripts, you need to indicate which keys you want and don't want to translate by providing the path to the keys:

{
  "test": "hello1",
  "test2": {
    "bonjour": "hello2",
    "test3": ["hello3", "hello3"]
  }
}

ex: path for "bonjour" key would be "/test2/bonjour"


For the above JSON sample file. Let's extract the test2 key and exclude the test one key. The below script will extract the "test2" key and all its children, and ignore all the other keys:

selectionPathList = [Pair("/test2", True), Pair("/", False)]
contextsPath = []
groupingPaths = []
contentNames = []
groupingPathNames = []
targetInjections = []
targetInjectionsRange = []


Improve your scripts


Split your large files with the groupingPaths parameter


codexSeparator parameter

JSON files can be very large and contain a lot of keys. In order to generate small bundles of keys and therefore tasks to translate, you can make use of the codexSeparator parameter for groupingPaths:

groupingPaths = [Pair("codexSeparator","/")]

When extracting .json files using this parameter, tasks which belong to the same parent keys will be grouped together.


codexGroupingSize parameter

In case you would like to go even further with splitting tasks, you can specify the maximum number of keys within a same task using the codexGroupingSize parameter:

groupingPaths = [Pair("codexGroupingSize", "20")]

When extracting .json files using the codexGroupingSize parameter, tasks will contain a maximum of 20 keys.


Give context to your localizable content with the contextPaths parameter


The localization process can be improved by providing translation context.

You can indicate in the script which keys should be used as translation context, and their values will then be displayed on the Details panel of the Translation Studio.

Here is a sample script to extract some content as context:

contextsPath = [Pair("/test2", True)]

Here we've added the test2 branch as context.


URLs & Images

To have clickable URLs in the Translation Studio Details panel, make sure they are provided between "[url=" and "]" tags.

ex: [url=https://helpdesk.wezen.com]


To have images displayed in the Translation Studio Details panel, make sure they are provided between "[img=" and "]" tags.

ex: [img=https://wezen.com/yourimage.jpg]


JSON script improvement with Regex


selectionPathList usage


selectionPathList is used for selecting what want to translate and what we do not.


Regex "*"

Select all or a part of path.


Example :  

Content from a file.

root/date = "february 7th"
root/animal[0]/name = "Husky"
root/animal[0]/type = "Dog"
root/animal[0]/age = 5
root/animal[1]/name = "Leo"
root/animal[1]/type = "Cat"
root/animal[1]/age = 7
root/animal[2]/name = "Lucky"
root/animal[2]/type = "Horse"
root/animal[2]/age = 8
root/vegetable[0] = "Carrot"
root/vegetable[1] = "Potato"
root/vegetable[2] = "Spinach"
root/vegetable[3] = "Celery"
root/vegetable[4] = "Broccoli"


Example of the "*" usage in Codex script:

selectionPathlist = [Pair("root/date",False),Pair("root/animal[*]/name",False),Pair("root/vegetable*",True),Pair("*animal[*]/*",True)]  

ex: do not select the "date" key, do not select all the indexed value of the "animal/name" key, select the "root/vegetable" key, and select all the rest of the value of the "animal" key, be it precedented by any by name, indexed by any indices, and followed by any child key


Result :

root/animal[0]/type = "Dog" 
root/animal[0]/age = 5 
root/animal[1]/type = "Cat" 
root/animal[1]/age = 7 
root/animal[2]/type = "Horse" 
root/animal[2]/age = 8 
root/vegetable[0] = "Carrot" 
root/vegetable[1] = "Potato" 
root/vegetable[2] = "Spinach" 
root/vegetable[3] = "Celery" 
root/vegetable[4] = "Broccoli"

groupingPaths usage


Regroup all paths we choose into a group. If two Pair took the same path, only the first Pair could take the path and not others.


Warning : JSON files keep contents which are not included in groupingPaths and put contents into a default group without name.


Regex "*"

Select all or a part of path.


Regex "[*]"

Group all paths which match with groupingPaths and put all data into the same group.


Example :  

Content from a file.

root/date = "february 7th"
root/animal[0]/name = "Husky"
root/animal[0]/type = "Dog"
root/animal[0]/age = 5
root/animal[1]/name = "Leo"
root/animal[1]/type = "Cat"
root/animal[1]/age = 7
root/animal[2]/name = "Lucky"
root/animal[2]/type = "Horse"
root/animal[2]/age = 8
root/vegetable[0] = "Carrot"
root/vegetable[1] = "Potato"
root/vegetable[2] = "Spinach"
root/vegetable[3] = "Celery"
root/vegetable[4] = "Broccoli"


Example of the Regex usage in Codex script:

selectionPathList = [Pair("root/date",False),Pair("*",True)]  
groupingPaths =  [Pair("/animal[*]/name","animal"), Pair("/vegetable[*]","vegetable"), Pair("root/animal[0]*","first animal")]


Result :

animal task:

root/animal[0]/name = "Husky"
root/animal[1]/name = "Leo"
root/animal[2]/name = "Lucky"

vegetable task:

root/vegetable[0] = "Carrot"
root/vegetable[1] = "Potato"
root/vegetable[2] = "Spinach"
root/vegetable[3] = "Celery"
root/vegetable[4] = "Broccoli"

first animal task:

root/animal[0]/type = "Dog"
root/animal[0]/age = 5
root/animal[1]/type = "Cat"
root/animal[1]/age = 7
root/animal[2]/type = "Horse"
root/animal[2]/age = 8

info: "Husky" is not in first animal because it is already in animal.  


Regex "[?]"

Take all paths which match with groupingPaths and separate all data which do not have the same contained data into [].

When [?] is used in left part of Pair, left part and right part MUST contain the same quantity of [?].


Example :  

Content from a file.

root/date = "february 7th"
root/animal[0]/name = "Husky"
root/animal[0]/type = "Dog"
root/animal[0]/age = 5
root/animal[1]/name = "Leo"
root/animal[1]/type = "Cat"
root/animal[1]/age = 7
root/animal[2]/name = "Lucky"
root/animal[2]/type = "Horse"
root/animal[2]/age = 8
root/vegetable[0] = "Carrot"
root/vegetable[1] = "Potato"
root/vegetable[2] = "Spinach"
root/vegetable[3] = "Celery"
root/vegetable[4] = "Broccoli"


Example of the Regex usage in Codex script:

selectionPathList = [Pair("root/date",False),Pair("*",True)]  
groupingPaths =  [Pair("/animal[?]","animal[?]")]


Result :

animal[0] task:

root/animal[0]/name = "Husky"
root/animal[0]/type = "Dog"
root/animal[0]/age = 5

animal[1] task:

root/animal[1]/name = "Leo"
root/animal[1]/type = "Cat"
root/animal[1]/age = 7

animal[2] task:

root/animal[2]/name = "Lucky"
root/animal[2]/type = "Horse"
root/animal[2]/age = 8

no name task:

vegetable[2] = "Spinach"
root/vegetable[3] = "Celery"
root/vegetable[4] = "Broccoli"