Namespace: MlString

MlString

Helper methods for handling multilingual strings.

Source:

Methods

(static) getSchema(optionsopt) → {TypeObject}

Obtain a Thinky type definition for a multilingual string object which permits only strings in the supported languages defined in locales/. Language keys like 'en' are used as object keys, so you can use syntax like label.en, or aliases.fr[0] for arrays.

Parameters:
Name Type Attributes Description
options Object <optional>

settings for this type definition

Properties
Name Type Default Description
maxLength Number

maximum length for any individual string. If not set, no maximum is enforced.

array Boolean false

Set this to true for strings of the form

{
  en: ['something', 'other'],
  de: ['something']
}

For arrays of multilingual strings, instead encapsulate getSchema in an array in the schema definition.

Source:
Returns:

type definition

Type
TypeObject

(static) resolve(lang, strObj) → {ResolveResult}

Find the best fit for a given language from a multilingual string object, taking into account fallbacks.

Parameters:
Name Type Description
lang String

the preferred language code of the target string

strObj Object

a multilingual string object

Source:
Returns:

or undefined if we can't find any suitable string

Type
ResolveResult

(static) stripHTML(strObj) → {Object}

Parameters:
Name Type Description
strObj Object

a multilingual string object

Source:
Returns:

string object with HTML entities decoded and HTML elements stripped

Type
Object

(static) stripHTMLFromArray(strObjArr) → {Array.<Object>}

Parameters:
Name Type Description
strObjArr Array.<Object>

an array of multilingual string objects

Source:
Returns:

string object array with HTML entities decoded and HTML elements stripped

Type
Array.<Object>