@cloudflare/intl-core
Advanced tools
Comparing version 1.1.2 to 1.1.3
@@ -6,3 +6,11 @@ # Change Log | ||
<a name="1.1.2"></a> | ||
<a name="1.1.3"></a> | ||
## [1.1.3](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/intl-core@1.1.2...@cloudflare/intl-core@1.1.3) (2018-10-29) | ||
**Note:** Version bump only for package @cloudflare/intl-core | ||
<a name="1.1.2"></a> | ||
## [1.1.2](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/intl-core@1.1.1...@cloudflare/intl-core@1.1.2) (2018-10-29) | ||
@@ -15,3 +23,3 @@ | ||
<a name="1.1.1"></a> | ||
<a name="1.1.1"></a> | ||
## [1.1.1](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/intl-core@1.1.0...@cloudflare/intl-core@1.1.1) (2018-10-26) | ||
@@ -18,0 +26,0 @@ |
@@ -30,2 +30,4 @@ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); } | ||
function Translator(options) { | ||
var _this = this; | ||
_classCallCheck(this, Translator); | ||
@@ -39,31 +41,3 @@ | ||
this.map = {}; | ||
this.options = options || {}; | ||
this.locale(options && options.locale || ESupportedLocales.en_US); //clear locale and phrases since future instances of Polyglot | ||
//created should be bases on params passed in to functions and not | ||
//initial options | ||
if (options && options.phrases) { | ||
options.phrases = undefined; | ||
} | ||
if (options && options.locale) { | ||
options.locale = undefined; | ||
} | ||
} | ||
_createClass(Translator, [{ | ||
key: "createInstance", | ||
value: function createInstance(locale) { | ||
if (this.options.pseudoLoc && this.options.phrases) { | ||
this.options.phrases = this.psudoLocalizePhrases(this.options.phrases); | ||
} | ||
this.map[locale] = new Polyglot(Object.assign(this.options, { | ||
locale: locale | ||
})); | ||
} | ||
}, { | ||
key: "psudoLocalizePhrases", | ||
value: function psudoLocalizePhrases(phrases) { | ||
_defineProperty(this, "psudoLocalizePhrases", function (phrases) { | ||
return Object.entries(phrases).reduce(function (acc, _ref) { | ||
@@ -76,39 +50,35 @@ var _ref2 = _slicedToArray(_ref, 2), | ||
}, {}); | ||
} | ||
}, { | ||
key: "getInstance", | ||
value: function getInstance(locale) { | ||
}); | ||
_defineProperty(this, "getInstance", function (locale) { | ||
if (locale) { | ||
return this.map[locale]; | ||
return _this.map[locale]; | ||
} else { | ||
return this.map[this.currentLocale]; | ||
return _this.map[_this.currentLocale]; | ||
} | ||
} | ||
}, { | ||
key: "getInstanceMatchingPhrase", | ||
value: function getInstanceMatchingPhrase(phrase) { | ||
var p = this.getInstance(); | ||
}); | ||
_defineProperty(this, "getInstanceMatchingPhrase", function (phrase) { | ||
var p = _this.getInstance(); | ||
if (p.has(phrase)) { | ||
return p; | ||
} else { | ||
return this.getInstance(ESupportedLocales.en_US); | ||
return _this.getInstance(ESupportedLocales.en_US); | ||
} | ||
} | ||
}, { | ||
key: "extend", | ||
value: function extend(phrases, locale) { | ||
var p = this.getInstance(locale); | ||
}); | ||
if (this.options.pseudoLoc) { | ||
phrases = this.psudoLocalizePhrases(phrases); | ||
_defineProperty(this, "extend", function (phrases, locale) { | ||
var p = _this.getInstance(locale); | ||
if (_this.options.pseudoLoc) { | ||
phrases = _this.psudoLocalizePhrases(phrases); | ||
} | ||
p.extend(phrases); | ||
} | ||
}, { | ||
key: "t", | ||
value: function t(phrase, arg) { | ||
var p = this.getInstanceMatchingPhrase(phrase); | ||
}); | ||
_defineProperty(this, "t", function (phrase, arg) { | ||
var p = _this.getInstanceMatchingPhrase(phrase); | ||
if (arg) { | ||
@@ -123,47 +93,41 @@ if (typeof arg === 'number') { | ||
return p.t(phrase); | ||
} | ||
}, { | ||
key: "tm", | ||
value: function tm(phrase, arg) { | ||
return markdown(this.t(phrase, arg)); | ||
} | ||
}, { | ||
key: "clear", | ||
value: function clear() { | ||
this.getInstance().clear(); | ||
} | ||
}, { | ||
key: "replace", | ||
value: function replace(phrases) { | ||
if (this.options.pseudoLoc) { | ||
phrases = this.psudoLocalizePhrases(phrases); | ||
}); | ||
_defineProperty(this, "tm", function (phrase, arg) { | ||
return markdown(_this.t(phrase, arg)); | ||
}); | ||
_defineProperty(this, "clear", function () { | ||
_this.getInstance().clear(); | ||
}); | ||
_defineProperty(this, "replace", function (phrases) { | ||
if (_this.options.pseudoLoc) { | ||
phrases = _this.psudoLocalizePhrases(phrases); | ||
} | ||
this.getInstance().replace(phrases); | ||
} | ||
}, { | ||
key: "locale", | ||
value: function locale(_locale) { | ||
if (_locale) { | ||
this.currentLocale = _locale; | ||
_this.getInstance().replace(phrases); | ||
}); | ||
if (!this.map[_locale]) { | ||
this.createInstance(_locale); | ||
_defineProperty(this, "locale", function (locale) { | ||
if (locale) { | ||
_this.currentLocale = locale; | ||
if (!_this.map[locale]) { | ||
_this.createInstance(locale); | ||
} | ||
} | ||
return this.currentLocale; | ||
} | ||
}, { | ||
key: "has", | ||
value: function has(phrase) { | ||
return this.getInstanceMatchingPhrase(phrase).has(phrase); | ||
} | ||
}, { | ||
key: "translateSeconds", | ||
value: function translateSeconds(seconds) { | ||
return _this.currentLocale; | ||
}); | ||
_defineProperty(this, "has", function (phrase) { | ||
return _this.getInstanceMatchingPhrase(phrase).has(phrase); | ||
}); | ||
_defineProperty(this, "translateSeconds", function (seconds) { | ||
// Prevent 0 seconds returning "0 days" | ||
if (Number(seconds) !== 0) { | ||
if (seconds % 86400 === 0) { | ||
return this.t('time.num_days', { | ||
return _this.t('time.num_days', { | ||
smart_count: seconds / 86400 | ||
@@ -174,3 +138,3 @@ }); | ||
if (seconds % 3600 === 0) { | ||
return this.t('time.num_hours', { | ||
return _this.t('time.num_hours', { | ||
smart_count: seconds / 3600 | ||
@@ -181,3 +145,3 @@ }); | ||
if (seconds % 60 === 0) { | ||
return this.t('time.num_minutes', { | ||
return _this.t('time.num_minutes', { | ||
smart_count: seconds / 60 | ||
@@ -188,11 +152,37 @@ }); | ||
return this.t('time.num_seconds', { | ||
return _this.t('time.num_seconds', { | ||
smart_count: seconds | ||
}); | ||
}); | ||
_defineProperty(this, "translateObject", function (phrases) { | ||
return mapValues(phrases, _this.t); | ||
}); | ||
this.map = {}; | ||
this.options = options || {}; | ||
this.locale(options && options.locale || ESupportedLocales.en_US); //clear locale and phrases since future instances of Polyglot | ||
//created should be bases on params passed in to functions and not | ||
//initial options | ||
if (options && options.phrases) { | ||
options.phrases = undefined; | ||
} | ||
}, { | ||
key: "translateObject", | ||
value: function translateObject(phrases) { | ||
return mapValues(phrases, this.t); | ||
if (options && options.locale) { | ||
options.locale = undefined; | ||
} | ||
} | ||
_createClass(Translator, [{ | ||
key: "createInstance", | ||
value: function createInstance(locale) { | ||
if (this.options.pseudoLoc && this.options.phrases) { | ||
this.options.phrases = this.psudoLocalizePhrases(this.options.phrases); | ||
} | ||
this.map[locale] = new Polyglot(Object.assign(this.options, { | ||
locale: locale | ||
})); | ||
} | ||
}]); | ||
@@ -199,0 +189,0 @@ |
@@ -44,2 +44,4 @@ "use strict"; | ||
function Translator(options) { | ||
var _this = this; | ||
_classCallCheck(this, Translator); | ||
@@ -53,31 +55,3 @@ | ||
this.map = {}; | ||
this.options = options || {}; | ||
this.locale(options && options.locale || _types.ESupportedLocales.en_US); //clear locale and phrases since future instances of Polyglot | ||
//created should be bases on params passed in to functions and not | ||
//initial options | ||
if (options && options.phrases) { | ||
options.phrases = undefined; | ||
} | ||
if (options && options.locale) { | ||
options.locale = undefined; | ||
} | ||
} | ||
_createClass(Translator, [{ | ||
key: "createInstance", | ||
value: function createInstance(locale) { | ||
if (this.options.pseudoLoc && this.options.phrases) { | ||
this.options.phrases = this.psudoLocalizePhrases(this.options.phrases); | ||
} | ||
this.map[locale] = new _nodePolyglot.default(Object.assign(this.options, { | ||
locale: locale | ||
})); | ||
} | ||
}, { | ||
key: "psudoLocalizePhrases", | ||
value: function psudoLocalizePhrases(phrases) { | ||
_defineProperty(this, "psudoLocalizePhrases", function (phrases) { | ||
return Object.entries(phrases).reduce(function (acc, _ref) { | ||
@@ -90,39 +64,35 @@ var _ref2 = _slicedToArray(_ref, 2), | ||
}, {}); | ||
} | ||
}, { | ||
key: "getInstance", | ||
value: function getInstance(locale) { | ||
}); | ||
_defineProperty(this, "getInstance", function (locale) { | ||
if (locale) { | ||
return this.map[locale]; | ||
return _this.map[locale]; | ||
} else { | ||
return this.map[this.currentLocale]; | ||
return _this.map[_this.currentLocale]; | ||
} | ||
} | ||
}, { | ||
key: "getInstanceMatchingPhrase", | ||
value: function getInstanceMatchingPhrase(phrase) { | ||
var p = this.getInstance(); | ||
}); | ||
_defineProperty(this, "getInstanceMatchingPhrase", function (phrase) { | ||
var p = _this.getInstance(); | ||
if (p.has(phrase)) { | ||
return p; | ||
} else { | ||
return this.getInstance(_types.ESupportedLocales.en_US); | ||
return _this.getInstance(_types.ESupportedLocales.en_US); | ||
} | ||
} | ||
}, { | ||
key: "extend", | ||
value: function extend(phrases, locale) { | ||
var p = this.getInstance(locale); | ||
}); | ||
if (this.options.pseudoLoc) { | ||
phrases = this.psudoLocalizePhrases(phrases); | ||
_defineProperty(this, "extend", function (phrases, locale) { | ||
var p = _this.getInstance(locale); | ||
if (_this.options.pseudoLoc) { | ||
phrases = _this.psudoLocalizePhrases(phrases); | ||
} | ||
p.extend(phrases); | ||
} | ||
}, { | ||
key: "t", | ||
value: function t(phrase, arg) { | ||
var p = this.getInstanceMatchingPhrase(phrase); | ||
}); | ||
_defineProperty(this, "t", function (phrase, arg) { | ||
var p = _this.getInstanceMatchingPhrase(phrase); | ||
if (arg) { | ||
@@ -137,47 +107,41 @@ if (typeof arg === 'number') { | ||
return p.t(phrase); | ||
} | ||
}, { | ||
key: "tm", | ||
value: function tm(phrase, arg) { | ||
return (0, _utilMarkdown.default)(this.t(phrase, arg)); | ||
} | ||
}, { | ||
key: "clear", | ||
value: function clear() { | ||
this.getInstance().clear(); | ||
} | ||
}, { | ||
key: "replace", | ||
value: function replace(phrases) { | ||
if (this.options.pseudoLoc) { | ||
phrases = this.psudoLocalizePhrases(phrases); | ||
}); | ||
_defineProperty(this, "tm", function (phrase, arg) { | ||
return (0, _utilMarkdown.default)(_this.t(phrase, arg)); | ||
}); | ||
_defineProperty(this, "clear", function () { | ||
_this.getInstance().clear(); | ||
}); | ||
_defineProperty(this, "replace", function (phrases) { | ||
if (_this.options.pseudoLoc) { | ||
phrases = _this.psudoLocalizePhrases(phrases); | ||
} | ||
this.getInstance().replace(phrases); | ||
} | ||
}, { | ||
key: "locale", | ||
value: function locale(_locale) { | ||
if (_locale) { | ||
this.currentLocale = _locale; | ||
_this.getInstance().replace(phrases); | ||
}); | ||
if (!this.map[_locale]) { | ||
this.createInstance(_locale); | ||
_defineProperty(this, "locale", function (locale) { | ||
if (locale) { | ||
_this.currentLocale = locale; | ||
if (!_this.map[locale]) { | ||
_this.createInstance(locale); | ||
} | ||
} | ||
return this.currentLocale; | ||
} | ||
}, { | ||
key: "has", | ||
value: function has(phrase) { | ||
return this.getInstanceMatchingPhrase(phrase).has(phrase); | ||
} | ||
}, { | ||
key: "translateSeconds", | ||
value: function translateSeconds(seconds) { | ||
return _this.currentLocale; | ||
}); | ||
_defineProperty(this, "has", function (phrase) { | ||
return _this.getInstanceMatchingPhrase(phrase).has(phrase); | ||
}); | ||
_defineProperty(this, "translateSeconds", function (seconds) { | ||
// Prevent 0 seconds returning "0 days" | ||
if (Number(seconds) !== 0) { | ||
if (seconds % 86400 === 0) { | ||
return this.t('time.num_days', { | ||
return _this.t('time.num_days', { | ||
smart_count: seconds / 86400 | ||
@@ -188,3 +152,3 @@ }); | ||
if (seconds % 3600 === 0) { | ||
return this.t('time.num_hours', { | ||
return _this.t('time.num_hours', { | ||
smart_count: seconds / 3600 | ||
@@ -195,3 +159,3 @@ }); | ||
if (seconds % 60 === 0) { | ||
return this.t('time.num_minutes', { | ||
return _this.t('time.num_minutes', { | ||
smart_count: seconds / 60 | ||
@@ -202,11 +166,37 @@ }); | ||
return this.t('time.num_seconds', { | ||
return _this.t('time.num_seconds', { | ||
smart_count: seconds | ||
}); | ||
}); | ||
_defineProperty(this, "translateObject", function (phrases) { | ||
return (0, _lodash.mapValues)(phrases, _this.t); | ||
}); | ||
this.map = {}; | ||
this.options = options || {}; | ||
this.locale(options && options.locale || _types.ESupportedLocales.en_US); //clear locale and phrases since future instances of Polyglot | ||
//created should be bases on params passed in to functions and not | ||
//initial options | ||
if (options && options.phrases) { | ||
options.phrases = undefined; | ||
} | ||
}, { | ||
key: "translateObject", | ||
value: function translateObject(phrases) { | ||
return (0, _lodash.mapValues)(phrases, this.t); | ||
if (options && options.locale) { | ||
options.locale = undefined; | ||
} | ||
} | ||
_createClass(Translator, [{ | ||
key: "createInstance", | ||
value: function createInstance(locale) { | ||
if (this.options.pseudoLoc && this.options.phrases) { | ||
this.options.phrases = this.psudoLocalizePhrases(this.options.phrases); | ||
} | ||
this.map[locale] = new _nodePolyglot.default(Object.assign(this.options, { | ||
locale: locale | ||
})); | ||
} | ||
}]); | ||
@@ -213,0 +203,0 @@ |
{ | ||
"name": "@cloudflare/intl-core", | ||
"description": "", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"types": "./src", | ||
@@ -6,0 +6,0 @@ "main": "lib/index.js", |
@@ -55,3 +55,3 @@ import Polyglot from 'node-polyglot'; | ||
psudoLocalizePhrases(phrases: IPhrases) { | ||
psudoLocalizePhrases = (phrases: IPhrases) => { | ||
return Object.entries(phrases).reduce( | ||
@@ -62,5 +62,5 @@ (acc, [key, value]) => | ||
); | ||
} | ||
}; | ||
getInstance(locale?: ESupportedLocales) { | ||
getInstance = (locale?: ESupportedLocales) => { | ||
if (locale) { | ||
@@ -71,5 +71,5 @@ return this.map[locale]; | ||
} | ||
} | ||
}; | ||
getInstanceMatchingPhrase(phrase: string) { | ||
getInstanceMatchingPhrase = (phrase: string) => { | ||
const p = this.getInstance(); | ||
@@ -82,5 +82,5 @@ | ||
} | ||
} | ||
}; | ||
extend(phrases: IPhrases, locale?: ESupportedLocales) { | ||
extend = (phrases: IPhrases, locale?: ESupportedLocales) => { | ||
const p = this.getInstance(locale); | ||
@@ -93,5 +93,5 @@ | ||
p.extend(phrases); | ||
} | ||
}; | ||
t(phrase: string, arg?: number | Polyglot.InterpolationOptions) { | ||
t = (phrase: string, arg?: number | Polyglot.InterpolationOptions) => { | ||
const p = this.getInstanceMatchingPhrase(phrase); | ||
@@ -107,13 +107,13 @@ | ||
return p.t(phrase); | ||
} | ||
}; | ||
tm(phrase: string, arg?: number | Polyglot.InterpolationOptions) { | ||
tm = (phrase: string, arg?: number | Polyglot.InterpolationOptions) => { | ||
return markdown(this.t(phrase, arg)); | ||
} | ||
}; | ||
clear() { | ||
clear = () => { | ||
this.getInstance().clear(); | ||
} | ||
}; | ||
replace(phrases: IPhrases) { | ||
replace = (phrases: IPhrases) => { | ||
if (this.options.pseudoLoc) { | ||
@@ -124,5 +124,5 @@ phrases = this.psudoLocalizePhrases(phrases); | ||
this.getInstance().replace(phrases); | ||
} | ||
}; | ||
locale(locale?: ESupportedLocales) { | ||
locale = (locale?: ESupportedLocales) => { | ||
if (locale) { | ||
@@ -135,9 +135,9 @@ this.currentLocale = locale; | ||
return this.currentLocale; | ||
} | ||
}; | ||
has(phrase: string) { | ||
has = (phrase: string) => { | ||
return this.getInstanceMatchingPhrase(phrase).has(phrase); | ||
} | ||
}; | ||
translateSeconds(seconds: number) { | ||
translateSeconds = (seconds: number) => { | ||
// Prevent 0 seconds returning "0 days" | ||
@@ -165,9 +165,9 @@ if (Number(seconds) !== 0) { | ||
}); | ||
} | ||
}; | ||
translateObject(phrases: IPhrases) { | ||
translateObject = (phrases: IPhrases) => { | ||
return mapValues(phrases, this.t); | ||
} | ||
}; | ||
} | ||
export default Translator; |
36209
697