Community Tip - You can change your system assigned username to something more personal in your community settings. X
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.
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);
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
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);