Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lingui/react

Package Overview
Dependencies
Maintainers
1
Versions
157
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lingui/react - npm Package Compare versions

Comparing version 2.7.0 to 3.0.0-1

forwardRef.js.flow

608

cjs/react.development.js

@@ -7,150 +7,63 @@ 'use strict';

var _Object$getPrototypeOf = _interopDefault(require('babel-runtime/core-js/object/get-prototype-of'));
var _classCallCheck = _interopDefault(require('babel-runtime/helpers/classCallCheck'));
var _createClass = _interopDefault(require('babel-runtime/helpers/createClass'));
var _possibleConstructorReturn = _interopDefault(require('babel-runtime/helpers/possibleConstructorReturn'));
var _inherits = _interopDefault(require('babel-runtime/helpers/inherits'));
var _classCallCheck = _interopDefault(require('@babel/runtime/helpers/classCallCheck'));
var _createClass = _interopDefault(require('@babel/runtime/helpers/createClass'));
var _possibleConstructorReturn = _interopDefault(require('@babel/runtime/helpers/possibleConstructorReturn'));
var _getPrototypeOf = _interopDefault(require('@babel/runtime/helpers/getPrototypeOf'));
var _inherits = _interopDefault(require('@babel/runtime/helpers/inherits'));
var _assertThisInitialized = _interopDefault(require('@babel/runtime/helpers/assertThisInitialized'));
var _defineProperty = _interopDefault(require('@babel/runtime/helpers/defineProperty'));
var React = require('react');
var PropTypes = _interopDefault(require('prop-types'));
var hashSum = _interopDefault(require('hash-sum'));
var _slicedToArray = _interopDefault(require('@babel/runtime/helpers/slicedToArray'));
var _toConsumableArray = _interopDefault(require('@babel/runtime/helpers/toConsumableArray'));
var _objectSpread = _interopDefault(require('@babel/runtime/helpers/objectSpread'));
var _extends = _interopDefault(require('@babel/runtime/helpers/extends'));
var hoistStatics = _interopDefault(require('hoist-non-react-statics'));
var core = require('@lingui/core');
var _extends = _interopDefault(require('babel-runtime/helpers/extends'));
var hoistStatics = _interopDefault(require('hoist-non-react-statics'));
var _getIterator = _interopDefault(require('babel-runtime/core-js/get-iterator'));
var _slicedToArray = _interopDefault(require('babel-runtime/helpers/slicedToArray'));
var _Object$keys = _interopDefault(require('babel-runtime/core-js/object/keys'));
var _toConsumableArray = _interopDefault(require('babel-runtime/helpers/toConsumableArray'));
var _objectWithoutProperties = _interopDefault(require('babel-runtime/helpers/objectWithoutProperties'));
/*
* I18nPublisher - Connects to lingui-i18n/I18n class
* Allows listeners to subscribe for changes
*/
function LinguiPublisher(i18n) {
var subscribers = [];
return {
i18n: i18n,
i18nHash: null,
getSubscribers: function getSubscribers() {
return subscribers;
},
subscribe: function subscribe(callback) {
subscribers.push(callback);
},
unsubscribe: function unsubscribe(callback) {
subscribers = subscribers.filter(function (cb) {
return cb !== callback;
});
},
update: function update() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
catalogs = _ref.catalogs,
language = _ref.language,
locales = _ref.locales;
if (!catalogs && !language && !locales) return;
if (catalogs) i18n.load(catalogs);
if (language) i18n.activate(language, locales);
this.i18nHash = hashSum([i18n.language, i18n.messages]);
subscribers.forEach(function (f) {
return f();
});
}
};
}
var I18nProvider = function (_React$Component) {
var _React$createContext = React.createContext({
i18n: {},
defaultRender: null
}),
I18nContextProvider = _React$createContext.Provider,
I18n = _React$createContext.Consumer;
var I18nProvider =
/*#__PURE__*/
function (_React$Component) {
_inherits(I18nProvider, _React$Component);
function I18nProvider(props) {
var _this;
_classCallCheck(this, I18nProvider);
var _this = _possibleConstructorReturn(this, (I18nProvider.__proto__ || _Object$getPrototypeOf(I18nProvider)).call(this, props));
_this = _possibleConstructorReturn(this, _getPrototypeOf(I18nProvider).call(this, props));
var language = props.language,
locales = props.locales,
catalogs = props.catalogs,
missing = props.missing;
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "unsubscribe", void 0);
var i18n = props.i18n || core.setupI18n({
language: language,
locales: locales,
catalogs: catalogs
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "setContext", function () {
var set = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
var state = {
context: {
i18n: _this.props.i18n,
defaultRender: _this.props.defaultRender
}
};
if (set) _this.setState(state);
return state;
});
_this.linguiPublisher = new LinguiPublisher(i18n);
_this.linguiPublisher.i18n._missing = _this.props.missing;
_this.state = _this.setContext(false);
return _this;
}
/**
* I18n object from `@lingui/core` is the single source of truth for all i18n related
* data (active locale, catalogs). When new messages are loaded or locale is changed
* we need to trigger re-rendering of I18nContextConsumers.
*/
_createClass(I18nProvider, [{
key: "componentDidUpdate",
value: function componentDidUpdate(prevProps) {
var _props = this.props,
language = _props.language,
locales = _props.locales,
catalogs = _props.catalogs;
if (language !== prevProps.language || locales !== prevProps.locales || catalogs !== prevProps.catalogs) {
this.linguiPublisher.update({ language: language, catalogs: catalogs, locales: locales });
}
this.linguiPublisher.i18n._missing = this.props.missing;
}
}, {
key: "getChildContext",
value: function getChildContext() {
return {
linguiPublisher: this.linguiPublisher,
linguiDefaultRender: this.props.defaultRender
};
}
}, {
key: "render",
value: function render() {
return this.props.children;
}
}]);
return I18nProvider;
}(React.Component);
I18nProvider.defaultProps = {
defaultRender: null
};
I18nProvider.childContextTypes = {
linguiPublisher: PropTypes.object.isRequired,
linguiDefaultRender: PropTypes.any
};
var I18n = function (_React$Component) {
_inherits(I18n, _React$Component);
function I18n() {
var _ref;
var _temp, _this, _ret;
_classCallCheck(this, I18n);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = I18n.__proto__ || _Object$getPrototypeOf(I18n)).call.apply(_ref, [this].concat(args))), _this), _this.checkUpdate = /* istanbul ignore next */function () {
_this.forceUpdate();
}, _temp), _possibleConstructorReturn(_this, _ret);
}
_createClass(I18n, [{
key: "componentDidMount",
value: function componentDidMount() {
var _getI18n = this.getI18n(),
subscribe = _getI18n.subscribe;
if (this.props.update && subscribe) subscribe(this.checkUpdate);
this.unsubscribe = this.props.i18n.didActivate(this.setContext);
}

@@ -160,127 +73,32 @@ }, {

value: function componentWillUnmount() {
var _getI18n2 = this.getI18n(),
unsubscribe = _getI18n2.unsubscribe;
if (this.props.update && unsubscribe) unsubscribe(this.checkUpdate);
this.unsubscribe();
}
/**
* We can't pass `i18n` object directly through context, because even when locale
* or messages are changed, i18n object is still the same. Context provider compares
* reference identity and suggested workaround is create a wrapper object every time
* we need to trigger re-render. See https://reactjs.org/docs/context.html#caveats.
*
* Due to this effect we also pass `defaultRender` in the same context, instead
* of creating a separate Provider/Consumer pair.
*
* When `set` is false, `setState` isn't called and new state is returned. This is
* used in constructor when we can't call `setState`
*/
// Test checks that subscribe/unsubscribe is called with function.
}, {
key: "getI18n",
value: function getI18n() {
return this.context.linguiPublisher || {};
}
}, {
key: "render",
value: function render() {
var _props = this.props,
children = _props.children,
withHash = _props.withHash;
var _getI18n3 = this.getI18n(),
i18n = _getI18n3.i18n,
i18nHash = _getI18n3.i18nHash;
var props = _extends({
i18n: i18n
}, withHash ? { i18nHash: i18nHash } : {});
if (typeof children === "function") {
return children(props);
}
{
console.warn("I18n accepts only function as a children. " + "Other usecases are deprecated and will be removed in v3.0");
}
// Deprecate v3.0
return React.isValidElement(children) ? React.cloneElement(children, props) : React.createElement(children, props);
var context = this.state.context;
return React.createElement(I18nContextProvider, {
value: context
}, context.i18n.locale && this.props.children);
}
}]);
return I18n;
return I18nProvider;
}(React.Component);
I18n.defaultProps = {
update: true,
withHash: true
};
I18n.contextTypes = {
linguiPublisher: PropTypes.object
};
var withI18n = function withI18n() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
return function (WrappedComponent) {
{
if (typeof options === "function" || React.isValidElement(options)) {
console.warn("withI18n([options]) takes options as a first argument, " + "but received React component itself. Without options, the Component " + "should be wrapped as withI18n()(Component), not withI18n(Component).");
}
}
var _options$update = options.update,
update = _options$update === undefined ? true : _options$update,
_options$withHash = options.withHash,
withHash = _options$withHash === undefined ? true : _options$withHash,
_options$withRef = options.withRef,
withRef = _options$withRef === undefined ? false : _options$withRef;
var WithI18n = function (_React$Component) {
_inherits(WithI18n, _React$Component);
function WithI18n() {
var _ref;
var _temp, _this, _ret;
_classCallCheck(this, WithI18n);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = WithI18n.__proto__ || _Object$getPrototypeOf(WithI18n)).call.apply(_ref, [this].concat(args))), _this), _this.wrappedInstance = null, _this.setWrappedInstance = function (ref) {
if (withRef) _this.wrappedInstance = ref;
}, _this.getWrappedInstance = function () {
if (!withRef) {
throw new Error("To access the wrapped instance, you need to specify { withRef: true }" + " in the options argument of the withI18n() call.");
}
return _this.wrappedInstance;
}, _temp), _possibleConstructorReturn(_this, _ret);
}
_createClass(WithI18n, [{
key: "render",
value: function render() {
var props = _extends({}, this.props, withRef ? { ref: this.setWrappedInstance } : {});
return React.createElement(
I18n,
{ update: update, withHash: withHash },
function (_ref2) {
var i18n = _ref2.i18n,
i18nHash = _ref2.i18nHash;
return React.createElement(WrappedComponent, _extends({}, props, { i18n: i18n, i18nHash: i18nHash }));
}
);
}
}]);
return WithI18n;
}(React.Component);
WithI18n.contextTypes = {
linguiPublisher: PropTypes.object
};
return hoistStatics(WithI18n, WrappedComponent);
};
};
// match <0>paired</0> and <1/> unpaired tags
var tagRe = /<(\d+)>(.*)<\/\1>|<(\d+)\/>/;
var nlRe = /(?:\r\n|\r|\n)/g;
/**

@@ -293,18 +111,13 @@ * `formatElements` - parse string and return tree of react elements

*/
function formatElements(value) {
var elements = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
// TODO: warn if there're any unprocessed elements
// TODO: warn if element at `index` doesn't exist
var parts = value.replace(nlRe, "").split(tagRe); // no inline elements, return
var parts = value.replace(nlRe, "").split(tagRe);
// no inline elements, return
if (parts.length === 1) return value;
var tree = [];
var before = parts.shift();
if (before) tree.push(before);
var _iteratorNormalCompletion = true;

@@ -315,18 +128,14 @@ var _didIteratorError = false;

try {
for (var _iterator = _getIterator(getElements(parts)), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _ref = _step.value;
for (var _iterator = getElements(parts)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _step$value = _slicedToArray(_step.value, 3),
index = _step$value[0],
children = _step$value[1],
after = _step$value[2];
var _ref2 = _slicedToArray(_ref, 3);
var index = _ref2[0];
var children = _ref2[1];
var after = _ref2[2];
var element = elements[index];
tree.push(React.cloneElement(element, { key: index },
// format children for pair tags
tree.push(React.cloneElement(element, {
key: index
}, // format children for pair tags
// unpaired tags might have children if it's a component passed as a variable
children ? formatElements(children, elements) : element.props.children));
if (after) tree.push(after);

@@ -339,3 +148,3 @@ }

try {
if (!_iteratorNormalCompletion && _iterator.return) {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();

@@ -352,3 +161,2 @@ }

}
/*

@@ -368,2 +176,4 @@ * `getElements` - return array of element indexes and element childrens

*/
function getElements(parts) {

@@ -382,71 +192,25 @@ if (!parts.length) return [];

var Render = function (_React$Component) {
_inherits(Render, _React$Component);
var Trans$$1 =
/*#__PURE__*/
function (_React$Component) {
_inherits(Trans$$1, _React$Component);
function Render() {
_classCallCheck(this, Render);
function Trans$$1() {
_classCallCheck(this, Trans$$1);
return _possibleConstructorReturn(this, (Render.__proto__ || _Object$getPrototypeOf(Render)).apply(this, arguments));
return _possibleConstructorReturn(this, _getPrototypeOf(Trans$$1).apply(this, arguments));
}
_createClass(Render, [{
key: "render",
value: function render() {
var _props = this.props,
className = _props.className,
value = _props.value;
var render = this.props.render || this.context.linguiDefaultRender;
if (render === null || render === undefined) {
return value;
} else if (typeof render === "string") {
// Built-in element: h1, p
return React.createElement(render, { className: className }, value);
}
return React.isValidElement(render) ? // Custom element: <p className="lear' />
React.cloneElement(render, {}, value) : // Custom component: ({ translation }) => <a title={translation}>x</a>
React.createElement(render, { translation: value });
}
}]);
return Render;
}(React.Component);
Render.contextTypes = {
linguiDefaultRender: PropTypes.any
};
var Trans = function (_React$Component) {
_inherits(Trans, _React$Component);
function Trans() {
_classCallCheck(this, Trans);
return _possibleConstructorReturn(this, (Trans.__proto__ || _Object$getPrototypeOf(Trans)).apply(this, arguments));
}
_createClass(Trans, [{
key: "componentDidMount",
value: function componentDidMount() {
{
if (!this.getTranslation() && this.props.children) {
console.warn("@lingui/babel-preset-react is probably missing in babel config, " + "but you are using <Trans> component in a way which requires it. " + "Either don't use children in <Trans> component or configure babel " + "to load @lingui/babel-preset-react preset. See tutorial for more info: " + "https://l.lingui.io/tutorial-i18n-react");
}
}
}
}, {
_createClass(Trans$$1, [{
key: "getTranslation",
value: function getTranslation() {
var _props = this.props,
_props$id = _props.id,
id = _props$id === undefined ? "" : _props$id,
defaults = _props.defaults,
i18n = _props.i18n,
formats = _props.formats;
value: function getTranslation(i18n) {
var _this$props = this.props,
_this$props$id = _this$props.id,
id = _this$props$id === void 0 ? "" : _this$props$id,
defaults = _this$props.defaults,
formats = _this$props.formats;
var values = _objectSpread({}, this.props.values);
var values = _extends({}, this.props.values);
var components = this.props.components ? [].concat(_toConsumableArray(this.props.components)) : [];
var components = this.props.components ? _toConsumableArray(this.props.components) : [];

@@ -463,15 +227,17 @@ if (values) {

*/
_Object$keys(values).forEach(function (key) {
Object.keys(values).forEach(function (key) {
var value = values[key];
if (!React.isValidElement(value)) return;
var index = components.push(value) - 1; // push returns new length of array
var index = components.push(value) - 1; // push returns new length of array
values[key] = "<" + index + "/>";
values[key] = "<".concat(index, "/>");
});
}
var translation = i18n && typeof i18n._ === "function" ? i18n._(id, values, { defaults: defaults, formats: formats }) : id; // i18n provider isn't loaded at all
var translation = i18n && typeof i18n._ === "function" ? i18n._(id, values, {
defaults: defaults,
formats: formats
}) : id; // i18n provider isn't loaded at all
if (!translation) return null;
return formatElements(translation, components);

@@ -482,40 +248,32 @@ }

value: function render() {
return React.createElement(Render, {
render: this.props.render,
className: this.props.className,
value: this.getTranslation()
});
}
}]);
var _this = this;
return Trans;
}(React.Component);
return React.createElement(I18n, null, function (_ref) {
var i18n = _ref.i18n,
defaultRender = _ref.defaultRender;
var Trans$1 = withI18n()(Trans);
var translation = _this.getTranslation(i18n);
var Select = withI18n()(function (_React$Component) {
_inherits(Select, _React$Component);
var _this$props2 = _this.props,
_this$props2$render = _this$props2.render,
render = _this$props2$render === void 0 ? defaultRender : _this$props2$render,
id = _this$props2.id,
defaults = _this$props2.defaults;
function Select() {
_classCallCheck(this, Select);
if (render === null || render === undefined) {
return translation;
} else if (typeof render === "string") {
// Built-in element: h1, p
return React.createElement(render, {}, translation);
} else if (typeof render === "function") {
// Function: (props) => <a title={props.translation}>x</a>
return render({
id: id,
translation: translation,
defaults: defaults
});
} // Element: <p className="lear' />
return _possibleConstructorReturn(this, (Select.__proto__ || _Object$getPrototypeOf(Select)).apply(this, arguments));
}
_createClass(Select, [{
key: "render",
value: function render() {
// lingui-transform-js transforms also this file in react-native env.
// i18n must be aliased to _i18n to hide i18n.select call from plugin,
// otherwise it throws "undefined is not iterable" obscure error.
var _props = this.props,
className = _props.className,
render = _props.render,
_i18n = _props.i18n,
selectProps = _objectWithoutProperties(_props, ["className", "render", "i18n"]);
return React.createElement(Render, {
className: className,
render: render,
value: _i18n.select(selectProps)
return React.cloneElement(render, {}, translation);
});

@@ -525,100 +283,54 @@ }

return Select;
}(React.Component));
return Trans$$1;
}(React.Component);
var PluralFactory = function PluralFactory() {
var _class2, _temp2;
// Flow is missing definition for forwardRef.
var ordinal = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
function makeWithI18n() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
_ref$withHash = _ref.withHash,
withHash = _ref$withHash === void 0 ? false : _ref$withHash;
var displayName = !ordinal ? "Plural" : "SelectOrdinal";
var pluralType = !ordinal ? "plural" : "selectOrdinal";
return function withI18n$$1(WrappedComponent) {
var WithI18n = React.forwardRef(function (props, ref) {
return React.createElement(I18n, null, function (_ref2) {
var i18n = _ref2.i18n;
return React.createElement(WrappedComponent, _extends({}, props, {
ref: ref,
i18n: i18n,
i18nHash: withHash ? i18n.locale : undefined
}));
});
});
return hoistStatics(WithI18n, WrappedComponent);
};
}
return _temp2 = _class2 = function (_React$Component2) {
_inherits(_class2, _React$Component2);
var withI18n$$1 = makeWithI18n();
var withI18nForPure$$1 = makeWithI18n({
withHash: true
});
function _class2() {
var _ref;
var _temp, _this2, _ret;
_classCallCheck(this, _class2);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this2 = _possibleConstructorReturn(this, (_ref = _class2.__proto__ || _Object$getPrototypeOf(_class2)).call.apply(_ref, [this].concat(args))), _this2), _this2.displayName = displayName, _temp), _possibleConstructorReturn(_this2, _ret);
}
_createClass(_class2, [{
key: "render",
value: function render() {
var _props2 = this.props,
className = _props2.className,
render = _props2.render,
i18n = _props2.i18n,
value = _props2.value,
offset = _props2.offset,
props = _objectWithoutProperties(_props2, ["className", "render", "i18n", "value", "offset"]);
// i18n.selectOrdinal/plural uses numbers for exact matches (1, 2),
// while SelectOrdinal/Plural has to use strings (_1, _2).
var pluralProps = _Object$keys(props).reduce(function (acc, prop) {
var key = prop.replace("_", "");
acc[key] = props[prop];
return acc;
}, {
value: Number(value),
offset: Number(offset)
});
return React.createElement(Render, {
className: className,
render: render,
value: i18n[pluralType](pluralProps)
});
}
}]);
return _class2;
}(React.Component), _class2.defaultProps = {
offset: 0
}, _temp2;
};
var Plural = withI18n()(PluralFactory(false));
var SelectOrdinal = withI18n()(PluralFactory(true));
function createFormat(formatFunction) {
return function (_ref) {
var value = _ref.value,
format = _ref.format,
i18n = _ref.i18n,
className = _ref.className,
render = _ref.render;
var formatter = formatFunction(i18n.locales || i18n.language, format);
return React.createElement(Render, { className: className, render: render, value: formatter(value) });
format = _ref.format;
return React.createElement(I18n, null, function (_ref2) {
var i18n = _ref2.i18n;
var formatter = formatFunction(i18n.locales || i18n.locale, format);
return formatter(value);
});
};
}
var DateFormat = withI18n()(createFormat(core.date));
var NumberFormat = withI18n()(createFormat(core.number));
var DateFormat = createFormat(core.date);
var NumberFormat = createFormat(core.number);
var i18nMark = function i18nMark(id) {
return id;
};
exports.i18nMark = i18nMark;
exports.withI18n = withI18n;
exports.setupI18n = core.setupI18n;
exports.withI18n = withI18n$$1;
exports.withI18nForPure = withI18nForPure$$1;
exports.I18nProvider = I18nProvider;
exports.I18n = I18n;
exports.Trans = Trans$1;
exports.Plural = Plural;
exports.Select = Select;
exports.SelectOrdinal = SelectOrdinal;
exports.Trans = Trans$$1;
exports.DateFormat = DateFormat;
exports.NumberFormat = NumberFormat;

@@ -1,24 +0,10 @@

'use strict';var e=e||{};e.scope={};e.ASSUME_ES5=!1;e.ASSUME_NO_NATIVE_MAP=!1;e.ASSUME_NO_NATIVE_SET=!1;e.defineProperty=e.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(a,b,c){a!=Array.prototype&&a!=Object.prototype&&(a[b]=c.value)};e.getGlobal=function(a){return"undefined"!=typeof window&&window===a?a:"undefined"!=typeof global&&null!=global?global:a};e.global=e.getGlobal(this);e.SYMBOL_PREFIX="jscomp_symbol_";
e.initSymbol=function(){e.initSymbol=function(){};e.global.Symbol||(e.global.Symbol=e.Symbol)};e.Symbol=function(){var a=0;return function(b){return e.SYMBOL_PREFIX+(b||"")+a++}}();e.initSymbolIterator=function(){e.initSymbol();var a=e.global.Symbol.iterator;a||(a=e.global.Symbol.iterator=e.global.Symbol("iterator"));"function"!=typeof Array.prototype[a]&&e.defineProperty(Array.prototype,a,{configurable:!0,writable:!0,value:function(){return e.arrayIterator(this)}});e.initSymbolIterator=function(){}};
e.arrayIterator=function(a){var b=0;return e.iteratorPrototype(function(){return b<a.length?{done:!1,value:a[b++]}:{done:!0}})};e.iteratorPrototype=function(a){e.initSymbolIterator();a={next:a};a[e.global.Symbol.iterator]=function(){return this};return a};
e.iteratorFromArray=function(a,b){e.initSymbolIterator();a instanceof String&&(a+="");var c=0,f={next:function(){if(c<a.length){var d=c++;return{value:b(d,a[d]),done:!1}}f.next=function(){return{done:!0,value:void 0}};return f.next()}};f[Symbol.iterator]=function(){return f};return f};
e.polyfill=function(a,b){if(b){var c=e.global;a=a.split(".");for(var f=0;f<a.length-1;f++){var d=a[f];d in c||(c[d]={});c=c[d]}a=a[a.length-1];f=c[a];b=b(f);b!=f&&null!=b&&e.defineProperty(c,a,{configurable:!0,writable:!0,value:b})}};e.polyfill("Array.prototype.values",function(a){return a?a:function(){return e.iteratorFromArray(this,function(a,c){return c})}},"es8","es3");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/core-js/object/get-prototype-of")),n=h(require("babel-runtime/helpers/classCallCheck")),q=h(require("babel-runtime/helpers/createClass")),r=h(require("babel-runtime/helpers/possibleConstructorReturn")),t=h(require("babel-runtime/helpers/inherits")),u=require("react"),w=h(require("prop-types")),y=h(require("hash-sum")),A=require("@lingui/core"),B=h(require("babel-runtime/helpers/extends")),C=h(require("hoist-non-react-statics")),D=h(require("babel-runtime/core-js/get-iterator")),
E=h(require("babel-runtime/helpers/slicedToArray")),G=h(require("babel-runtime/core-js/object/keys")),H=h(require("babel-runtime/helpers/toConsumableArray")),I=h(require("babel-runtime/helpers/objectWithoutProperties"));
function L(a){var b=[];return{i18n:a,i18nHash:null,getSubscribers:function(){return b},subscribe:function(c){b.push(c)},unsubscribe:function(c){b=b.filter(function(a){return a!==c})},update:function(){var c=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},f=c.catalogs,d=c.language;c=c.locales;if(f||d||c)f&&a.load(f),d&&a.activate(d,c),this.i18nHash=y([a.language,a.messages]),b.forEach(function(c){return c()})}}}
var M=function(a){function b(c){n(this,b);var a=r(this,(b.__proto__||l(b)).call(this,c)),d=c.language,g=c.locales,k=c.catalogs;c=c.i18n||A.setupI18n({language:d,locales:g,catalogs:k});a.linguiPublisher=new L(c);a.linguiPublisher.i18n._missing=a.props.missing;return a}t(b,a);q(b,[{key:"componentDidUpdate",value:function(c){var a=this.props,b=a.language,g=a.locales;a=a.catalogs;b===c.language&&g===c.locales&&a===c.catalogs||this.linguiPublisher.update({language:b,catalogs:a,locales:g});this.linguiPublisher.i18n._missing=
this.props.missing}},{key:"getChildContext",value:function(){return{linguiPublisher:this.linguiPublisher,linguiDefaultRender:this.props.defaultRender}}},{key:"render",value:function(){return this.props.children}}]);return b}(u.Component);M.defaultProps={defaultRender:null};M.childContextTypes={linguiPublisher:w.object.isRequired,linguiDefaultRender:w.any};
var N=function(a){function b(){var c,a,d,g;n(this,b);for(var k=arguments.length,m=Array(k),v=0;v<k;v++)m[v]=arguments[v];return g=(a=(d=r(this,(c=b.__proto__||l(b)).call.apply(c,[this].concat(m))),d),d.checkUpdate=function(){d.forceUpdate()},a),r(d,g)}t(b,a);q(b,[{key:"componentDidMount",value:function(){var c=this.getI18n().subscribe;this.props.update&&c&&c(this.checkUpdate)}},{key:"componentWillUnmount",value:function(){var c=this.getI18n().unsubscribe;this.props.update&&c&&c(this.checkUpdate)}},
{key:"getI18n",value:function(){return this.context.linguiPublisher||{}}},{key:"render",value:function(){var c=this.props,a=c.children;c=c.withHash;var b=this.getI18n(),g=b.i18nHash;c=B({i18n:b.i18n},c?{i18nHash:g}:{});return"function"===typeof a?a(c):u.isValidElement(a)?u.cloneElement(a,c):u.createElement(a,c)}}]);return b}(u.Component);N.defaultProps={update:!0,withHash:!0};N.contextTypes={linguiPublisher:w.object};
function O(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};return function(b){var c=a.update,f=void 0===c?!0:c;c=a.withHash;var d=void 0===c?!0:c;c=a.withRef;var g=void 0===c?!1:c;c=function(a){function c(){var a,b,d,f;n(this,c);for(var m=arguments.length,k=Array(m),x=0;x<m;x++)k[x]=arguments[x];return f=(b=(d=r(this,(a=c.__proto__||l(c)).call.apply(a,[this].concat(k))),d),d.wrappedInstance=null,d.setWrappedInstance=function(a){g&&(d.wrappedInstance=a)},d.getWrappedInstance=function(){if(!g)throw Error("To access the wrapped instance, you need to specify { withRef: true } in the options argument of the withI18n() call.");
return d.wrappedInstance},b),r(d,f)}t(c,a);q(c,[{key:"render",value:function(){var a=B({},this.props,g?{ref:this.setWrappedInstance}:{});return u.createElement(N,{update:f,withHash:d},function(c){return u.createElement(b,B({},a,{i18n:c.i18n,i18nHash:c.i18nHash}))})}}]);return c}(u.Component);c.contextTypes={linguiPublisher:w.object};return C(c,b)}}var P=/<(\d+)>(.*)<\/\1>|<(\d+)\/>/,Q=/(?:\r\n|\r|\n)/g;
function R(a){var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:[],c=a.replace(Q,"").split(P);if(1===c.length)return a;var f=[],d=c.shift();d&&f.push(d);d=!0;var g=!1,k=void 0;try{for(var m=D(S(c)),v;!(d=(v=m.next()).done);d=!0){var F=E(v.value,3),J=F[0],K=F[1],z=F[2],p=b[J];f.push(u.cloneElement(p,{key:J},K?R(K,b):p.props.children));z&&f.push(z)}}catch(x){g=!0,k=x}finally{try{!d&&m.return&&m.return()}finally{if(g)throw k;}}return f}
function S(a){if(!a.length)return[];var b=a.slice(0,4);b=E(b,4);var c=b[1],f=b[2],d=b[3];return[[parseInt(b[0]||f),c||"",d]].concat(S(a.slice(4,a.length)))}
var T=function(a){function b(){n(this,b);return r(this,(b.__proto__||l(b)).apply(this,arguments))}t(b,a);q(b,[{key:"render",value:function(){var a=this.props,b=a.className;a=a.value;var d=this.props.render||this.context.linguiDefaultRender;return null===d||void 0===d?a:"string"===typeof d?u.createElement(d,{className:b},a):u.isValidElement(d)?u.cloneElement(d,{},a):u.createElement(d,{translation:a})}}]);return b}(u.Component);T.contextTypes={linguiDefaultRender:w.any};
var U=function(a){function b(){n(this,b);return r(this,(b.__proto__||l(b)).apply(this,arguments))}t(b,a);q(b,[{key:"componentDidMount",value:function(){}},{key:"getTranslation",value:function(){var a=this.props,b=a.id;b=void 0===b?"":b;var d=a.defaults,g=a.i18n;a=a.formats;var k=B({},this.props.values),m=this.props.components?[].concat(H(this.props.components)):[];k&&G(k).forEach(function(a){var b=k[a];u.isValidElement(b)&&(b=m.push(b)-1,k[a]="\x3c"+b+"/\x3e")});return(a=g&&"function"===typeof g._?
g._(b,k,{defaults:d,formats:a}):b)?R(a,m):null}},{key:"render",value:function(){return u.createElement(T,{render:this.props.render,className:this.props.className,value:this.getTranslation()})}}]);return b}(u.Component),V=O()(U),W=O()(function(a){function b(){n(this,b);return r(this,(b.__proto__||l(b)).apply(this,arguments))}t(b,a);q(b,[{key:"render",value:function(){var a=this.props,b=a.className,d=a.render,g=a.i18n;a=I(a,["className","render","i18n"]);return u.createElement(T,{className:b,render:d,
value:g.select(a)})}}]);return b}(u.Component));
function X(){var a,b,c=0<arguments.length&&void 0!==arguments[0]?arguments[0]:!1,f=c?"SelectOrdinal":"Plural",d=c?"selectOrdinal":"plural";return b=a=function(a){function b(){var a,c,d,g;n(this,b);for(var k=arguments.length,z=Array(k),p=0;p<k;p++)z[p]=arguments[p];return g=(c=(d=r(this,(a=b.__proto__||l(b)).call.apply(a,[this].concat(z))),d),d.displayName=f,c),r(d,g)}t(b,a);q(b,[{key:"render",value:function(){var a=this.props,b=a.className,c=a.render,f=a.i18n,g=a.value,k=a.offset,p=I(a,["className",
"render","i18n","value","offset"]);a=G(p).reduce(function(a,b){var c=b.replace("_","");a[c]=p[b];return a},{value:Number(g),offset:Number(k)});return u.createElement(T,{className:b,render:c,value:f[d](a)})}}]);return b}(u.Component),a.defaultProps={offset:0},b}var Y=O()(X(!1)),aa=O()(X(!0));function Z(a){return function(b){var c=b.value,f=b.i18n,d=b.className,g=b.render;b=a(f.locales||f.language,b.format);return u.createElement(T,{className:d,render:g,value:b(c)})}}var ba=O()(Z(A.date)),ca=O()(Z(A.number));
exports.i18nMark=function(a){return a};exports.withI18n=O;exports.I18nProvider=M;exports.I18n=N;exports.Trans=V;exports.Plural=Y;exports.Select=W;exports.SelectOrdinal=aa;exports.DateFormat=ba;exports.NumberFormat=ca;
'use strict';Object.defineProperty(exports,"__esModule",{value:!0});function f(d){return d&&"object"===typeof d&&"default"in d?d["default"]:d}
var g=f(require("@babel/runtime/helpers/classCallCheck")),k=f(require("@babel/runtime/helpers/createClass")),l=f(require("@babel/runtime/helpers/possibleConstructorReturn")),m=f(require("@babel/runtime/helpers/getPrototypeOf")),q=f(require("@babel/runtime/helpers/inherits")),r=f(require("@babel/runtime/helpers/assertThisInitialized")),t=f(require("@babel/runtime/helpers/defineProperty")),u=require("react"),v=f(require("@babel/runtime/helpers/slicedToArray")),w=f(require("@babel/runtime/helpers/toConsumableArray")),
x=f(require("@babel/runtime/helpers/objectSpread")),y=f(require("@babel/runtime/helpers/extends")),z=f(require("hoist-non-react-statics")),B=require("@lingui/core"),H=u.createContext({i18n:{},defaultRender:null}),I=H.Provider,J=H.Consumer,K=function(d){function a(h){g(this,a);var b=l(this,m(a).call(this,h));t(r(r(b)),"unsubscribe",void 0);t(r(r(b)),"setContext",function(){var c={context:{i18n:b.props.i18n,defaultRender:b.props.defaultRender}};(0<arguments.length&&void 0!==arguments[0]?arguments[0]:
1)&&b.setState(c);return c});b.state=b.setContext(!1);return b}q(a,d);k(a,[{key:"componentDidMount",value:function(){this.unsubscribe=this.props.i18n.didActivate(this.setContext)}},{key:"componentWillUnmount",value:function(){this.unsubscribe()}},{key:"render",value:function(){var a=this.state.context;return u.createElement(I,{value:a},a.i18n.locale&&this.props.children)}}]);return a}(u.Component),L=/<(\d+)>(.*)<\/\1>|<(\d+)\/>/,M=/(?:\r\n|\r|\n)/g;
function N(d){var a=1<arguments.length&&void 0!==arguments[1]?arguments[1]:[],h=d.replace(M,"").split(L);if(1===h.length)return d;var b=[],c=h.shift();c&&b.push(c);c=!0;var A=!1,e=void 0;try{for(var n=O(h)[Symbol.iterator](),C;!(c=(C=n.next()).done);c=!0){var p=v(C.value,3),D=p[0],E=p[1],F=p[2],G=a[D];b.push(u.cloneElement(G,{key:D},E?N(E,a):G.props.children));F&&b.push(F)}}catch(R){A=!0,e=R}finally{try{c||null==n.return||n.return()}finally{if(A)throw e;}}return b}
function O(d){if(!d.length)return[];var a=d.slice(0,4);a=v(a,4);var h=a[1],b=a[2],c=a[3];return[[parseInt(a[0]||b),h||"",c]].concat(O(d.slice(4,d.length)))}
var P=function(d){function a(){g(this,a);return l(this,m(a).apply(this,arguments))}q(a,d);k(a,[{key:"getTranslation",value:function(a){var b=this.props,c=b.id;c=void 0===c?"":c;var d=b.defaults;b=b.formats;var e=x({},this.props.values),h=this.props.components?w(this.props.components):[];e&&Object.keys(e).forEach(function(a){var c=e[a];u.isValidElement(c)&&(c=h.push(c)-1,e[a]="<".concat(c,"/>"))});return(a=a&&"function"===typeof a._?a._(c,e,{defaults:d,formats:b}):c)?N(a,h):null}},{key:"render",value:function(){var a=
this;return u.createElement(J,null,function(b){var c=b.defaultRender;b=a.getTranslation(b.i18n);var d=a.props,e=d.render;c=void 0===e?c:e;e=d.id;d=d.defaults;return null===c||void 0===c?b:"string"===typeof c?u.createElement(c,{},b):"function"===typeof c?c({id:e,translation:b,defaults:d}):u.cloneElement(c,{},b)})}}]);return a}(u.Component);
function Q(){var d=(0<arguments.length&&void 0!==arguments[0]?arguments[0]:{}).withHash,a=void 0===d?!1:d;return function(d){var b=u.forwardRef(function(c,b){return u.createElement(J,null,function(e){e=e.i18n;return u.createElement(d,y({},c,{ref:b,i18n:e,i18nHash:a?e.locale:void 0}))})});return z(b,d)}}var S=Q(),T=Q({withHash:!0});function U(d){return function(a){var h=a.value,b=a.format;return u.createElement(J,null,function(a){a=a.i18n;return d(a.locales||a.locale,b)(h)})}}var V=U(B.date),W=U(B.number);
exports.setupI18n=B.setupI18n;exports.withI18n=S;exports.withI18nForPure=T;exports.I18nProvider=K;exports.I18n=J;exports.Trans=P;exports.DateFormat=V;exports.NumberFormat=W;
{
"name": "@lingui/react",
"version": "2.7.0",
"version": "3.0.0-1",
"description": "React components for translations",

@@ -29,3 +29,3 @@ "main": "index.js",

"engines": {
"node": ">=4.0"
"node": ">=8.0.0"
},

@@ -44,5 +44,4 @@ "files": [

"dependencies": {
"@lingui/core": "2.7.0",
"babel-runtime": "^6.26.0",
"hash-sum": "^1.0.2",
"@babel/runtime": "^7.0.0",
"@lingui/core": "3.0.0-1",
"hoist-non-react-statics": "3.0.1",

@@ -49,0 +48,0 @@ "prop-types": "^15.6.2"

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc