@lingui/core
Advanced tools
Comparing version 2.7.0 to 3.0.0-1
@@ -7,12 +7,8 @@ 'use strict'; | ||
var _Object$getOwnPropertyNames = _interopDefault(require('babel-runtime/core-js/object/get-own-property-names')); | ||
var _objectWithoutProperties = _interopDefault(require('babel-runtime/helpers/objectWithoutProperties')); | ||
var _extends = _interopDefault(require('babel-runtime/helpers/extends')); | ||
var _objectWithoutProperties = _interopDefault(require('@babel/runtime/helpers/objectWithoutProperties')); | ||
var _objectSpread = _interopDefault(require('@babel/runtime/helpers/objectSpread')); | ||
var messageformatParser = require('messageformat-parser'); | ||
var _slicedToArray = _interopDefault(require('babel-runtime/helpers/slicedToArray')); | ||
var _slicedToArray = _interopDefault(require('@babel/runtime/helpers/slicedToArray')); | ||
var plurals = _interopDefault(require('make-plural/umd/plurals')); | ||
var _Object$keys = _interopDefault(require('babel-runtime/core-js/object/keys')); | ||
var _typeof = _interopDefault(require('babel-runtime/helpers/typeof')); | ||
var _classCallCheck = _interopDefault(require('babel-runtime/helpers/classCallCheck')); | ||
var _createClass = _interopDefault(require('babel-runtime/helpers/createClass')); | ||
var _typeof = _interopDefault(require('@babel/runtime/helpers/typeof')); | ||
@@ -28,7 +24,5 @@ var isString = function isString(s) { | ||
if (obj === null || obj === undefined) return true; | ||
if (obj.length > 0) return false; | ||
if (obj.length === 0) return true; | ||
return !_Object$getOwnPropertyNames(obj).length; | ||
return !Object.getOwnPropertyNames(obj).length; | ||
} | ||
@@ -38,3 +32,2 @@ | ||
var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var formatter = new Intl.DateTimeFormat(locales, format); | ||
@@ -46,6 +39,4 @@ return function (value) { | ||
} | ||
function number(locales) { | ||
var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var formatter = new Intl.NumberFormat(locales, format); | ||
@@ -57,12 +48,14 @@ return function (value) { | ||
var defaultFormats = function defaultFormats(language, locales) { | ||
var languageData = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var defaultFormats = function defaultFormats(locale, locales) { | ||
var localeData = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var formats = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
locales = locales || locale; | ||
var plurals$$1 = localeData.plurals; | ||
locales = locales || language; | ||
var plurals$$1 = languageData.plurals; | ||
var style = function style(format) { | ||
return isString(format) ? formats[format] || { style: format } : format; | ||
return isString(format) ? formats[format] || { | ||
style: format | ||
} : format; | ||
}; | ||
var replaceOctothorpe = function replaceOctothorpe(value, message) { | ||
@@ -83,3 +76,3 @@ return function (ctx) { | ||
var _ref$offset = _ref.offset, | ||
offset = _ref$offset === undefined ? 0 : _ref$offset, | ||
offset = _ref$offset === void 0 ? 0 : _ref$offset, | ||
rules = _objectWithoutProperties(_ref, ["offset"]); | ||
@@ -90,6 +83,5 @@ | ||
}, | ||
selectordinal: function selectordinal(value, _ref2) { | ||
var _ref2$offset = _ref2.offset, | ||
offset = _ref2$offset === undefined ? 0 : _ref2$offset, | ||
offset = _ref2$offset === void 0 ? 0 : _ref2$offset, | ||
rules = _objectWithoutProperties(_ref2, ["offset"]); | ||
@@ -100,15 +92,11 @@ | ||
}, | ||
select: function select(value, rules) { | ||
return rules[value] || rules.other; | ||
}, | ||
number: function number$$1(value, format) { | ||
return number(locales, style(format))(value); | ||
}, | ||
date: function date$$1(value, format) { | ||
return date(locales, style(format))(value); | ||
}, | ||
undefined: function undefined(value) { | ||
@@ -118,5 +106,4 @@ return value; | ||
}; | ||
}; | ||
}; // Params -> CTX | ||
// Params -> CTX | ||
/** | ||
@@ -126,18 +113,19 @@ * Creates a context object, which formats ICU MessageFormat arguments based on | ||
* | ||
* @param language - Language of message | ||
* @param locale - Locale of message | ||
* @param locales - Locales to be used when formatting the numbers or dates | ||
* @param values - Parameters for variable interpolation | ||
* @param languageData - Language data (e.g: plurals) | ||
* @param localeData - Locale data (e.g: plurals) | ||
* @param formats - Custom format styles | ||
* @returns {function(string, string, any)} | ||
*/ | ||
function context(_ref3) { | ||
var language = _ref3.language, | ||
var locale = _ref3.locale, | ||
locales = _ref3.locales, | ||
values = _ref3.values, | ||
formats = _ref3.formats, | ||
languageData = _ref3.languageData; | ||
localeData = _ref3.localeData; | ||
var formatters = defaultFormats(locale, locales, localeData, formats); | ||
var formatters = defaultFormats(language, locales, languageData, formats); | ||
var ctx = function ctx(name, type, format) { | ||
@@ -153,14 +141,12 @@ var value = values[name]; | ||
function interpolate(translation, language, locales, languageData) { | ||
function interpolate(translation, locale, locales, localeData) { | ||
return function (values) { | ||
var formats = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var message = translation(context({ | ||
language: language, | ||
locale: locale, | ||
locales: locales, | ||
languageData: languageData, | ||
localeData: localeData, | ||
formats: formats, | ||
values: values | ||
})); | ||
return Array.isArray(message) ? message.join("").trim() : message; | ||
@@ -170,57 +156,3 @@ }; | ||
var flatten = function flatten(arrays) { | ||
return [].concat.apply([], arrays); | ||
}; | ||
var zip = function zip(a, b) { | ||
return a.map(function (item, index) { | ||
return [item, b[index]]; | ||
}); | ||
}; | ||
var t = function t(strings) { | ||
for (var _len = arguments.length, values = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
values[_key - 1] = arguments[_key]; | ||
} | ||
return flatten(zip(strings, values)).join(""); | ||
}; | ||
var _plural = function _plural(type) { | ||
return function (i18n) { | ||
return function (_ref) { | ||
var value = _ref.value, | ||
_ref$offset = _ref.offset, | ||
offset = _ref$offset === undefined ? 0 : _ref$offset, | ||
locales = _ref.locales, | ||
format = _ref.format, | ||
other = _ref.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("#", diffAsString); | ||
}; | ||
}; | ||
}; | ||
var plural = _plural("cardinal"); | ||
var selectOrdinal = _plural("ordinal"); | ||
function select(_ref2) { | ||
var value = _ref2.value, | ||
other = _ref2.other, | ||
selectForms = _objectWithoutProperties(_ref2, ["value", "other"]); | ||
return selectForms[value] || other; | ||
} | ||
// [Tokens] -> (CTX -> String) | ||
function processTokens(tokens) { | ||
var octothorpe = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
if (!tokens.filter(function (token) { | ||
@@ -235,17 +167,7 @@ return !isString(token); | ||
if (isString(token)) { | ||
return token; | ||
// # in plural case | ||
return token; // # in plural case | ||
} else if (token.type === "octothorpe") { | ||
var name = octothorpe.name, | ||
_octothorpe$offset = octothorpe.offset, | ||
_offset = _octothorpe$offset === undefined ? 0 : _octothorpe$offset; | ||
return ctx(name) - _offset; | ||
// simple argument | ||
return "#"; // simple argument | ||
} else if (token.type === "argument") { | ||
return ctx(token.arg); | ||
// argument with custom format (date, number) | ||
return ctx(token.arg); // argument with custom format (date, number) | ||
} else if (token.type === "function") { | ||
@@ -255,14 +177,9 @@ return ctx(token.arg, token.key, token.params[0]); | ||
var offset = token.offset ? parseInt(token.offset) : undefined; | ||
var offset = token.offset ? parseInt(token.offset) : undefined; // complex argument with cases | ||
// complex argument with cases | ||
var formatProps = {}; | ||
token.cases.forEach(function (item) { | ||
formatProps[item.key] = processTokens(item.tokens, { | ||
name: token.arg, | ||
offset: offset | ||
}); | ||
formatProps[item.key] = processTokens(item.tokens); | ||
}); | ||
return ctx(token.arg, token.type, _extends({ | ||
return ctx(token.arg, token.type, _objectSpread({ | ||
offset: offset | ||
@@ -272,5 +189,5 @@ }, formatProps)); | ||
}; | ||
} | ||
} // Message -> (Params -> String) | ||
// Message -> (Params -> String) | ||
function compile(message) { | ||
@@ -280,3 +197,3 @@ try { | ||
} catch (e) { | ||
console.error("Message cannot be parsed due to syntax erorrs: " + message); | ||
console.error("Message cannot be parsed due to syntax erorrs: ".concat(message)); | ||
return message; | ||
@@ -286,3 +203,3 @@ } | ||
var loadLanguageData = (function (locale) { | ||
var loadLocaleData = (function (locale) { | ||
if (!locale) { | ||
@@ -296,3 +213,5 @@ return; | ||
return { plurals: plurals[language] }; | ||
return { | ||
plurals: plurals[language] | ||
}; | ||
}); | ||
@@ -304,197 +223,172 @@ | ||
compile: compile, | ||
loadLanguageData: loadLanguageData | ||
loadLocaleData: loadLocaleData | ||
}); | ||
function getLanguageData(catalog) { | ||
return (catalog || {}).languageData || {}; | ||
function I18n() { | ||
// Messages and localeData are merged on load, | ||
// so we must initialize it manually | ||
this._catalogs = {}; | ||
this._didActivate = []; | ||
this._willActivate = []; | ||
} | ||
function getMessages(catalog) { | ||
return (catalog || {}).messages || {}; | ||
} | ||
I18n.prototype = { | ||
get availableLocales() { | ||
return Object.keys(this._catalogs); | ||
}, | ||
var I18n = function () { | ||
function I18n() { | ||
_classCallCheck(this, I18n); | ||
get locale() { | ||
return this._locale; | ||
}, | ||
// Messages and languageData are merged on load, | ||
// so we must initialize it manually | ||
this._activeMessages = {}; | ||
this._catalogs = {}; | ||
get locales() { | ||
return this._locales; | ||
}, | ||
get catalog() { | ||
return this._catalogs[this.locale]; | ||
}, | ||
get messages() { | ||
return this.catalog && this.catalog.messages ? this.catalog.messages : {}; | ||
}, | ||
get localeData() { | ||
{ | ||
this.t = t; | ||
this.select = select; | ||
this.plural = plural(this); | ||
this.selectOrdinal = selectOrdinal(this); | ||
if (!this.catalog) { | ||
this._catalogs[this.locale] = {}; | ||
} | ||
if (isEmpty(this.catalog.localeData)) { | ||
this.catalog.localeData = this._dev.loadLocaleData(this._locale); | ||
} | ||
} | ||
} | ||
// Messages/language data in active language. | ||
// This is optimization, so we don't perform object lookup | ||
// _catalogs[language] for each translation. | ||
return this.catalog.localeData; | ||
}, | ||
loadAll: function loadAll(catalogs) { | ||
var _this = this; | ||
// Message catalogs | ||
Object.keys(catalogs).forEach(function (locale) { | ||
return _this.load(locale, catalogs[locale]); | ||
}); | ||
}, | ||
load: function load(locale, catalog) { | ||
var _this2 = this; | ||
if (!catalog) { | ||
return Promise.all(this._willActivate.map(function (load) { | ||
return load(locale).then(function (catalog) { | ||
return _this2.load(locale, catalog); | ||
}); | ||
})); | ||
} | ||
_createClass(I18n, [{ | ||
key: "_cacheActiveLanguage", | ||
value: function _cacheActiveLanguage() { | ||
var activeCatalog = this._catalogs[this.language]; | ||
if (this._catalogs[locale] === undefined) { | ||
this._catalogs[locale] = { | ||
messages: {}, | ||
localeData: {} | ||
}; | ||
} | ||
var languageData = getLanguageData(activeCatalog); | ||
var prev = this._catalogs[locale]; | ||
Object.assign(prev.messages, catalog.messages); | ||
Object.assign(prev.localeData, catalog.localeData); | ||
return Promise.resolve(); | ||
}, | ||
activate: function activate(locale, locales) { | ||
var _this3 = this; | ||
if (!this._catalogs[locale]) { | ||
if (this._willActivate.length) { | ||
return this.load(locale).then(function () { | ||
return _this3.activate(locale, locales); | ||
}); | ||
} | ||
{ | ||
// Allow overriding data in development, useful for testing | ||
if (isEmpty(languageData) && this._dev && isFunction(this._dev.loadLanguageData)) { | ||
languageData = this._dev.loadLanguageData(this.language); | ||
} | ||
console.warn("Message catalog for locale \"".concat(locale, "\" not loaded.")); | ||
} | ||
this._activeMessages = getMessages(activeCatalog); | ||
this._activeLanguageData = languageData; | ||
} | ||
}, { | ||
key: "load", | ||
value: function load(catalogs) { | ||
var _this = this; | ||
if ((typeof catalogs === "undefined" ? "undefined" : _typeof(catalogs)) !== "object") return; | ||
this._locale = locale; | ||
this._locales = locales; | ||
// deeply merge Catalogs | ||
_Object$keys(_extends({}, this._catalogs, catalogs)).forEach(function (language) { | ||
var compiledMessages = getMessages(catalogs[language]); | ||
this._didActivate.forEach(function (s) { | ||
return s(); | ||
}); | ||
{ | ||
if (_this._dev && isFunction(_this._dev.compile)) { | ||
compiledMessages = _Object$keys(compiledMessages).reduce(function (dict, id) { | ||
var msg = compiledMessages[id]; | ||
dict[id] = isString(msg) ? _this._dev.compile(msg) : msg; | ||
return dict; | ||
}, {}); | ||
} | ||
} | ||
return Promise.resolve(); | ||
}, | ||
use: function use(locale, locales) { | ||
var i18n = setupI18n(); | ||
i18n._catalogs = this._catalogs; | ||
i18n.activate(locale, locales); | ||
return i18n; | ||
}, | ||
willActivate: function willActivate(callback) { | ||
var _this4 = this; | ||
_this._catalogs[language] = { | ||
messages: _extends({}, getMessages(_this._catalogs[language]), compiledMessages), | ||
languageData: _extends({}, getLanguageData(_this._catalogs[language]), getLanguageData(catalogs[language])) | ||
}; | ||
this._willActivate.push(callback); | ||
return function () { | ||
return _this4._willActivate.filter(function (cb) { | ||
return cb !== callback; | ||
}); | ||
}; | ||
}, | ||
didActivate: function didActivate(callback) { | ||
var _this5 = this; | ||
this._cacheActiveLanguage(); | ||
} | ||
}, { | ||
key: "activate", | ||
value: function activate(language, locales) { | ||
if (!language) return; | ||
this._didActivate.push(callback); | ||
{ | ||
if (this.availableLanguages.indexOf(language) === -1) { | ||
console.warn("Message catalog for locale \"" + language + "\" not loaded."); | ||
} | ||
} | ||
this._language = language; | ||
this._locales = locales; | ||
this._cacheActiveLanguage(); | ||
} | ||
}, { | ||
key: "use", | ||
value: function use(language, locales) { | ||
return setupI18n({ | ||
language: language, | ||
locales: locales, | ||
catalogs: this._catalogs, | ||
development: this._dev | ||
return function () { | ||
return _this5._didActivate.filter(function (cb) { | ||
return cb !== callback; | ||
}); | ||
} | ||
}; | ||
}, | ||
// default translate method | ||
_: function _(id) { | ||
var values = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
// default translate method | ||
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, | ||
defaults = _ref.defaults, | ||
_ref$formats = _ref.formats, | ||
formats = _ref$formats === void 0 ? {} : _ref$formats; | ||
}, { | ||
key: "_", | ||
value: function _(id) { | ||
var values = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
// Expand message descriptor | ||
if (id && _typeof(id) === "object") { | ||
values = id.values; | ||
defaults = id.defaults; | ||
formats = id.formats; | ||
id = id.id; | ||
} | ||
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, | ||
defaults = _ref.defaults, | ||
_ref$formats = _ref.formats, | ||
formats = _ref$formats === undefined ? {} : _ref$formats; | ||
var translation = this.messages[id] || defaults || id; // replace missing messages with custom message for debugging | ||
// Expand message descriptor | ||
if (id && (typeof id === "undefined" ? "undefined" : _typeof(id)) === "object") { | ||
values = id.values; | ||
defaults = id.defaults; | ||
formats = id.formats; | ||
id = id.id; | ||
} | ||
var missing = this._missing; | ||
var translation = this.messages[id] || defaults || id; | ||
// replace missing messages with custom message for debugging | ||
var missing = this._missing; | ||
if (missing && !this.messages[id]) { | ||
translation = isFunction(missing) ? missing(this.language, id) : missing; | ||
} | ||
{ | ||
if (isString(translation) && this._dev && isFunction(this._dev.compile)) { | ||
translation = this._dev.compile(translation); | ||
} | ||
} | ||
if (!isFunction(translation)) return translation; | ||
return interpolate(translation, this.language, this.locales, this.languageData)(values, formats); | ||
if (missing && !this.messages[id]) { | ||
return isFunction(missing) ? missing(this.locale, id) : missing; | ||
} | ||
}, { | ||
key: "pluralForm", | ||
value: function pluralForm(n) { | ||
var pluralType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "cardinal"; | ||
if (!this.languageData.plurals) return "other"; | ||
return this.languageData.plurals(n, pluralType === "ordinal"); | ||
{ | ||
translation = isString(translation) ? this._dev.compile(translation) : translation; | ||
} | ||
}, { | ||
key: "date", | ||
value: function date$$1(value, format) { | ||
return date(this.locales || this.language, format)(value); | ||
} | ||
}, { | ||
key: "number", | ||
value: function number$$1(value, format) { | ||
return number(this.locales || this.language, format)(value); | ||
} | ||
}, { | ||
key: "availableLanguages", | ||
get: function get() { | ||
return _Object$keys(this._catalogs); | ||
} | ||
}, { | ||
key: "language", | ||
get: function get() { | ||
return this._language; | ||
} | ||
}, { | ||
key: "locales", | ||
get: function get() { | ||
return this._locales; | ||
} | ||
}, { | ||
key: "messages", | ||
get: function get() { | ||
return this._activeMessages; | ||
} | ||
}, { | ||
key: "languageData", | ||
get: function get() { | ||
return this._activeLanguageData; | ||
} | ||
}]); | ||
return I18n; | ||
}(); | ||
if (!isFunction(translation)) return translation; | ||
return interpolate(translation, this.locale, this.locales, this.localeData)(values, formats); | ||
}, | ||
date: function date$$1(value, format) { | ||
return date(this.locales || this.locale, format)(value); | ||
}, | ||
number: function number$$1(value, format) { | ||
return number(this.locales || this.locale, format)(value); | ||
} | ||
}; | ||
function setupI18n() { | ||
var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var i18n = new I18n(); | ||
@@ -506,19 +400,10 @@ | ||
if (params.catalogs) i18n.load(params.catalogs); | ||
if (params.language) i18n.activate(params.language, params.locales); | ||
if (params.catalogs) i18n.loadAll(params.catalogs); | ||
if (params.locale) i18n.activate(params.locale, params.locales); | ||
if (params.missing) i18n._missing = params.missing; | ||
return i18n; | ||
} | ||
var i18n = setupI18n(); | ||
var i18nMark = function i18nMark(id) { | ||
return id; | ||
}; | ||
exports.i18nMark = i18nMark; | ||
exports.i18n = i18n; | ||
exports.setupI18n = setupI18n; | ||
exports.date = date; | ||
exports.number = number; |
@@ -1,15 +0,10 @@ | ||
'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");Object.defineProperty(exports,"__esModule",{value:!0}); | ||
function h(a){return a&&"object"===typeof a&&"default"in a?a["default"]:a}var k=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){return"function"===typeof a} | ||
function u(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 v(a){var b=new Intl.NumberFormat(a,1<arguments.length&&void 0!==arguments[1]?arguments[1]:{});return function(a){return b.format(a)}} | ||
function w(a,b){function e(a,e){return function(c){c=t(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 l=f.plurals;return{plural:function(a,b){var c=b.offset;c=void 0===c?0:c;b=k(b,["offset"]);b=b[a]||b[l(a- | ||
c)];return e(a-c,b)},selectordinal:function(a,b){var c=b.offset;c=void 0===c?0:c;b=k(b,["offset"]);b=b[a]||b[l(a-c,!0)];return e(a-c,b)},select:function(a,b){return b[a]||b.other},number:function(a,e){return v(b,c(e))(a)},date:function(a,e){return u(b,c(e))(a)},undefined:function(a){return a}}}function x(a){var b=a.values,e=w(a.language,a.locales,a.languageData,a.formats);return function y(a,g,l){a=e[g](b[a],l);a=t(a)?a(y):a;return Array.isArray(a)?a.join(""):a}} | ||
function z(a,b,e,c){return function(f){var g=a(x({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 B=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 A({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;a&&"object"===("undefined"===typeof a?"undefined":p(a))&&(b=a.values,f=a.defaults,c=a.formats,a=a.id);f=this.messages[a]||f||a;var g=this._missing;g&&!this.messages[a]&&(f=t(g)?g(this.language,a):g);return t(f)?z(f,this.language,this.locales,this.languageData)(b,c):f}},{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:"date",value:function(a,e){return u(this.locales|| | ||
this.language,e)(a)}},{key:"number",value:function(a,e){return v(this.locales||this.language,e)(a)}},{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 A(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},b=new B;a.catalogs&&b.load(a.catalogs);a.language&&b.activate(a.language,a.locales);a.missing&&(b._missing=a.missing);return b}var C=A();exports.i18nMark=function(a){return a};exports.i18n=C;exports.setupI18n=A;exports.date=u;exports.number=v; | ||
'use strict';Object.defineProperty(exports,"__esModule",{value:!0});function h(a){return a&&"object"===typeof a&&"default"in a?a["default"]:a}var l=h(require("@babel/runtime/helpers/objectWithoutProperties"));require("@babel/runtime/helpers/objectSpread");require("@babel/runtime/helpers/slicedToArray");var m=h(require("@babel/runtime/helpers/typeof"));function n(a){return"function"===typeof a} | ||
function p(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 q(a){var b=new Intl.NumberFormat(a,1<arguments.length&&void 0!==arguments[1]?arguments[1]:{});return function(a){return b.format(a)}} | ||
function r(a,b){function c(a,c){return function(d){d=n(c)?c(d):c;d=Array.isArray(d)?d:[d];var v=(new Intl.NumberFormat(b)).format(a);return d.map(function(a){return"string"===typeof a?a.replace("#",v):a})}}function e(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 d=b.offset;d=void 0===d?0:d;b=l(b,["offset"]);b=b[a]||b[k(a- | ||
d)];return c(a-d,b)},selectordinal:function(a,b){var d=b.offset;d=void 0===d?0:d;b=l(b,["offset"]);b=b[a]||b[k(a-d,!0)];return c(a-d,b)},select:function(a,b){return b[a]||b.other},number:function(a,c){return q(b,e(c))(a)},date:function(a,c){return p(b,e(c))(a)},undefined:function(a){return a}}}function t(a){var b=a.values,c=r(a.locale,a.locales,a.localeData,a.formats);return function d(a,g,k){a=c[g](b[a],k);a=n(a)?a(d):a;return Array.isArray(a)?a.join(""):a}} | ||
function u(a,b,c,e){return function(f){var g=a(t({locale:b,locales:c,localeData:e,formats:1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},values:f}));return Array.isArray(g)?g.join("").trim():g}}function w(){this._catalogs={};this._didActivate=[];this._willActivate=[]} | ||
w.prototype={get availableLocales(){return Object.keys(this._catalogs)},get locale(){return this._locale},get locales(){return this._locales},get catalog(){return this._catalogs[this.locale]},get messages(){return this.catalog&&this.catalog.messages?this.catalog.messages:{}},get localeData(){return this.catalog.localeData},loadAll:function(a){var b=this;Object.keys(a).forEach(function(c){return b.load(c,a[c])})},load:function(a,b){var c=this;if(!b)return Promise.all(this._willActivate.map(function(b){return b(a).then(function(b){return c.load(a, | ||
b)})}));void 0===this._catalogs[a]&&(this._catalogs[a]={messages:{},localeData:{}});var e=this._catalogs[a];Object.assign(e.messages,b.messages);Object.assign(e.localeData,b.localeData);return Promise.resolve()},activate:function(a,b){var c=this;if(!this._catalogs[a]&&this._willActivate.length)return this.load(a).then(function(){return c.activate(a,b)});this._locale=a;this._locales=b;this._didActivate.forEach(function(a){return a()});return Promise.resolve()},use:function(a,b){var c=x();c._catalogs= | ||
this._catalogs;c.activate(a,b);return c},willActivate:function(a){var b=this;this._willActivate.push(a);return function(){return b._willActivate.filter(function(b){return b!==a})}},didActivate:function(a){var b=this;this._didActivate.push(a);return function(){return b._didActivate.filter(function(b){return b!==a})}},_:function(a){var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},c=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},e=c.defaults;c=c.formats;c=void 0===c?{}:c;a&& | ||
"object"===m(a)&&(b=a.values,e=a.defaults,c=a.formats,a=a.id);e=this.messages[a]||e||a;var f=this._missing;return f&&!this.messages[a]?n(f)?f(this.locale,a):f:n(e)?u(e,this.locale,this.locales,this.localeData)(b,c):e},date:function(a,b){return p(this.locales||this.locale,b)(a)},number:function(a,b){return q(this.locales||this.locale,b)(a)}}; | ||
function x(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},b=new w;a.catalogs&&b.loadAll(a.catalogs);a.locale&&b.activate(a.locale,a.locales);a.missing&&(b._missing=a.missing);return b}exports.setupI18n=x;exports.date=p;exports.number=q; |
{ | ||
"name": "@lingui/core", | ||
"version": "2.7.0", | ||
"version": "3.0.0-1", | ||
"description": "I18n tools for javascript", | ||
@@ -22,3 +22,3 @@ "keywords": [ | ||
"engines": { | ||
"node": ">=4.0" | ||
"node": ">=8.0.0" | ||
}, | ||
@@ -34,3 +34,3 @@ "files": [ | ||
"dependencies": { | ||
"babel-runtime": "^6.26.0", | ||
"@babel/runtime": "^7.0.0", | ||
"make-plural": "^4.1.1", | ||
@@ -37,0 +37,0 @@ "messageformat-parser": "^2.0.0" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
27333
11
351
3
1
+ Added@babel/runtime@^7.0.0
+ Added@babel/runtime@7.26.0(transitive)
+ Addedregenerator-runtime@0.14.1(transitive)
- Removedbabel-runtime@^6.26.0
- Removedbabel-runtime@6.26.0(transitive)
- Removedcore-js@2.6.12(transitive)
- Removedregenerator-runtime@0.11.1(transitive)