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

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

How to get the localized string in an extension widget

jsaunders1
7-Bedrock

How to get the localized string in an extension widget

To get the value of a localization token in a service, you can use the following snippet. Do we know what the corresponding code is inside a widget? If I use `getProperty()` on a localized string I get back something like "[[TokenName]]" (where "TokenName" is the name of the localization token the user bound to the property. Am I supposed to check for the double-brackets and look up the value of the localization token?

```var params = {
    token: "TokenName"
};
var result = Resources["RuntimeLocalizationFunctions"].GetEffectiveToken(params);
ACCEPTED SOLUTION

Accepted Solutions

It turns out you need to set the isLocalizable flag for the properties in runtimeProperties (in mywidget.runtime.js), not just widgetProperties (in mywidget.ide.js). For example:

    this.runtimeProperties = function () {

        return {

            'propertyAttributes': {

                'Header': {

                    'isLocalizable': true

                }

            }

        };

    };

View solution in original post

3 REPLIES 3

To be a bit more clear, my widget has a property called "Header" that has isLocalizable set to true. This property is bound to the localization token "TokenName". When I get the value for the property using this.getProperty("Header"), the return value is "[[TokenName]]".

So I either need to use something other than getProperty() to get the localized property value or I need to look up the localization token value (using, for example, GetEffectiveToken) if the property value starts with "[[" and ends with "]]". If I need to use GetEffectiveToken, how do I get access to the object that implements it?

I found TW.Runtime.convertLocalizableString('[[reply]]') but from the code I see, it seems like I shouldn't have to do that when getting the value of localized widget properties.

So that is how to look up localization tokens in a widget.

Now I need to figure out why my widget property values are coming in as "[[TokenName]]" instead of as the localized value...

It turns out you need to set the isLocalizable flag for the properties in runtimeProperties (in mywidget.runtime.js), not just widgetProperties (in mywidget.ide.js). For example:

    this.runtimeProperties = function () {

        return {

            'propertyAttributes': {

                'Header': {

                    'isLocalizable': true

                }

            }

        };

    };

Announcements


Top Tags