gengojs-default-api
The default API plugin for gengo.js.
This module will be used for gengo.js.
Note: The API examples defined are respect to the default parser.
An example usage with options is:
var gengo = require('gengojs');
var api = require('gengojs-default-api');
var app = require('express')();
app.use(gengo({
api:{
}
},));
The default API is already included in gengo.js so you should not have to require it.
Options
{
"global":"__",
"localize":"__l"
}
Internal API
None
Dependencies
this.header.getLocale(locale:String)
from Header
classthis.header.setLocale(locale:String)
from Header
classthis.header.detectLocale(locale:String)
from Header
classsupported:Array
from Header
optionsthis.backend.catalog(locale:String)
from Backend
class
Debug
Unix:
DEBUG=default-api
Windows:
SET DEBUG=default-api
API
i18n(arg)
I18ns the arguments.
Note: You can change ID for i18n. See Options.
Parameters
arg: *
, The arguments to internationalize.
Returns: String
, Then i18ned string.
Example:
Phrase notation with default parser.
__('Hello');
__('Hello %s', 'Bob');
__('Hello {{name}}', {name:'Bob'});
Bracket notation with default parser.
__('[Hello].informal');
__('[Hello %].informal', 'Bob');
__('[Hello {{name}}].informal', {name:'Bob'});
Dot notation with default parser.
__('greeting.hello.informal');
__('greeting.hello.person.informal', 'Bob');
__('greeting.hello.person.informal', {name:'Bob'});
All notations with Message Format.
Note: The format parser uses Yahoo's intl-messageformat.
__('You have {n, plural, =0 {no photos.}=1 {one photo.}other {# photos.}}', { n: 1000 });
__('[You have {n, plural, =0 {no photos.}=1 {one photo.}other {# photos.}}].since.date',
{ n:4000, d:new Date() });
__('pictures.since.date', { n:4000, d:new Date() });
language(id)
Returns the name of the current locale.
Parameters
id: string
, The locale to change.
Returns: String
, Then i18ned string.
Example:
Get the current language.
__.languages();
Get the current language in another locale.
__.language('en');
__.language('ja');
Example:
Get the current language.
__.languages();
Get the current language in another locale.
__.language('en');
__.language('ja');
languages(arg, supported)
Returns the names of the supported locale.
Parameters
arg: String | Array
, The locale to change or the supported locales.
supported: Array
, The supported locales.
Returns: String
, Then i18ned string.
Example:
Get the supported languages.
__.lanugages();
Get the current languages in another locale.
__.languages('ja');
Override the supported locales.
__.languages(['en', 'ja']);
Override the supported locales and get the languages in another locale.
__.languages('ja', ['en', 'ja']);
locales(locale)
Sets or gets the locale.
Parameters
locale: String
, The locale to set or get.
Returns: String
, The locale.
Example:
Get the current locale.
__.locale()
Set the locale.
__.locale('ja')
catalog(locale)
Returns the catalog.
Parameters
locale: String
, The locale to get.
Returns: Object
, The catalog.
Example:
Get the entire catalog.
__.catalog()
Set the locale and return the catalog.
__.catalog('en-us')
l10n(locale)
Localizes date, time and numbers.
See Tokei for documentation.
Note: You can change ID for l10n. See Options.
Parameters
locale: String
, The locale to override.
Returns: Tokei
, The context of Tokei.
Reserved words
There are a few reserved words in the API. These words are used for
overriding purposes. See the example:
__({phrase:'Hello!'});
__('Hello!', {parser:'default'});
__('You have {n, plural, =0 {no photos.}=1 {one photo.}other {# photos.}}', {parser:'format'});
Contribute
Feel free to contribute or even fork the project. This plugin has been
written in ES6 and can be seen under lib/index.js
.