cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Setting language table tokens via a script

Highlighted
Level 8

Setting language table tokens via a script

Hi,

I know that there are run time localisation functions for retrieving a tokens value in different languages, but are there any services for setting a token value in various languages.

I'm hoping to create a mash that will allow certain foreign users to do their own translations, but I can't find any in built services to set a token's value.

Tags (2)
3 REPLIES 3

Re: Setting language table tokens via a script

Hi,

I think I might have answered my own question

There is a service called UpdateToken(). In the example below I am using the German (de) language table.

var params = {

name: undefined /* STRING */,

value: undefined /* STRING */

};


// no return

LocalizationTables["de"].UpdateToken(params);

Re: Setting language table tokens via a script

I think I might have spoken too soon

I tried the UpdateToken service, wrapped in my own service, on an existing token named 'set' which was already in the table but it kept failing as it couldn't find the token?

Execution error in service script [My.Developement.Utility.Thing SetLanguageToken] : Wrapped com.thingworx.common.exceptions.InvalidRequestException: Token [[set]] not found Cause: Token [[set]] not found

​Not sure where the double brackets come from??

I then swapped the inner service from UpdateToken ​to AddOrUpdateToken​ which uses the same params


var params = {

name: tokenID /* STRING */,

value: NewString /* STRING */

};


LocalizationTables[LanguageID].AddOrUpdateToken(params);


At first this appeared to work, however on reloading my mash the '​set​' token value now appears to have disappeared from the button widgets that had been using it, leaving my buttons with no text

Does anyone know what has happened?

Thanks in advance


Re: Setting language table tokens via a script

After some investigation it turns out that the LocalizationTables[LanguageID].AddOrUpdateToken(params); service does in fact work correctly.

It was the incorrect use of the ​UpdateToken​ service that screwed things up above. So if you do want to add translations via a script you can use the following code;

var params = {

name: tokenID /* STRING */,

value: NewString /* STRING */

};


LocalizationTables[LanguageID].AddOrUpdateToken(params);


As an example changing the French version of a token called 'helloToken' would be -

var params = {

name: "helloToken" /* STRING */,

value: "Bonjour" /* STRING */

};


LocalizationTables["fr"].AddOrUpdateToken(params);