@pluginjs/i18n
Advanced tools
Comparing version 0.7.2 to 0.7.3
/*! | ||
* @pluginjs/i18n v0.7.2 (https://pluginjs.com) | ||
* @pluginjs/i18n v0.7.3 (https://pluginjs.com) | ||
* Copyright 2018 Creation Studio Limited | ||
@@ -39,3 +39,4 @@ * Released under the GPL-3.0 License. | ||
instance(options = {}) { | ||
instance() { | ||
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
const that = this; | ||
@@ -54,3 +55,5 @@ | ||
return { | ||
translate(key, args = {}, locale = _locale) { | ||
translate(key) { | ||
let args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
let locale = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _locale; | ||
let message = getMessage(key, locale); | ||
@@ -57,0 +60,0 @@ |
/*! | ||
* @pluginjs/i18n v0.7.2 (https://pluginjs.com) | ||
* @pluginjs/i18n v0.7.3 (https://pluginjs.com) | ||
* Copyright 2018 Creation Studio Limited | ||
* Released under the GPL-3.0 License. | ||
*/ | ||
"use strict";function _interopDefault(t){return t&&"object"==typeof t&&"default"in t?t.default:t}var utils=require("@pluginjs/utils"),template=_interopDefault(require("@pluginjs/template"));class I18N{constructor(t,e){this.defaults=utils.deepMerge(I18N.defaults,t),this.translations=e||{}}hasTranslation(t){return t in this.translations}addTranslation(t,e){this.translations[t]?Object.assign(this.translations[t],e):this.translations[t]=e}getTranslation(t){return this.translations[t]?this.translations[t]:{}}instance(t={}){const e=this,s=utils.deepMerge(e.defaults,t);let l=s.locale;function a(t,s){const l=e.getTranslation(s);return utils.getValueByPath(l,t)}return{translate(t,n={},i=l){let r=a(t,i);if(void 0===r&&s.fallbacks){const l=i.split("-");if(l.length>1&&e.hasTranslation(l[0])&&(r=a(t,l[0])),void 0===r){let l;r=a(t,l=!0!==s.fallbacks&&e.hasTranslation(s.fallbacks)?s.fallbacks:e.defaults.locale)}}if("[object Array]"===Object.prototype.toString.call(r)&&r.length>=2&&"string"==typeof n._number&&void 0!==n[n._number]){const t=parseInt(n[n._number],10);1===t?r=r[0]:t>1?r=r[1]:0===t&&r.length>=3&&(r=r[2])}if("string"==typeof r){const t=template.parse(r);if(!t)return r;let e;for(let l=0;l<t.length;l++)void 0===n[e=t[l]]?n[e]=s.missingPlaceholder(e):null===n[e]&&(n[e]=s.nullPlaceholder(e));return template.render(r,n)}return Object(r)===r?r:`[missing "${i}.${t}" translation]`},setLocale(t){l=t},getLocale:()=>l}}setTranslations(t){this.translations=t}}I18N.defaults={locale:"en",fallbacks:!0,nullPlaceholder:t=>`[missing {{${t}}} value]`,missingPlaceholder:t=>`[missing {{${t}}} value]`},module.exports=I18N; | ||
"use strict";function _interopDefault(t){return t&&"object"==typeof t&&"default"in t?t.default:t}var utils=require("@pluginjs/utils"),template=_interopDefault(require("@pluginjs/template"));class I18N{constructor(t,e){this.defaults=utils.deepMerge(I18N.defaults,t),this.translations=e||{}}hasTranslation(t){return t in this.translations}addTranslation(t,e){this.translations[t]?Object.assign(this.translations[t],e):this.translations[t]=e}getTranslation(t){return this.translations[t]?this.translations[t]:{}}instance(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const e=this,l=utils.deepMerge(e.defaults,t);let s=l.locale;function n(t,l){const s=e.getTranslation(l);return utils.getValueByPath(s,t)}return{translate(t){let a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:s,r=n(t,i);if(void 0===r&&l.fallbacks){const s=i.split("-");if(s.length>1&&e.hasTranslation(s[0])&&(r=n(t,s[0])),void 0===r){let s;r=n(t,s=!0!==l.fallbacks&&e.hasTranslation(l.fallbacks)?l.fallbacks:e.defaults.locale)}}if("[object Array]"===Object.prototype.toString.call(r)&&r.length>=2&&"string"==typeof a._number&&void 0!==a[a._number]){const t=parseInt(a[a._number],10);1===t?r=r[0]:t>1?r=r[1]:0===t&&r.length>=3&&(r=r[2])}if("string"==typeof r){const t=template.parse(r);if(!t)return r;let e;for(let s=0;s<t.length;s++)void 0===a[e=t[s]]?a[e]=l.missingPlaceholder(e):null===a[e]&&(a[e]=l.nullPlaceholder(e));return template.render(r,a)}return Object(r)===r?r:`[missing "${i}.${t}" translation]`},setLocale(t){s=t},getLocale:()=>s}}setTranslations(t){this.translations=t}}I18N.defaults={locale:"en",fallbacks:!0,nullPlaceholder:t=>`[missing {{${t}}} value]`,missingPlaceholder:t=>`[missing {{${t}}} value]`},module.exports=I18N; |
/*! | ||
* @pluginjs/i18n v0.7.2 (https://pluginjs.com) | ||
* @pluginjs/i18n v0.7.3 (https://pluginjs.com) | ||
* Copyright 2018 Creation Studio Limited | ||
@@ -35,3 +35,4 @@ * Released under the GPL-3.0 License. | ||
instance(options = {}) { | ||
instance() { | ||
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
const that = this; | ||
@@ -50,3 +51,5 @@ | ||
return { | ||
translate(key, args = {}, locale = _locale) { | ||
translate(key) { | ||
let args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
let locale = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _locale; | ||
let message = getMessage(key, locale); | ||
@@ -53,0 +56,0 @@ |
/*! | ||
* @pluginjs/i18n v0.7.2 (https://pluginjs.com) | ||
* @pluginjs/i18n v0.7.3 (https://pluginjs.com) | ||
* Copyright 2018 Creation Studio Limited | ||
* Released under the GPL-3.0 License. | ||
*/ | ||
import{getValueByPath,deepMerge}from"@pluginjs/utils";import template from"@pluginjs/template";class I18N{constructor(t,e){this.defaults=deepMerge(I18N.defaults,t),this.translations=e||{}}hasTranslation(t){return t in this.translations}addTranslation(t,e){this.translations[t]?Object.assign(this.translations[t],e):this.translations[t]=e}getTranslation(t){return this.translations[t]?this.translations[t]:{}}instance(t={}){const e=this,a=deepMerge(e.defaults,t);let s=a.locale;function l(t,a){const s=e.getTranslation(a);return getValueByPath(s,t)}return{translate(t,n={},r=s){let i=l(t,r);if(void 0===i&&a.fallbacks){const s=r.split("-");if(s.length>1&&e.hasTranslation(s[0])&&(i=l(t,s[0])),void 0===i){let s;i=l(t,s=!0!==a.fallbacks&&e.hasTranslation(a.fallbacks)?a.fallbacks:e.defaults.locale)}}if("[object Array]"===Object.prototype.toString.call(i)&&i.length>=2&&"string"==typeof n._number&&void 0!==n[n._number]){const t=parseInt(n[n._number],10);1===t?i=i[0]:t>1?i=i[1]:0===t&&i.length>=3&&(i=i[2])}if("string"==typeof i){const t=template.parse(i);if(!t)return i;let e;for(let s=0;s<t.length;s++)void 0===n[e=t[s]]?n[e]=a.missingPlaceholder(e):null===n[e]&&(n[e]=a.nullPlaceholder(e));return template.render(i,n)}return Object(i)===i?i:`[missing "${r}.${t}" translation]`},setLocale(t){s=t},getLocale:()=>s}}setTranslations(t){this.translations=t}}I18N.defaults={locale:"en",fallbacks:!0,nullPlaceholder:t=>`[missing {{${t}}} value]`,missingPlaceholder:t=>`[missing {{${t}}} value]`};export default I18N; | ||
import{getValueByPath,deepMerge}from"@pluginjs/utils";import template from"@pluginjs/template";class I18N{constructor(t,e){this.defaults=deepMerge(I18N.defaults,t),this.translations=e||{}}hasTranslation(t){return t in this.translations}addTranslation(t,e){this.translations[t]?Object.assign(this.translations[t],e):this.translations[t]=e}getTranslation(t){return this.translations[t]?this.translations[t]:{}}instance(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const e=this,l=deepMerge(e.defaults,t);let a=l.locale;function s(t,l){const a=e.getTranslation(l);return getValueByPath(a,t)}return{translate(t){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:a,r=s(t,i);if(void 0===r&&l.fallbacks){const a=i.split("-");if(a.length>1&&e.hasTranslation(a[0])&&(r=s(t,a[0])),void 0===r){let a;r=s(t,a=!0!==l.fallbacks&&e.hasTranslation(l.fallbacks)?l.fallbacks:e.defaults.locale)}}if("[object Array]"===Object.prototype.toString.call(r)&&r.length>=2&&"string"==typeof n._number&&void 0!==n[n._number]){const t=parseInt(n[n._number],10);1===t?r=r[0]:t>1?r=r[1]:0===t&&r.length>=3&&(r=r[2])}if("string"==typeof r){const t=template.parse(r);if(!t)return r;let e;for(let a=0;a<t.length;a++)void 0===n[e=t[a]]?n[e]=l.missingPlaceholder(e):null===n[e]&&(n[e]=l.nullPlaceholder(e));return template.render(r,n)}return Object(r)===r?r:`[missing "${i}.${t}" translation]`},setLocale(t){a=t},getLocale:()=>a}}setTranslations(t){this.translations=t}}I18N.defaults={locale:"en",fallbacks:!0,nullPlaceholder:t=>`[missing {{${t}}} value]`,missingPlaceholder:t=>`[missing {{${t}}} value]`};export default I18N; |
/*! | ||
* @pluginjs/i18n v0.7.2 (https://pluginjs.com) | ||
* @pluginjs/i18n v0.7.3 (https://pluginjs.com) | ||
* Copyright 2018 Creation Studio Limited | ||
@@ -4,0 +4,0 @@ * Released under the GPL-3.0 License. |
/*! | ||
* @pluginjs/i18n v0.7.2 (https://pluginjs.com) | ||
* @pluginjs/i18n v0.7.3 (https://pluginjs.com) | ||
* Copyright 2018 Creation Studio Limited | ||
@@ -4,0 +4,0 @@ * Released under the GPL-3.0 License. |
@@ -14,3 +14,3 @@ { | ||
}, | ||
"version": "0.7.2", | ||
"version": "0.7.3", | ||
"category": "core", | ||
@@ -37,4 +37,4 @@ "main": "dist/i18n.common.js", | ||
"dependencies": { | ||
"@pluginjs/template": "^0.7.2", | ||
"@pluginjs/utils": "^0.7.2" | ||
"@pluginjs/template": "^0.7.3", | ||
"@pluginjs/utils": "^0.7.3" | ||
}, | ||
@@ -44,3 +44,3 @@ "devDependencies": { | ||
"@pluginjs/browserslist-config": "^1.2.2", | ||
"@pluginjs/cli": "^0.7.2", | ||
"@pluginjs/cli": "^0.7.3", | ||
"babel-jest": "*", | ||
@@ -72,3 +72,3 @@ "jest": "*", | ||
"title": "Plugin", | ||
"gitHead": "f18c85114d702b75d2d67e57e43b51100f161f31" | ||
"gitHead": "304f657f71c8be62068380bd34fdc7f003082a24" | ||
} |
34453
10
692
Updated@pluginjs/template@^0.7.3
Updated@pluginjs/utils@^0.7.3