Quick note

Localization in widgets used as EPiServer gadgets or property editors

Given a language resource file like this:

<?xml version="1.0" encoding="utf-8" ?>
<languages>
  <language name="English" id="en">
    <mystuff>
      <substuff>
        <key>Value</key>
      </substuff>
    </mystuff>
  </language>
</languages>

The node "mystuff" can be accessed in a JavaScript UI-component such as a gadget or custom editor using require and the i18n module, like this:

define([
    "epi/i18n!epi/cms/nls/mystuff"
], function (
    resources
) {
    return declare("", [], {
        resources: resources,
    });
});

The resources variable will be an object like this:

{
    substuff: {
        key: "value"
    }
}

To instead retrieve only the "substuff" element the required module can be modified to epi/i18n!epi/cms/nls/mystuff.substuff.

To output a localized resource like "key" above in a template the following can be used:

${resources.substuff.key}
Joel Abrahamsson

Joel Abrahamsson

I'm a passionate web developer and systems architect living in Stockholm, Sweden. I work as CTO for a large media site and enjoy developing with all technologies, especially .NET, Node.js, and ElasticSearch. Read more

More about EPiServer CMS