API Docs for: 0.8.0
Show:

Localization Class

Module: Services

Provides functions to translate items based on keys. Also assists in the determination of the best language for the given user.

Methods

_registerLocale

(
  • locale
  • localizations
  • [options]
)
Boolean private static

Registers a localization package for the provided locale. Optionally, the packaged can be scoped to a specific plugin.

Parameters:

  • locale String | Object
    • [language] String optional

      Only required when passing locale as an object

    • [countryCode] String optional
  • localizations Object
  • [options] Object optional
    • [plugin=SYSTEM] String optional

Returns:

Boolean:

_registerLocale

(
  • locale
  • localizations
  • [options]
)
Boolean private static

Registers a localization package for the provided locale and plugin.

Parameters:

  • locale String | Object
  • localizations Object
  • [options] Object optional
    • [plugin] String optional

Returns:

Boolean:

_registerLocalization

(
  • locale
  • key
  • value
  • options
)
Boolean private static

Registers a single localization key for the provided locale and plugin.

Parameters:

  • locale String
  • key String
  • value String
  • options Object
    • plugin String

Returns:

Boolean:

_registerLocalization

(
  • locale
  • key
  • value
  • [options]
)
Boolean private static

Registers a single localization key for the provided locale. Optionally, the localization can be scoped to a single plugin.

Parameters:

  • locale String | Object
    • [language] String optional

      Only required when passing locale as an object

    • [countryCode] String optional
  • key String
  • value String
  • [options] Object optional
    • [plugin] String optional

Returns:

Boolean:

assertOptions

(
  • options
)
private static

Asserts that the options parameter is provided and that it contains a property "plugin" that is a string.

Parameters:

  • options Object
    • plugin String

best

(
  • request
  • [supported]
)
String

Determines the best language to send a user based on the 'accept-language' header in the request

Parameters:

  • request Request | String

    The request object

  • [supported] Array optional

    The array of supported locales

Returns:

String:

Locale for the request

containsParameters

(
  • localizationValue
)
Boolean static

Determines if a raw localization value contains named parameters

Parameters:

  • localizationValue String

Returns:

Boolean:

findKeyBlock

(
  • key
  • create
)
Object private static

Navigates the storage structure to find where a localization key's values live

Parameters:

  • key String
  • create Boolean

Returns:

Object:

The object that contains the values for the key

formatLocale

(
  • language
  • [countryCode]
)
String static

Formats a language and an optional country code into a proper locale format (lang-COUNTRY)

Parameters:

  • language String
  • [countryCode] String optional

Returns:

String:

g

(
  • key
  • [options]
)
String

Parameters:

  • key String
  • [options] Object optional
    • [site=global] String optional
    • [params={}] Object optional
    • [plugin] Object optional

Returns:

String:

get

(
  • key
  • [args]
)
String | Null deprecated

Defined in include/localization.js:217

Deprecated: Since 0.5.0

Translates a single key. The function accepts a variable number of parameters. The first must be the key to be localized. The rest are considered to be injectable values. The function will call "util.format" in situations where the key is found and the nuber of arguments passed to the function is greater than 1. See http://nodejs.org/api/util.html#util_util_format_format for details on supported formatting.

Parameters:

  • key String
  • [args] String | Integer | Number | Object optional

    The variable number of parameters to be injected into the localization value

Returns:

String | Null:

The formatted and localized string

getDefaultLocale

() String static

Retrieves the default locale for the instance. It first inspects the Configuration property localization.defaultLocale. As a last resort it will fall back to english. The locale is expected to be of the form: [language code]_[country code]

Returns:

String:

The default locale

getLocalizationPackage

(
  • locale
  • [options]
)
Object static

Retrieves the localization package for the specified locale

Parameters:

  • locale String
  • [options] Object optional

    See options for Localization.g

Returns:

Object:

getSupported

() Array static

Retrieves the supported locales

Returns:

Array:

getSupportedWithDisplay

() Array static

Retrieves the supported locales as an array where each item in the array contains a value (locale) and a name (locale specific representation of the locale).

Returns:

Array:

init

(
  • cb
)

Initializes the location. Loads all language packs into memory for fast retrieval and sets the supported locales for determining what language to send the user based on their list of acceptable languages.

Parameters:

  • cb Function

isSupported

(
  • locale
)
Boolean static

Determines if there have been keys registered for the specified locale. An example locale string would be: en-US. Where the characters to the left of the dash are the language code and the characters to the right of the dash represent the country code.

Parameters:

  • locale String

Returns:

Boolean:

k

(
  • key
)
String private static

Formats a given key to be formatted as a "private" property in the storage structure. This is to prevent collisions between localization keys.

Parameters:

  • key String

Returns:

String:

localize

(
  • sets
  • text
  • hostname
)
String deprecated

Localizes a string by searching for keys within the template and replacing them with the specified values.

Parameters:

  • sets Array

    The localizations sets to search in

  • text String

    The text to localize

  • hostname String

    The current hostname

Returns:

String:

The text where keys have been replaced with translated values

parseLocale

(
  • locale
)
Object private static

Takes a locale object or string representation. When a string it is parsed to an object. When an object is passed it is verified. The function throws an error when it finds invalid format.

Parameters:

  • locale String | Object
    • [language] String optional

      Only required when passing an object

Returns:

Object:

parseLocaleStr

(
  • filePath
)
Object static

Parses a locale or file path to a locale file and extracts the language and country code into an object.

Parameters:

  • filePath String | Object
    • [language] String optional

      Only required when passing filePath as an object

    • [countryCode] String optional

      Only required when passing filePath as an object

Returns:

Object:

registerLocalizations

(
  • locale
  • localizations
  • options
)
Boolean deprecated static

Defined in include/localization.js:586

Deprecated: since 0.5.0

Parameters:

  • locale String
  • localizations Object
  • options Object
    • [plugin] String optional

Returns:

Boolean:

replaceParameters

(
  • value
  • params
  • [defaultVal]
)
String static

Given a raw localization value and a set of parameters the function will attempt to replace the named parameters in the raw value with the values provided in the params. When a named parameter is found that was not provided a value the defaultVal parameter value is used.

Parameters:

  • value String
  • params Object
  • [defaultVal] String optional

Returns:

String:

unregisterLocale

(
  • locale
  • [options]
)
Boolean static

Removes a locale and all keys associated with it. Optionally, the operation can be scoped to a single plugin.

Parameters:

  • locale String | Object
    • [language] String optional

      Only required when locale is passed as an object

    • [countryCode] String optional
  • [options] Object optional
    • [plugin] String optional

Returns:

Boolean:

unregisterLocalization

(
  • locale
  • key
  • [options]
)
Boolean static

Unregisters a single key for the given locale. The locale can be just the language or the combination of the language and country code. Additionally, the operation can be scoped to a single plugin.

Parameters:

  • locale String | Object
    • [language] String optional

      Only required when passing locale as an object

    • [countryCode] String optional
  • key String
  • [options] Object optional
    • [plugin] String optional

Returns:

Boolean:

Properties

ACCEPT_LANG_HEADER

String static

activeTheme

String

The currently active theme that should be prioritized when performing key lookup

cache

Object

Stores the keys already retrieved for the instance to prevent duplicate retrieval.

JS_EXT

String

KEY_SEP

String static

language Really should be renamed to locale in the future

String

expected to be lowercase and of the form "en-us"

LOCALE_PART_SEP

String static

localeObj

Object

PARAM_REPLACEMENT_REGEX

RegExp static

PREFIX

String static

SEP

String static

storage

Object static

supported

Locales static

supportedLookup

Object static