/workspace/getLocale

The getLocale module exports the getLocale method which is required by the getLayer and workspace modules.

Requires

Methods

(async, inner) composeLocale(locale, parentLocaleopt, params, workspaceKey) → {Promise.<Object>}

Composes the final locale object by merging with an optional parentLocale and recursively processing further nested locales.

When a parentLocale is provided, its properties are merged into the locale. The locale name and role are composed with dot-notation to reflect the nesting hierarchy.

Temporary properties used during workspace composition (src, template, templates, _type, localesRoleContext) are removed before returning.

Parameters:
NameTypeAttributesDescription
localeObject

The locale object to compose.

parentLocaleObject<optional>

Optional parent locale to merge into.

paramsObject

Request parameters including locale keys and user.

workspaceKeystring

The workspace key to assign.

Returns:

The composed locale object.

Type: 
Promise.<Object>

(async, inner) getLocale(params, parentLocaleopt) → {Promise.<(Object|Error)>}

The getLocale method requests the workspace from cache and checks whether the requested locale is a property of the workspace.locales{}.

The workspace.locale is assigned as locale if params.locale is undefined.

Any locale can be nested into another locale, if the locale property is defined as an array of locale keys.

The localeKey will be shifted from the locale array property. The getLocale method will call itself recursively with the locale object provided as parentLocale param. The current locale object will be merged into the parentLocale. The locale key for nested locales is an array which reflects the locale array property.

The locales array property which provides an interface for locales which can be nested but are not available from the workspace.locales directly is removed on nested locales.

The mergeTemplate module will be called to merge templates into the locale object and substitute SRC_* xyzEnvironment variables.

A role check is performed to check whether the requesting user has access to the locale.

Role objects in the locale and nested layers are merged with their respective parent objects.

Template properties will be removed as these are not required by the MAPP API but only for the composition of workspace objects.

Parameters:
NameTypeAttributesDescription
paramsObject
parentLocaleObject<optional>

Locale will be merged into optional parentLocale to create a nested locale.

Properties
NameTypeAttributesDescription
params.localestring<optional>

Locale key.

params.localearray<optional>

An array of locale keys to be merged as a nested locale.

params.userObject<optional>

Requesting user.

params.ignoreRolesBoolean<optional>

Whether role check should be performed.

user.rolesArray<optional>

User roles.

Returns:

JSON Locale.

Type: 
Promise.<(Object|Error)>

(async, inner) processRoles(locale, parentLocale, params) → {Promise.<(Object|Error)>}

The processRoles method calls the utility method that combines a parentLocale roles with a locale.

The locale.template and templates[] will be merged into the locale object.

Locale access for the user will be checked without the ignoreRoles property provided in the params object.

An error will be returned if the user does not have access to the role.

If the parentLocale has a localesRoleContext property (set by mergeTemplates when a template contributes a locales array), it is used as the role context for combining. This ensures nested locales are combined only with the roles of the template that defined the locales array, not the accumulated roles of all sibling templates.

Parameters:
NameTypeDescription
localeObject
parentLocaleObject

Parent locale with roles.

paramsObject
Properties
NameTypeAttributesDescription
params.useruser<optional>

User object with access roles.

params.ignoreRolesboolean<optional>

Ignore roles for template merging and checks.

Returns:

JSON Locale.

Type: 
Promise.<(Object|Error)>