Constructor
new Lang(options)
- Source:
Parameters:
| Name |
Type |
Description |
options |
Object
|
Properties
| Name |
Type |
Attributes |
Description |
dependencies |
Object
|
|
Key/value map of dependency configs (each with a rootDir) |
defaultLang |
String
|
|
The default language for translations |
rootDir |
String
|
|
The application root directory |
log |
function
|
<optional>
|
Optional logging function (level, id, ...args) |
|
Members
defaultLang :String
- Description:
- The default language for translations
- Source:
The default language for translations
Type:
log :function
- Description:
- Optional logging function (level, id, ...args)
- Source:
Optional logging function (level, id, ...args)
Type:
phrases :Object
- Description:
- The loaded language phrases
- Source:
The loaded language phrases
Type:
supportedLanguages :Array.<String>
- Description:
- Returns the languages supported by the application
- Source:
Returns the languages supported by the application
Type:
Methods
loadPhrases(dependencies, appRootDir, logopt)
- Description:
- Loads and merges all language phrases from dependencies
- Source:
Parameters:
| Name |
Type |
Attributes |
Description |
dependencies |
Object
|
|
Key/value map of dependency configs (each with a rootDir) |
appRootDir |
String
|
|
The application root directory |
log |
function
|
<optional>
|
Optional logging function (level, id, ...args) |
substituteData(s, lang, data) → {String}
- Description:
- Replaces placeholders in a translated string with data values.
Supports ${key} for simple substitution, and $map{key:attrs:delim}
for mapping over array values.
- Source:
Parameters:
| Name |
Type |
Description |
s |
String
|
The translated string |
lang |
String
|
The target language |
data |
Object
|
Key/value pairs to substitute |
Returns:
-
Type
-
String
translate(lang, key, data) → {String}
- Description:
- Returns translated language string. If key is an Error, translates using
the error code as the key and error data for substitution. Non-Error,
non-string values are returned unchanged.
- Source:
Parameters:
| Name |
Type |
Description |
lang |
String
|
The target language (falls back to defaultLang) |
key |
String
|
Error
|
The unique string key, or an Error to translate |
data |
Object
|
Dynamic data to be inserted into translated string |
Returns:
-
Type
-
String