@lingui/core
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -16,7 +16,8 @@ 'use strict'; | ||
function date(language) { | ||
function date(locales) { | ||
var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var formatter = new Intl.DateTimeFormat(language, format); | ||
var formatter = new Intl.DateTimeFormat(locales, format); | ||
return function (value) { | ||
if (typeof value === "string") value = new Date(value); | ||
return formatter.format(value); | ||
@@ -26,6 +27,7 @@ }; | ||
function number(language) { | ||
function number(locales) { | ||
var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var formatter = new Intl.NumberFormat(language, format); | ||
var formatter = new Intl.NumberFormat(locales, format); | ||
return function (value) { | ||
@@ -52,5 +54,7 @@ return formatter.format(value); | ||
var defaultFormats = function defaultFormats(language) { | ||
var languageData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var formats = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var defaultFormats = function defaultFormats(language, locales) { | ||
var languageData = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var formats = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
locales = locales || language; | ||
var plurals$$1 = languageData.plurals; | ||
@@ -61,3 +65,2 @@ | ||
}; | ||
var replaceOctothorpe = function replaceOctothorpe(value, message) { | ||
@@ -67,4 +70,6 @@ return function (ctx) { | ||
var norm = Array.isArray(msg) ? msg : [msg]; | ||
var formatter = new Intl.NumberFormat(locales); | ||
var valueStr = formatter.format(value); | ||
return norm.map(function (m) { | ||
return isString(m) ? m.replace("#", value) : m; | ||
return isString(m) ? m.replace("#", valueStr) : m; | ||
}); | ||
@@ -98,7 +103,7 @@ }; | ||
number: function number$$1(value, format) { | ||
return number(language, style(format))(value); | ||
return number(locales, style(format))(value); | ||
}, | ||
date: function date$$1(value, format) { | ||
return date(language, style(format))(value); | ||
return date(locales, style(format))(value); | ||
}, | ||
@@ -118,2 +123,3 @@ | ||
* @param language - Language of message | ||
* @param locales - Locales to be used when formatting the numbers or dates | ||
* @param values - Parameters for variable interpolation | ||
@@ -126,2 +132,3 @@ * @param languageData - Language data (e.g: plurals) | ||
var language = _ref3.language, | ||
locales = _ref3.locales, | ||
values = _ref3.values, | ||
@@ -131,3 +138,3 @@ formats = _ref3.formats, | ||
var formatters = defaultFormats(language, languageData, formats); | ||
var formatters = defaultFormats(language, locales, languageData, formats); | ||
@@ -144,3 +151,3 @@ var ctx = function ctx(name, type, format) { | ||
function interpolate(translation, language, languageData) { | ||
function interpolate(translation, language, locales, languageData) { | ||
return function (values) { | ||
@@ -151,2 +158,3 @@ var formats = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
language: language, | ||
locales: locales, | ||
languageData: languageData, | ||
@@ -184,10 +192,15 @@ formats: formats, | ||
offset = _ref$offset === undefined ? 0 : _ref$offset, | ||
locales = _ref.locales, | ||
format = _ref.format, | ||
other = _ref.other, | ||
pluralForms = _objectWithoutProperties(_ref, ["value", "offset", "other"]); | ||
pluralForms = _objectWithoutProperties(_ref, ["value", "offset", "locales", "format", "other"]); | ||
if (locales === undefined) locales = i18n.locales || i18n.language; | ||
var diff = value - offset; | ||
var diffAsString = number(locales, format)(diff); | ||
var translation = pluralForms[value.toString()] || // exact match | ||
pluralForms[i18n.pluralForm(diff, type)] || // plural form | ||
other; // fallback | ||
return translation.replace("#", diff.toString()); | ||
return translation.replace("#", diffAsString); | ||
}; | ||
@@ -309,3 +322,3 @@ }; | ||
// Messages/langauge data in active language. | ||
// Messages/language data in active language. | ||
// This is optimization, so we don't perform object lookup | ||
@@ -362,3 +375,3 @@ // _catalogs[language] for each translation. | ||
key: "activate", | ||
value: function activate(language) { | ||
value: function activate(language, locales) { | ||
if (!language) return; | ||
@@ -373,2 +386,3 @@ | ||
this._language = language; | ||
this._locales = locales; | ||
this._cacheActiveLanguage(); | ||
@@ -378,5 +392,6 @@ } | ||
key: "use", | ||
value: function use(language) { | ||
value: function use(language, locales) { | ||
return setupI18n({ | ||
language: language, | ||
locales: locales, | ||
catalogs: this._catalogs, | ||
@@ -408,3 +423,3 @@ development: this._dev | ||
if (typeof translation !== "function") return translation; | ||
return interpolate(translation, this.language, this.languageData)(values, formats); | ||
return interpolate(translation, this.language, this.locales, this.languageData)(values, formats); | ||
} | ||
@@ -430,2 +445,7 @@ }, { | ||
}, { | ||
key: "locales", | ||
get: function get() { | ||
return this._locales; | ||
} | ||
}, { | ||
key: "messages", | ||
@@ -455,3 +475,3 @@ get: function get() { | ||
if (params.catalogs) i18n.load(params.catalogs); | ||
if (params.language) i18n.activate(params.language); | ||
if (params.language) i18n.activate(params.language, params.locales); | ||
@@ -458,0 +478,0 @@ return i18n; |
@@ -1,14 +0,14 @@ | ||
'use strict';var d=d||{};d.scope={};d.ASSUME_ES5=!1;d.ASSUME_NO_NATIVE_MAP=!1;d.ASSUME_NO_NATIVE_SET=!1;d.defineProperty=d.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(a,c,e){a!=Array.prototype&&a!=Object.prototype&&(a[c]=e.value)};d.getGlobal=function(a){return"undefined"!=typeof window&&window===a?a:"undefined"!=typeof global&&null!=global?global:a};d.global=d.getGlobal(this);d.SYMBOL_PREFIX="jscomp_symbol_"; | ||
d.initSymbol=function(){d.initSymbol=function(){};d.global.Symbol||(d.global.Symbol=d.Symbol)};d.Symbol=function(){var a=0;return function(c){return d.SYMBOL_PREFIX+(c||"")+a++}}();d.initSymbolIterator=function(){d.initSymbol();var a=d.global.Symbol.iterator;a||(a=d.global.Symbol.iterator=d.global.Symbol("iterator"));"function"!=typeof Array.prototype[a]&&d.defineProperty(Array.prototype,a,{configurable:!0,writable:!0,value:function(){return d.arrayIterator(this)}});d.initSymbolIterator=function(){}}; | ||
d.arrayIterator=function(a){var c=0;return d.iteratorPrototype(function(){return c<a.length?{done:!1,value:a[c++]}:{done:!0}})};d.iteratorPrototype=function(a){d.initSymbolIterator();a={next:a};a[d.global.Symbol.iterator]=function(){return this};return a}; | ||
d.iteratorFromArray=function(a,c){d.initSymbolIterator();a instanceof String&&(a+="");var e=0,b={next:function(){if(e<a.length){var f=e++;return{value:c(f,a[f]),done:!1}}b.next=function(){return{done:!0,value:void 0}};return b.next()}};b[Symbol.iterator]=function(){return b};return b}; | ||
d.polyfill=function(a,c){if(c){var e=d.global;a=a.split(".");for(var b=0;b<a.length-1;b++){var f=a[b];f in e||(e[f]={});e=e[f]}a=a[a.length-1];b=e[a];c=c(b);c!=b&&null!=c&&d.defineProperty(e,a,{configurable:!0,writable:!0,value:c})}};d.polyfill("Array.prototype.values",function(a){return a?a:function(){return d.iteratorFromArray(this,function(a,e){return e})}},"es8","es3");function g(a){return a&&"object"===typeof a&&"default"in a?a["default"]:a} | ||
var h=g(require("babel-runtime/helpers/objectWithoutProperties")),k=g(require("babel-runtime/helpers/extends")),l=g(require("babel-runtime/core-js/object/keys")),m=g(require("babel-runtime/helpers/typeof")),n=g(require("babel-runtime/helpers/classCallCheck")),p=g(require("babel-runtime/helpers/createClass"));function q(a){var c=new Intl.DateTimeFormat(a,1<arguments.length&&void 0!==arguments[1]?arguments[1]:{});return function(a){return c.format(a)}} | ||
function r(a){var c=new Intl.NumberFormat(a,1<arguments.length&&void 0!==arguments[1]?arguments[1]:{});return function(a){return c.format(a)}} | ||
function t(a){function c(a,c){return function(b){b="function"===typeof c?c(b):c;return(Array.isArray(b)?b:[b]).map(function(c){return"string"===typeof c?c.replace("#",a):c})}}function e(a){return"string"===typeof a?b[a]||{style:a}:a}var b=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},f=(1<arguments.length&&void 0!==arguments[1]?arguments[1]:{}).plurals;return{plural:function(a,b){var e=b.offset;e=void 0===e?0:e;b=h(b,["offset"]);b=b[a]||b[f(a-e)];return c(a-e,b)},selectordinal:function(a, | ||
b){var e=b.offset;e=void 0===e?0:e;b=h(b,["offset"]);b=b[a]||b[f(a-e,!0)];return c(a-e,b)},select:function(a,c){return c[a]||c.other},number:function(c,b){return r(a,e(b))(c)},date:function(c,b){return q(a,e(b))(c)},undefined:function(a){return a}}}function u(a){var c=a.values,e=t(a.language,a.languageData,a.formats);return function x(a,v,w){a=e[v](c[a],w);a="function"===typeof a?a(x):a;return Array.isArray(a)?a.join(""):a}} | ||
function y(a,c,e){return function(b){var f=a(u({language:c,languageData:e,formats:1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},values:b}));return Array.isArray(f)?f.join("").trim():f}} | ||
var A=function(){function a(){n(this,a);this._activeMessages={};this._catalogs={}}p(a,[{key:"_cacheActiveLanguage",value:function(){var a=this._catalogs[this.language],e=(a||{}).languageData||{};this._activeMessages=(a||{}).messages||{};this._activeLanguageData=e}},{key:"load",value:function(a){var c=this;"object"===("undefined"===typeof a?"undefined":m(a))&&(l(k({},this._catalogs,a)).forEach(function(b){c._catalogs[b]={messages:k({},(c._catalogs[b]||{}).messages||{},(a[b]||{}).messages||{}),languageData:k({}, | ||
(c._catalogs[b]||{}).languageData||{},(a[b]||{}).languageData||{})}}),this._cacheActiveLanguage())}},{key:"activate",value:function(a){a&&(this._language=a,this._cacheActiveLanguage())}},{key:"use",value:function(a){return z({language:a,catalogs:this._catalogs,development:this._dev})}},{key:"_",value:function(a){var c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},b=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},f=b.defaults;b=b.formats;b=void 0===b?{}:b;f=this.messages[a]|| | ||
f||a;return"function"!==typeof f?f:y(f,this.language,this.languageData)(c,b)}},{key:"pluralForm",value:function(a){return this.languageData.plurals?this.languageData.plurals(a,"ordinal"===(1<arguments.length&&void 0!==arguments[1]?arguments[1]:"cardinal")):"other"}},{key:"availableLanguages",get:function(){return l(this._catalogs)}},{key:"language",get:function(){return this._language}},{key:"messages",get:function(){return this._activeMessages}},{key:"languageData",get:function(){return this._activeLanguageData}}]); | ||
return a}();function z(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},c=new A;a.catalogs&&c.load(a.catalogs);a.language&&c.activate(a.language);return c}var B=z(),C=Object.freeze({i18nMark:function(a){return a},i18n:B,setupI18n:z,date:q,number:r});module.exports=C; | ||
'use strict';var d=d||{};d.scope={};d.ASSUME_ES5=!1;d.ASSUME_NO_NATIVE_MAP=!1;d.ASSUME_NO_NATIVE_SET=!1;d.defineProperty=d.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(a,b,e){a!=Array.prototype&&a!=Object.prototype&&(a[b]=e.value)};d.getGlobal=function(a){return"undefined"!=typeof window&&window===a?a:"undefined"!=typeof global&&null!=global?global:a};d.global=d.getGlobal(this);d.SYMBOL_PREFIX="jscomp_symbol_"; | ||
d.initSymbol=function(){d.initSymbol=function(){};d.global.Symbol||(d.global.Symbol=d.Symbol)};d.Symbol=function(){var a=0;return function(b){return d.SYMBOL_PREFIX+(b||"")+a++}}();d.initSymbolIterator=function(){d.initSymbol();var a=d.global.Symbol.iterator;a||(a=d.global.Symbol.iterator=d.global.Symbol("iterator"));"function"!=typeof Array.prototype[a]&&d.defineProperty(Array.prototype,a,{configurable:!0,writable:!0,value:function(){return d.arrayIterator(this)}});d.initSymbolIterator=function(){}}; | ||
d.arrayIterator=function(a){var b=0;return d.iteratorPrototype(function(){return b<a.length?{done:!1,value:a[b++]}:{done:!0}})};d.iteratorPrototype=function(a){d.initSymbolIterator();a={next:a};a[d.global.Symbol.iterator]=function(){return this};return a}; | ||
d.iteratorFromArray=function(a,b){d.initSymbolIterator();a instanceof String&&(a+="");var e=0,c={next:function(){if(e<a.length){var f=e++;return{value:b(f,a[f]),done:!1}}c.next=function(){return{done:!0,value:void 0}};return c.next()}};c[Symbol.iterator]=function(){return c};return c}; | ||
d.polyfill=function(a,b){if(b){var e=d.global;a=a.split(".");for(var c=0;c<a.length-1;c++){var f=a[c];f in e||(e[f]={});e=e[f]}a=a[a.length-1];c=e[a];b=b(c);b!=c&&null!=b&&d.defineProperty(e,a,{configurable:!0,writable:!0,value:b})}};d.polyfill("Array.prototype.values",function(a){return a?a:function(){return d.iteratorFromArray(this,function(a,e){return e})}},"es8","es3");function h(a){return a&&"object"===typeof a&&"default"in a?a["default"]:a} | ||
var l=h(require("babel-runtime/helpers/objectWithoutProperties")),m=h(require("babel-runtime/helpers/extends")),n=h(require("babel-runtime/core-js/object/keys")),p=h(require("babel-runtime/helpers/typeof")),q=h(require("babel-runtime/helpers/classCallCheck")),r=h(require("babel-runtime/helpers/createClass"));function t(a){var b=new Intl.DateTimeFormat(a,1<arguments.length&&void 0!==arguments[1]?arguments[1]:{});return function(a){"string"===typeof a&&(a=new Date(a));return b.format(a)}} | ||
function u(a){var b=new Intl.NumberFormat(a,1<arguments.length&&void 0!==arguments[1]?arguments[1]:{});return function(a){return b.format(a)}} | ||
function v(a,b){function e(a,e){return function(c){c="function"===typeof e?e(c):e;c=Array.isArray(c)?c:[c];var f=(new Intl.NumberFormat(b)).format(a);return c.map(function(a){return"string"===typeof a?a.replace("#",f):a})}}function c(a){return"string"===typeof a?g[a]||{style:a}:a}var f=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},g=3<arguments.length&&void 0!==arguments[3]?arguments[3]:{};b=b||a;var k=f.plurals;return{plural:function(a,b){var c=b.offset;c=void 0===c?0:c;b=l(b,["offset"]); | ||
b=b[a]||b[k(a-c)];return e(a-c,b)},selectordinal:function(a,b){var c=b.offset;c=void 0===c?0:c;b=l(b,["offset"]);b=b[a]||b[k(a-c,!0)];return e(a-c,b)},select:function(a,b){return b[a]||b.other},number:function(a,e){return u(b,c(e))(a)},date:function(a,e){return t(b,c(e))(a)},undefined:function(a){return a}}}function w(a){var b=a.values,e=v(a.language,a.locales,a.languageData,a.formats);return function x(a,g,k){a=e[g](b[a],k);a="function"===typeof a?a(x):a;return Array.isArray(a)?a.join(""):a}} | ||
function y(a,b,e,c){return function(f){var g=a(w({language:b,locales:e,languageData:c,formats:1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},values:f}));return Array.isArray(g)?g.join("").trim():g}} | ||
var A=function(){function a(){q(this,a);this._activeMessages={};this._catalogs={}}r(a,[{key:"_cacheActiveLanguage",value:function(){var a=this._catalogs[this.language],e=(a||{}).languageData||{};this._activeMessages=(a||{}).messages||{};this._activeLanguageData=e}},{key:"load",value:function(a){var b=this;"object"===("undefined"===typeof a?"undefined":p(a))&&(n(m({},this._catalogs,a)).forEach(function(c){b._catalogs[c]={messages:m({},(b._catalogs[c]||{}).messages||{},(a[c]||{}).messages||{}),languageData:m({}, | ||
(b._catalogs[c]||{}).languageData||{},(a[c]||{}).languageData||{})}}),this._cacheActiveLanguage())}},{key:"activate",value:function(a,e){a&&(this._language=a,this._locales=e,this._cacheActiveLanguage())}},{key:"use",value:function(a,e){return z({language:a,locales:e,catalogs:this._catalogs,development:this._dev})}},{key:"_",value:function(a){var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},c=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},f=c.defaults;c=c.formats;c=void 0=== | ||
c?{}:c;f=this.messages[a]||f||a;return"function"!==typeof f?f:y(f,this.language,this.locales,this.languageData)(b,c)}},{key:"pluralForm",value:function(a){return this.languageData.plurals?this.languageData.plurals(a,"ordinal"===(1<arguments.length&&void 0!==arguments[1]?arguments[1]:"cardinal")):"other"}},{key:"availableLanguages",get:function(){return n(this._catalogs)}},{key:"language",get:function(){return this._language}},{key:"locales",get:function(){return this._locales}},{key:"messages",get:function(){return this._activeMessages}}, | ||
{key:"languageData",get:function(){return this._activeLanguageData}}]);return a}();function z(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},b=new A;a.catalogs&&b.load(a.catalogs);a.language&&b.activate(a.language,a.locales);return b}var B=z(),C=Object.freeze({i18nMark:function(a){return a},i18n:B,setupI18n:z,date:t,number:u});module.exports=C; |
{ | ||
"name": "@lingui/core", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "I18n tools for javascript", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22700
421