Provides helper to allow strings to be externalised
var Handlebars = require("handlebars");
var Phrase = require("handlebars.phrase");
Phrase.registerHelpers(Handlebars);
Phrase.setLanguages(langs);
Phrase.locale(lang);
Returns
Phrase instance
- Type
- object
Methods
(static) addLanguage(lang, phrases)
Add phrases to individual language
Clears any previously cached strings or templates for language
Parameters
Name | Type | Description |
---|---|---|
lang |
string | Language to add to |
phrases |
object | Phrases object for the language |
(static) addLanguages(languagesopt)
Add keys to existing languages object
Clears any previously cached strings or templates for languages passed
Parameters
Name | Type | Attributes | Description |
---|---|---|---|
languages |
object |
<optional> |
Object of language phrases |
(static) get(phrase, args, context, localeopt) → {HandlebarsSafeString}
Get HandlebarsSafeString object for a key
Parameters
Name | Type | Attributes | Description |
---|---|---|---|
phrase |
object | Lookup key |
|
args |
object | Any arguments to pass to phrase |
|
context |
object | Specific context to use |
|
locale |
string |
<optional> |
Locale to use |
Returns
phrase
- Type
- HandlebarsSafeString
(static) getString(phrase, args, context, localeopt) → {string}
Get phrase value for a key
Parameters
Name | Type | Attributes | Description |
---|---|---|---|
phrase |
object | Lookup key |
|
args |
object | Any arguments to pass to phrase |
|
context |
object | Specific context to use |
|
locale |
string |
<optional> |
Locale to use |
Returns
phrase
- Type
- string
(static) locale(locopt) → {string}
Get or set default locale used by Phrase
If called without loc parameter, returns locale
If called with loc parameter, sets locale
Parameters
Name | Type | Attributes | Description |
---|---|---|---|
loc |
string |
<optional> |
Locale to change to |
Returns
Phrase’s locale
- Type
- string
(static) registerHelper(hbars)
Register Phrase helper with Handlebars
Parameters
Name | Type | Description |
---|---|---|
hbars |
object | Handlebars instance |
(static) setFilter(fn)
Sets a filter to apply to all returned output
Parameters
Name | Type | Description |
---|---|---|
fn |
function |
(static) setLanguage(lang, phrases)
Set language individually
Clears any previously cached strings or templates for language
Parameters
Name | Type | Description |
---|---|---|
lang |
string | Language to be set |
phrases |
object | Phrases object for the language |
(static) setLanguages(languagesopt, optionsopt)
Set languages object without which Phrase cannot work
Clears any previously set languages
Parameters
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
languages |
object |
<optional> |
Object of language phrases |
|
options |
object |
<optional> |
||
options.localefallback |
boolean |
<optional> |
false | Whether default language should provide missing values for other languages |
options.penddelimiter |
string |
<optional> |
. | Delimiter to use when appending or prepending keys |