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

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

How to Insert Tokens on Localization Table with Service or Rest API

mberber
11-Garnet

How to Insert Tokens on Localization Table with Service or Rest API

Hello everyone;

 

We want to insert multiple Tokens on Localizations Table for certain language ( Turkish - tr  ) . Adding one by one taking is very time consuming. I cannot find any related service which doing this job. 

 

Things I Tried 

 

1 ) After createing new Localization Table, i added a new Token for label. And then i exported the XML file. Opened it a Text Editor and try to duplicate inserted Row Value but i failed. 

 

2) I also tried to monitor the adding token process from Chrome Developper Tool - Network and mimic the process from Postman. it also failed.

 

Addng one by one is doable but its not Efficent way to do. Maybe we need to update some translation on table on future and there is more then 300 entry on the Table. 

 

Can anyone suggest to me any viable option to solve this issue ?

 

Thank you.

5 REPLIES 5

Here you have the code snippet:

 

    LocalizationTables["LocalizationTableName"].AddOrUpdateToken({
        name: "tokenName" ,
        value: "tokenValue" 
    });

Hello Carles

 

Thank you for your fast reply but the code you had share didn't work. 

 

I am using Thingworx 8.4.3 Version.

 

Thank you.

But didn't worked with no result, you get an error,... You are setting the right Localization Table Name? I can test it on 8.2.x and it do works.

 

Just navigate on Entities and localize the LocalizationTables, there you can see the available services it has.

I found the services

 

 

var params = {

name: "OrderNumber" /* STRING */,

value: "Sipariş Numarası" /* STRING */

};

result = LocalizationTables["tr"].AddOrUpdateToken(params);

 

 

This is worked but only on the existed tokens which i manually added before. It cannot create new Token, its only update it.

 

In order to make it work for new Tokens, you first must add it to the default Localization Table, here it's our full Update Tokens code (a helper service, this service accepts an infotable -texts- with three columns: table, token and text ):

 

var result = 0;
var nTexts = texts.rows.length;
var entry;
var defaultLocalizationTable = LocalizationTables["Default"];
for (var i=0;i<nTexts;i++) {
	entry = texts.rows[i];
    // -- First of all let's check if the Token exists
	var exist = null;
    try {
        exist = Resources["RuntimeLocalizationFunctions"].GetEffectiveToken( { token: entry.token   });
    } catch (err) {
       // logger.info("Error trying to recover token: "+err);
        exist = null;
    }

    if (exist==null) {
        // -- If it not exists, we have to create the Token on the Default Localization Table
        defaultLocalizationTable.AddOrUpdateToken({
            name: entry.token ,
            value: entry.text 
    	});
        result++;
    }
    
    LocalizationTables[entry.table].AddOrUpdateToken({
        name: entry.token ,
        value: entry.text 
    });
    result++;
}
Top Tags