How to Insert Tokens on Localization Table with Service or Rest API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Labels:
-
Troubleshooting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Here you have the code snippet:
LocalizationTables["LocalizationTableName"].AddOrUpdateToken({ name: "tokenName" , value: "tokenValue" });
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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++; }
