Socket
Socket
Sign inDemoInstall

gengojs-default-api

Package Overview
Dependencies
94
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.5 to 0.0.6

2

gulpfile.js

@@ -92,3 +92,3 @@ /* Dev-Dependencies */

output: ' -o docs/',
name:' -n "gengo.js/plugins/api"',
name:' -n "gengo.js/plugin/api"',
theme:' -t cayman'

@@ -95,0 +95,0 @@ };

@@ -17,74 +17,23 @@ import cldr from 'cldr';

var core = this.context;
/**
* The i18n function
*/
var i18n = function() {};
/**
* The l10n function
*/
var l10n = function() {};
// Set the options
var options = this.options.api;
_.assign((options.header = {}), this.options.header);
debug('api', 'info', 'options exists:', !(!options));
/**
* @method i18n
* @description I18ns the arguments.
* Note: You can change ID for i18n. See Configuration.
* @param {...*} arg The arguments to internationalize.
*
* @example <caption>Phrase notation with default parser.</caption>
*
* // Assuming the locale === 'ja',
* // a basic phrase returns 'こんにちは'
* __('Hello');
*
* // a basic phrase with sprintf returns 'Bob こんにちは'
* __('Hello %s', 'Bob');
*
* // a basic phrase with interpolation returns 'Bob こんにちは'
* __('Hello {{name}}', {name:'Bob'});
*
* @example <caption>Bracket notation with default parser.</caption>
*
* // Assuming the locale === 'ja',
* // a basic bracket phrase returns 'おっす'
* __('[Hello].informal');
*
* // a basic bracket phrase with sprintf returns 'Bob おっす'
* __('[Hello %].informal', 'Bob');
*
* // a basic bracket phrase with interpolation returns 'Bob おっす'
* __('[Hello {{name}}].informal', {name:'Bob'});
*
* @example <caption>Dot notation with default parser.</caption>
*
* // Assuming the locale === 'ja',
* // a basic dot phrase returns 'おっす'
* __('greeting.hello.informal');
*
* // a basic dot phrase with sprintf returns 'Bob おっす'
* __('greeting.hello.person.informal', 'Bob');
*
* //a basic dot phrase with interpolation returns 'Bob おっす'
* __('greeting.hello.person.informal', {name:'Bob'});
*
*
* @example <caption>All notations with Message Format.</caption>
* // See [message-format](https://github.com/thetalecrafter/
message-format) for documentation.
* // See updated docs at README:
*
* // Assuming the locale === 'en-us',
* // a basic phrase with message formatting
* // returns "You took 4,000 pictures since Jan 1, 2015 9:33:04 AM"
* __('You took {n,number} pictures since
{d,date} {d,time}', { n:4000, d:new Date() });
*
* // a basic bracket phrase with message formatting
* // returns "You took 4,000 pictures since Jan 1, 2015 9:33:04 AM"
* __('[You took {n, numbers} pictures].since.date',
{ n:4000, d:new Date() });
*
* // a basic dot phrase with message formatting
* // returns "You took 4,000 pictures since Jan 1, 2015 9:33:04 AM"
* __('pictures.since.date', { n:4000, d:new Date() });
*
* @return {String} Then i18ned string.
* @public
*/
* i18ns the arguments. Note: You can change ID for i18n. See Options.
* @param {...*} arg The arguments to internationalize.
* @return {String} Then i18ned string.
*/
i18n[options.global] = function(...args) {

@@ -95,23 +44,67 @@ log.debug(`class: ${API.name}`, `process: i18n`);

/**
* ### Example
* *The following applies only for gengojs-default-parser*
*#### Phrase notation with default parser.
*```javascript
* // Assuming the locale === 'ja',
* // a basic phrase returns 'こんにちは'
* __('Hello');
*
* // a basic phrase with sprintf returns 'Bob こんにちは'
* __('Hello %s', 'Bob');
*
* // a basic phrase with interpolation returns 'Bob こんにちは'
* __('Hello {{name}}', {name:'Bob'});
*```
*#### Bracket notation with default parser.
*```javascript
* // Assuming the locale === 'ja',
* // a basic bracket phrase returns 'おっす'
* __('[Hello].informal');
*
* // a basic bracket phrase with sprintf returns 'Bob おっす'
* __('[Hello %].informal', 'Bob');
*
* // a basic bracket phrase with interpolation returns 'Bob おっす'
* __('[Hello {{name}}].informal', {name:'Bob'});
*```
*#### Dot notation with default parser.
*```javascript
* // Assuming the locale === 'ja',
* // a basic dot phrase returns 'おっす'
* __('greeting.hello.informal');
*
* // a basic dot phrase with sprintf returns 'Bob おっす'
* __('greeting.hello.person.informal', 'Bob');
*
* //a basic dot phrase with interpolation returns 'Bob おっす'
* __('greeting.hello.person.informal', {name:'Bob'});
*```
*
*#### All notations with Message Format.
* See [message-format](https://github.com/thetalecrafter/
message-format) for documentation.
* ```javascript
* // Assuming the locale === 'en-us',
* // a basic phrase with message formatting
* // returns "You took 4,000 pictures since Jan 1, 2015 9:33:04 AM"
* __('You took {n,number} pictures since
{d,date} {d,time}', { n:4000, d:new Date() });
*
* // a basic bracket phrase with message formatting
* // returns "You took 4,000 pictures since Jan 1, 2015 9:33:04 AM"
* __('[You took {n, numbers} pictures].since.date',
{ n:4000, d:new Date() });
*
* // a basic dot phrase with message formatting
* // returns "You took 4,000 pictures since Jan 1, 2015 9:33:04 AM"
* __('pictures.since.date', { n:4000, d:new Date() });
*```
*/
/**
* @method language
* @description Returns the name of the current locale.
* @param {string} id The locale to change.
*
* @example <caption>Get the current language.</caption>
*
* // assuming locale === 'en-us'
* // returns 'American English'
* __.languages();
*
* @example <caption>Get the current language in another locale. </caption>
*
* // assuming locale === 'en-us'
* // returns 'English'
* __.language('en');
*
* // returns 'Japanese'
* __.language('ja');
*
* @return {String} Then i18ned string.
* @public
*/

@@ -128,36 +121,30 @@ i18n.language = function(id) {

};
/**
* @method languages
* @description Returns the names of the supported locale.
* @param {String | Array} arg The locale to change or the supported locales.
* @param {Array} supported The supported locales.
*
* @example <caption>Get the supported languages.</caption>
*
* // Assuming locale === 'en-us'
* // returns ['American English', 'Japanese']
* __.lanugages();
*
* @example <caption>Get the current languages in another locale. </caption>
*
* // Assuming locale === 'en-us'
* // returns ['アメリカ英語', '日本語']
* __.languages('ja');
*
* @example <caption>Override the supported locales.</caption>
*
* // Assuming locale === 'en-us'
* // returns ['English', 'Japanese']
* __.languages(['en', 'ja']);
*
* @example <caption>Override the supported locales
and get the languages in another locale.</caption>
*
* // Assuming locale === 'en-us'
* // returns ['英語', '日本語']
* __.languages('ja', ['en', 'ja']);
*
* @return {String} Then i18ned string.
* @public
*/
* ### Example
*#### Get the current language.
*```javascript
* // assuming locale === 'en-us'
* // returns 'American English'
* __.languages();
*```
*#### Get the current language in another locale.
*```javascript
* // assuming locale === 'en-us'
* // returns 'English'
* __.language('en');
*
* // returns 'Japanese'
* __.language('ja');
*```
*/
/**
* @method languages
* @description Returns the names of the supported locale.
* @param {String | Array} arg The locale to change or the supported locales.
* @param {Array} supported The supported locales.
* @return {String} Then i18ned string.
*/
i18n.languages = (arg, supported) => {

@@ -182,23 +169,37 @@ log.debug(`class: ${API.name}`, `process: i18n.languges`);

/**
* ### Example
* #### Get the supported languages.
*```javascript
* // Assuming locale === 'en-us'
* // returns ['American English', 'Japanese']
* __.lanugages();
*```
*#### Get the current languages in another locale.
*```javascript
* // Assuming locale === 'en-us'
* // returns ['アメリカ英語', '日本語']
* __.languages('ja');
*```
*#### Override the supported locales.
*```javascript
* // Assuming locale === 'en-us'
* // returns ['English', 'Japanese']
* __.languages(['en', 'ja']);
*```
*#### Override the supported locales and get the languages in another locale.
*```javascript
* // Assuming locale === 'en-us'
* // returns ['英語', '日本語']
* __.languages('ja', ['en', 'ja']);
*```
*/
/**
* @method locale
* @description Sets or gets the locale.
* @param {String} locale The locale to set or get.
*
* @example <caption>Get the current locale.</caption>
*
* // Assuming locale === 'en-us'
* // returns 'en-us'
* __.locale()
*
* @example <caption>Set the locale.</caption>
*
* // Asumming locale === 'en-us'
* // sets and returns 'ja'
* __.locale('ja')
*
* @return {String} The locale.
* @public
*/
i18n.locale = (locale) => {
debug('api', 'debug', `class: ${API.name}`, `process: i18n.locale`);
log.debug(`class: ${API.name}`, `process: i18n.locale`);
return locale ?

@@ -232,3 +233,3 @@ core.header.setLocale(locale) :

/**
* @method l10n
* l10n
* @description Localizes date, time and numbers.

@@ -245,2 +246,17 @@ * See [Tokei](https://github.com/iwatakeshi/tokei) for documentation.

};
/**
* ### Example
* #### Get the current locale.
*```javascript
* // Assuming locale === 'en-us'
* // returns 'en-us'
* __.locale()
*```
*#### Set the locale.
*```javascript
* // Asumming locale === 'en-us'
* // sets and returns 'ja'
* __.locale('ja')
*```
*/
return {

@@ -247,0 +263,0 @@ i18n: i18n,

{
"name": "gengojs-default-api",
"version": "0.0.5",
"version": "0.0.6",
"description": "The default router plugin for gengojs",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -11,5 +11,10 @@ # gengojs-default-api

## Documentation
See [documentation](https://gengojs.github.io/plugin-api)
An example usage with options is:
```js
```javascript

@@ -33,8 +38,21 @@ var gengo = require('gengojs');

```
The default API is already included in gengo.js so you should not have to require it.
## Documentation
## Internal API
See [documentation](https://gengojs.github.io/plugin-api)
Not Applicable
## Dependencies
* `this.header.getLocale(locale:String)` from `Header`
* Should return a string of the current locale.
* `this.header.setLocale(locale:String)` from `Header`
* Should set the locale.
* `this.header.detectLocale(locale:String)` from `Header` (optional)
* Should detect the current locale by parsing the
Accept-Language, domains, sub-domains, queries, URLs, and cookies.
* `supported:Array` from `Header` options
* Should be an array of supported locales.
* `this.backend.catalog(locale:String)` from `Backend`
* Should return an object containing the dictionaries for each locale.
## Options

@@ -48,14 +66,3 @@

```
## Internal API
None
## Dependencies
* `this.header.getLocale(locale:String)` from `Header` class
* `this.header.setLocale(locale:String)` from `Header` class
* `this.header.detectLocale(locale:String)` from `Header` class (optional)
* `supported:Array` from `Header` options
* `this.backend.catalog(locale:String)` from `Backend` class
## Debug

@@ -81,3 +88,3 @@

```js
```javascript
// Using 'phrase' keyword:

@@ -84,0 +91,0 @@ __({phrase:'Hello!'});

@@ -47,15 +47,36 @@ 'use strict';

var core = this.context;
/**
* The i18n function
*/
var i18n = function i18n() {};
/**
* The l10n function
*/
var l10n = function l10n() {};
// Set the options
var options = this.options.api;
_lodash2['default'].assign(options.header = {}, this.options.header);
(0, _gengojsDebug2['default'])('api', 'info', 'options exists:', !!options);
/**
* @method i18n
* @description I18ns the arguments.
* Note: You can change ID for i18n. See Configuration.
* @param {...*} arg The arguments to internationalize.
*
* @example <caption>Phrase notation with default parser.</caption>
*
* i18ns the arguments. Note: You can change ID for i18n. See Options.
* @param {...*} arg The arguments to internationalize.
* @return {String} Then i18ned string.
*/
i18n[options.global] = function () {
log.debug('class: ' + API.name, 'process: i18n');
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return core.parse.apply(core, args);
};
/**
* ### Example
*#### Phrase notation with default parser.
*```javascript
* // Assuming the locale === 'ja',

@@ -70,5 +91,5 @@ * // a basic phrase returns 'こんにちは'

* __('Hello {{name}}', {name:'Bob'});
*
* @example <caption>Bracket notation with default parser.</caption>
*
*```
*#### Bracket notation with default parser.
*```javascript
* // Assuming the locale === 'ja',

@@ -83,5 +104,5 @@ * // a basic bracket phrase returns 'おっす'

* __('[Hello {{name}}].informal', {name:'Bob'});
*
* @example <caption>Dot notation with default parser.</caption>
*
*```
*#### Dot notation with default parser.
*```javascript
* // Assuming the locale === 'ja',

@@ -96,9 +117,8 @@ * // a basic dot phrase returns 'おっす'

* __('greeting.hello.person.informal', {name:'Bob'});
*
*```
*
* @example <caption>All notations with Message Format.</caption>
* // See [message-format](https://github.com/thetalecrafter/
message-format) for documentation.
* // See updated docs at README:
*
*#### All notations with Message Format.
* See [message-format](https://github.com/thetalecrafter/
message-format) for documentation.
* ```javascript
* // Assuming the locale === 'en-us',

@@ -108,3 +128,3 @@ * // a basic phrase with message formatting

* __('You took {n,number} pictures since
{d,date} {d,time}', { n:4000, d:new Date() });
{d,date} {d,time}', { n:4000, d:new Date() });
*

@@ -114,3 +134,3 @@ * // a basic bracket phrase with message formatting

* __('[You took {n, numbers} pictures].since.date',
{ n:4000, d:new Date() });
{ n:4000, d:new Date() });
*

@@ -120,16 +140,5 @@ * // a basic dot phrase with message formatting

* __('pictures.since.date', { n:4000, d:new Date() });
*
* @return {String} Then i18ned string.
* @public
*```
*/
i18n[options.global] = function () {
log.debug('class: ' + API.name, 'process: i18n');
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return core.parse.apply(core, args);
};
/**

@@ -139,20 +148,3 @@ * @method language

* @param {string} id The locale to change.
*
* @example <caption>Get the current language.</caption>
*
* // assuming locale === 'en-us'
* // returns 'American English'
* __.languages();
*
* @example <caption>Get the current language in another locale. </caption>
*
* // assuming locale === 'en-us'
* // returns 'English'
* __.language('en');
*
* // returns 'Japanese'
* __.language('ja');
*
* @return {String} Then i18ned string.
* @public
*/

@@ -169,36 +161,29 @@ i18n.language = function (id) {

};
/**
* @method languages
* @description Returns the names of the supported locale.
* @param {String | Array} arg The locale to change or the supported locales.
* @param {Array} supported The supported locales.
*
* @example <caption>Get the supported languages.</caption>
*
* // Assuming locale === 'en-us'
* // returns ['American English', 'Japanese']
* __.lanugages();
*
* @example <caption>Get the current languages in another locale. </caption>
*
* // Assuming locale === 'en-us'
* // returns ['アメリカ英語', '日本語']
* __.languages('ja');
*
* @example <caption>Override the supported locales.</caption>
*
* // Assuming locale === 'en-us'
* // returns ['English', 'Japanese']
* __.languages(['en', 'ja']);
*
* @example <caption>Override the supported locales
and get the languages in another locale.</caption>
*
* // Assuming locale === 'en-us'
* // returns ['英語', '日本語']
* __.languages('ja', ['en', 'ja']);
*
* @return {String} Then i18ned string.
* @public
*/
* ### Example
*#### Get the current language.
*```javascript
* // assuming locale === 'en-us'
* // returns 'American English'
* __.languages();
*```
*#### Get the current language in another locale.
*```javascript
* // assuming locale === 'en-us'
* // returns 'English'
* __.language('en');
*
* // returns 'Japanese'
* __.language('ja');
*```
*/
/**
* @method languages
* @description Returns the names of the supported locale.
* @param {String | Array} arg The locale to change or the supported locales.
* @param {Array} supported The supported locales.
* @return {String} Then i18ned string.
*/
i18n.languages = function (arg, supported) {

@@ -221,23 +206,37 @@ log.debug('class: ' + API.name, 'process: i18n.languges');

/**
* ### Example
* #### Get the supported languages.
*```javascript
* // Assuming locale === 'en-us'
* // returns ['American English', 'Japanese']
* __.lanugages();
*```
*#### Get the current languages in another locale.
*```javascript
* // Assuming locale === 'en-us'
* // returns ['アメリカ英語', '日本語']
* __.languages('ja');
*```
*#### Override the supported locales.
*```javascript
* // Assuming locale === 'en-us'
* // returns ['English', 'Japanese']
* __.languages(['en', 'ja']);
*```
*#### Override the supported locales and get the languages in another locale.
*```javascript
* // Assuming locale === 'en-us'
* // returns ['英語', '日本語']
* __.languages('ja', ['en', 'ja']);
*```
*/
/**
* @method locale
* @description Sets or gets the locale.
* @param {String} locale The locale to set or get.
*
* @example <caption>Get the current locale.</caption>
*
* // Assuming locale === 'en-us'
* // returns 'en-us'
* __.locale()
*
* @example <caption>Set the locale.</caption>
*
* // Asumming locale === 'en-us'
* // sets and returns 'ja'
* __.locale('ja')
*
* @return {String} The locale.
* @public
*/
i18n.locale = function (locale) {
(0, _gengojsDebug2['default'])('api', 'debug', 'class: ' + API.name, 'process: i18n.locale');
log.debug('class: ' + API.name, 'process: i18n.locale');
return locale ? core.header.setLocale(locale) : core.header.detectLocale ? core.header.detectLocale() : core.header.getLocale();

@@ -267,3 +266,3 @@ };

/**
* @method l10n
* l10n
* @description Localizes date, time and numbers.

@@ -285,2 +284,17 @@ * See [Tokei](https://github.com/iwatakeshi/tokei) for documentation.

};
/**
* ### Example
* #### Get the current locale.
*```javascript
* // Assuming locale === 'en-us'
* // returns 'en-us'
* __.locale()
*```
*#### Set the locale.
*```javascript
* // Asumming locale === 'en-us'
* // sets and returns 'ja'
* __.locale('ja')
*```
*/
return {

@@ -287,0 +301,0 @@ i18n: i18n,

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc