Skip to main content
1-Visitor
September 14, 2015
Solved

How to get the localized string in an extension widget

  • September 14, 2015
  • 3 replies
  • 2486 views

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);
    Best answer by jsaunders1

    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

                    }

                }

            };

        };

    3 replies

    1-Visitor
    September 14, 2015

    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?

    1-Visitor
    September 14, 2015

    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...

    jsaunders11-VisitorAuthorAnswer
    1-Visitor
    September 15, 2015

    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

                    }

                }

            };

        };