As already mentioned above, the {{ns}}
variable represents a RequireJS namespace that has been defined for a Commerce Store Accelerator module. A RequireJS namespace is tied to a specific directory path through configuration in the module’s main.js
file.
Understanding how the namespace is calculated starts with the cartridge renderer view model. The view model for a cartridge renderer that has translation resource dependencies must include the i18n-loader!
statement in its define
code block. To describe how this statement behaves, we consider a specific example, the AccountMenu.js
file, which has the following i18n-loader!
statement:
define([ 'content-item-mixin', 'text!AccountMenu.html', 'i18n-loader!AccountLocales.json', 'profile-services' ], function (contentItemMixin, template, localeNamespace, profileServices) { }
The i18n-loader
statement in this example instructs RequireJS to call the load()
function of the i18n-loader
, passing in AccountLocales.json
for the name
parameter. The load()
function strips off the .json
portion of the name, leaving the namespace AccountLocales
as the value for the name
parameter. The load()
function calls the req.toUrl()
function, passing in the name
parameter, to convert the namespace to a URL. In this case, the URL is converted to bower_components/CSA.Plugins.Account/locales
, which is the value defined for the AccountLocales
namespace in the CommerceAccelerator/Plugins/Account/src/main/web-app/main.js
file.
At this point, the {{ns}}
portion of the template path for the resource file to be loaded is known.