From aefb69852a8cd8e7cb683ce497e7f9fd1b263a38 Mon Sep 17 00:00:00 2001 From: Jan Muehlemann Date: Mon, 12 Aug 2019 16:23:59 +0200 Subject: [PATCH] rebuild --- package.json | 40 ++--- react-i18next.js | 375 ++++++++++++++++++++----------------------- react-i18next.min.js | 2 +- 3 files changed, 199 insertions(+), 218 deletions(-) diff --git a/package.json b/package.json index a70b8c1f1..388e57324 100644 --- a/package.json +++ b/package.json @@ -41,42 +41,42 @@ "@types/react": "^16.8.2", "all-contributors-cli": "^6.1.1", "babel-core": "^7.0.0-bridge.0", - "babel-eslint": "10.0.1", - "babel-jest": "24.1.0", + "babel-eslint": "10.0.2", + "babel-jest": "24.8.0", "babel-plugin-macros": "^2.5.0", "babel-plugin-tester": "^6.0.0", "coveralls": "^3.0.2", - "dtslint": "^0.5.3", + "dtslint": "^0.9.1", "enzyme": "^3.8.0", "enzyme-adapter-react-16": "^1.9.1", "enzyme-adapter-react-helper": "^1.3.2", - "eslint": "5.13.0", - "eslint-config-airbnb": "17.1.0", - "eslint-config-prettier": "4.0.0", - "eslint-plugin-import": "2.16.0", - "eslint-plugin-jsx-a11y": "6.2.1", - "eslint-plugin-react": "7.12.4", - "husky": "^1.3.1", + "eslint": "6.1.0", + "eslint-config-airbnb": "18.0.0", + "eslint-config-prettier": "6.0.0", + "eslint-plugin-import": "2.18.2", + "eslint-plugin-jsx-a11y": "6.2.3", + "eslint-plugin-react": "7.14.3", + "husky": "^3.0.3", "i18next": "^17.0.8", - "jest": "24.1.0", - "jest-cli": "24.1.0", + "jest": "24.8.0", + "jest-cli": "24.8.0", "lint-staged": "^8.1.3", "mkdirp": "0.5.1", - "prettier": "1.16.4", + "prettier": "1.18.2", "raf": "^3.4.1", - "react": "16.8.1", - "react-dom": "16.8.1", + "react": "16.9.0", + "react-dom": "16.9.0", "rimraf": "2.6.3", - "rollup": "1.1.2", + "rollup": "1.19.4", "rollup-plugin-babel": "^4.3.2", - "rollup-plugin-commonjs": "^9.2.0", - "rollup-plugin-node-resolve": "4.0.0", + "rollup-plugin-commonjs": "^10.0.2", + "rollup-plugin-node-resolve": "5.2.0", "rollup-plugin-replace": "^2.1.0", - "rollup-plugin-terser": "^4.0.4", + "rollup-plugin-terser": "^5.1.1", "sinon": "^7.2.3", "tslint": "^5.13.1", "typescript": "^3.5.3", - "yargs": "12.0.5" + "yargs": "13.3.0" }, "peerDependencies": { "i18next": ">= 14.0.1", diff --git a/react-i18next.js b/react-i18next.js index 1e42eebc2..97146116b 100644 --- a/react-i18next.js +++ b/react-i18next.js @@ -21,20 +21,35 @@ return obj; } - function _objectSpread(target) { + function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + if (enumerableOnly) symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + }); + keys.push.apply(keys, symbols); + } + + return keys; + } + + function _objectSpread2(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; - var ownKeys = Object.keys(source); - if (typeof Object.getOwnPropertySymbols === 'function') { - ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { - return Object.getOwnPropertyDescriptor(source, sym).enumerable; - })); + if (i % 2) { + ownKeys(source, true).forEach(function (key) { + _defineProperty(target, key, source[key]); + }); + } else if (Object.getOwnPropertyDescriptors) { + Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); + } else { + ownKeys(source).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); } - - ownKeys.forEach(function (key) { - _defineProperty(target, key, source[key]); - }); } return target; @@ -76,44 +91,6 @@ return target; } - function _slicedToArray(arr, i) { - return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); - } - - function _arrayWithHoles(arr) { - if (Array.isArray(arr)) return arr; - } - - function _iterableToArrayLimit(arr, i) { - var _arr = []; - var _n = true; - var _d = false; - var _e = undefined; - - try { - for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { - _arr.push(_s.value); - - if (i && _arr.length === i) break; - } - } catch (err) { - _d = true; - _e = err; - } finally { - try { - if (!_n && _i["return"] != null) _i["return"](); - } finally { - if (_d) throw _e; - } - } - - return _arr; - } - - function _nonIterableRest() { - throw new TypeError("Invalid attempt to destructure non-iterable instance"); - } - /** * This file automatically generated from `pre-publish.js`. * Do not manually edit. @@ -330,7 +307,7 @@ stringify: stringify_1 }; - let defaultOptions = { + var defaultOptions = { bindI18n: 'languageChanging languageChanged', bindI18nStore: '', // nsMode: 'fallback' // loop through all namespaces given to hook, HOC, render prop for key lookup @@ -340,9 +317,9 @@ // hashTransKey: key => key // calculate a key for Trans component based on defaultValue useSuspense: true }; - let i18nInstance; - let hasUsedI18nextProvider; - const I18nContext = React__default.createContext(); + var i18nInstance; + var hasUsedI18nextProvider; + var I18nContext = React__default.createContext(); function usedI18nextProvider(used) { hasUsedI18nextProvider = used; } @@ -350,8 +327,8 @@ return hasUsedI18nextProvider; } function setDefaults() { - let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - defaultOptions = _objectSpread({}, defaultOptions, options); + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + defaultOptions = _objectSpread2({}, defaultOptions, {}, options); } function getDefaults() { return defaultOptions; @@ -378,7 +355,7 @@ function getI18n() { return i18nInstance; } - const initReactI18next = { + var initReactI18next = { type: '3rdParty', init(instance) { @@ -389,11 +366,11 @@ }; function composeInitialProps(ForComponent) { return ctx => new Promise(resolve => { - const i18nInitialProps = getInitialProps(); + var i18nInitialProps = getInitialProps(); if (ForComponent.getInitialProps) { ForComponent.getInitialProps(ctx).then(componentsInitialProps => { - resolve(_objectSpread({}, componentsInitialProps, i18nInitialProps)); + resolve(_objectSpread2({}, componentsInitialProps, {}, i18nInitialProps)); }); } else { resolve(i18nInitialProps); @@ -411,10 +388,10 @@ // }; } function getInitialProps() { - const i18n = getI18n(); - const namespaces = i18n.reportNamespaces ? i18n.reportNamespaces.getUsedNamespaces() : []; - const ret = {}; - const initialI18nStore = {}; + var i18n = getI18n(); + var namespaces = i18n.reportNamespaces ? i18n.reportNamespaces.getUsedNamespaces() : []; + var ret = {}; + var initialI18nStore = {}; i18n.languages.forEach(l => { initialI18nStore[l] = {}; namespaces.forEach(ns => { @@ -432,11 +409,11 @@ args[_key] = arguments[_key]; } - if (typeof args[0] === 'string') args[0] = `react-i18next:: ${args[0]}`; + if (typeof args[0] === 'string') args[0] = "react-i18next:: ".concat(args[0]); console.warn(...args); } } - const alreadyWarned = {}; + var alreadyWarned = {}; function warnOnce() { for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { args[_key2] = arguments[_key2]; @@ -460,7 +437,7 @@ if (i18n.isInitialized) { cb(); } else { - const initialized = () => { + var initialized = () => { // due to emitter removing issue in i18next we need to delay remove setTimeout(() => { i18n.off('initialized', initialized); @@ -478,14 +455,14 @@ return true; } - const lng = i18n.languages[0]; - const fallbackLng = i18n.options ? i18n.options.fallbackLng : false; - const lastLng = i18n.languages[i18n.languages.length - 1]; // we're in cimode so this shall pass + var lng = i18n.languages[0]; + var fallbackLng = i18n.options ? i18n.options.fallbackLng : false; + var lastLng = i18n.languages[i18n.languages.length - 1]; // we're in cimode so this shall pass if (lng.toLowerCase() === 'cimode') return true; - const loadNotPending = (l, n) => { - const loadState = i18n.services.backendConnector.state[`${l}|${n}`]; + var loadNotPending = (l, n) => { + var loadState = i18n.services.backendConnector.state["".concat(l, "|").concat(n)]; return loadState === -1 || loadState === 2; }; // loaded -> SUCCESS @@ -518,48 +495,48 @@ function nodesToString(mem, children, index, i18nOptions) { if (!children) return ''; if (Object.prototype.toString.call(children) !== '[object Array]') children = [children]; - const keepArray = i18nOptions.transKeepBasicHtmlNodesFor || []; + var keepArray = i18nOptions.transKeepBasicHtmlNodesFor || []; children.forEach((child, i) => { // const isElement = React.isValidElement(child); // const elementKey = `${index !== 0 ? index + '-' : ''}${i}:${typeof child.type === 'function' ? child.type.name : child.type || 'var'}`; - const elementKey = `${i}`; + var elementKey = "".concat(i); if (typeof child === 'string') { - mem = `${mem}${child}`; + mem = "".concat(mem).concat(child); } else if (hasChildren(child)) { - const elementTag = keepArray.indexOf(child.type) > -1 && Object.keys(child.props).length === 1 && typeof hasChildren(child) === 'string' ? child.type : elementKey; + var elementTag = keepArray.indexOf(child.type) > -1 && Object.keys(child.props).length === 1 && typeof hasChildren(child) === 'string' ? child.type : elementKey; if (child.props && child.props.i18nIsDynamicList) { // we got a dynamic list like """ // the result should be "<0>" and not "<0><0>a<1>b" - mem = `${mem}<${elementTag}>`; + mem = "".concat(mem, "<").concat(elementTag, ">"); } else { // regular case mapping the inner children - mem = `${mem}<${elementTag}>${nodesToString('', getChildren(child), i + 1, i18nOptions)}`; + mem = "".concat(mem, "<").concat(elementTag, ">").concat(nodesToString('', getChildren(child), i + 1, i18nOptions), ""); } } else if (React__default.isValidElement(child)) { if (keepArray.indexOf(child.type) > -1 && Object.keys(child.props).length === 0) { - mem = `${mem}<${child.type}/>`; + mem = "".concat(mem, "<").concat(child.type, "/>"); } else { - mem = `${mem}<${elementKey}>`; + mem = "".concat(mem, "<").concat(elementKey, ">"); } } else if (typeof child === 'object') { - const clone = _objectSpread({}, child); + var clone = _objectSpread2({}, child); - const format = clone.format; + var format = clone.format; delete clone.format; - const keys = Object.keys(clone); + var keys = Object.keys(clone); if (format && keys.length === 1) { - mem = `${mem}{{${keys[0]}, ${format}}}`; + mem = "".concat(mem, "{{").concat(keys[0], ", ").concat(format, "}}"); } else if (keys.length === 1) { - mem = `${mem}{{${keys[0]}}}`; + mem = "".concat(mem, "{{").concat(keys[0], "}}"); } else { // not a valid interpolation object (can only contain one value plus format) - warn(`react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.`, child); + warn("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.", child); } } else { - warn(`Trans: the passed in value is invalid - seems you passed in a variable like {number} - please pass in variables for interpolation as full objects like {{number}}.`, child); + warn("Trans: the passed in value is invalid - seems you passed in a variable like {number} - please pass in variables for interpolation as full objects like {{number}}.", child); } }); return mem; @@ -568,12 +545,12 @@ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts) { if (targetString === '') return []; // check if contains tags we need to replace from html string to react nodes - const keepArray = i18nOptions.transKeepBasicHtmlNodesFor || []; - const emptyChildrenButNeedsHandling = targetString && new RegExp(keepArray.join('|')).test(targetString); // no need to replace tags in the targetstring + var keepArray = i18nOptions.transKeepBasicHtmlNodesFor || []; + var emptyChildrenButNeedsHandling = targetString && new RegExp(keepArray.join('|')).test(targetString); // no need to replace tags in the targetstring if (!children && !emptyChildrenButNeedsHandling) return [targetString]; // v2 -> interpolates upfront no need for "some <0>{{var}}"" -> will be just "some {{var}}" in translation file - const data = {}; + var data = {}; function getData(childs) { if (Object.prototype.toString.call(childs) !== '[object Array]') childs = [childs]; @@ -584,57 +561,59 @@ } getData(children); - targetString = i18n.services.interpolator.interpolate(targetString, _objectSpread({}, data, combinedTOpts), i18n.language); // parse ast from string with additional wrapper tag + targetString = i18n.services.interpolator.interpolate(targetString, _objectSpread2({}, data, {}, combinedTOpts), i18n.language); // parse ast from string with additional wrapper tag // -> avoids issues in parser removing prepending text nodes - const ast = htmlParseStringify2.parse(`<0>${targetString}`); + var ast = htmlParseStringify2.parse("<0>".concat(targetString, "")); function mapAST(reactNodes, astNodes) { if (Object.prototype.toString.call(reactNodes) !== '[object Array]') reactNodes = [reactNodes]; if (Object.prototype.toString.call(astNodes) !== '[object Array]') astNodes = [astNodes]; return astNodes.reduce((mem, node, i) => { - const translationContent = node.children && node.children[0] && node.children[0].content; + var translationContent = node.children && node.children[0] && node.children[0].content; if (node.type === 'tag') { - const child = reactNodes[parseInt(node.name, 10)] || {}; - const isElement = React__default.isValidElement(child); + var child = reactNodes[parseInt(node.name, 10)] || {}; + var isElement = React__default.isValidElement(child); if (typeof child === 'string') { mem.push(child); } else if (hasChildren(child)) { - const childs = getChildren(child); - const mappedChildren = mapAST(childs, node.children); - const inner = hasValidReactChildren(childs) && mappedChildren.length === 0 ? childs : mappedChildren; + var childs = getChildren(child); + var mappedChildren = mapAST(childs, node.children); + var inner = hasValidReactChildren(childs) && mappedChildren.length === 0 ? childs : mappedChildren; if (child.dummy) child.children = inner; // needed on preact! - mem.push(React__default.cloneElement(child, _objectSpread({}, child.props, { + mem.push(React__default.cloneElement(child, _objectSpread2({}, child.props, { key: i }), inner)); } else if (emptyChildrenButNeedsHandling && typeof child === 'object' && child.dummy && !isElement) { // we have a empty Trans node (the dummy element) with a targetstring that contains html tags needing // conversion to react nodes // so we just need to map the inner stuff - const inner = mapAST(reactNodes + var _inner = mapAST(reactNodes /* wrong but we need something */ , node.children); - mem.push(React__default.cloneElement(child, _objectSpread({}, child.props, { + + mem.push(React__default.cloneElement(child, _objectSpread2({}, child.props, { key: i - }), inner)); + }), _inner)); } else if (isNaN(node.name) && i18nOptions.transSupportBasicHtmlNodes) { if (node.voidElement) { mem.push(React__default.createElement(node.name, { - key: `${node.name}-${i}` + key: "".concat(node.name, "-").concat(i) })); } else { - const inner = mapAST(reactNodes + var _inner2 = mapAST(reactNodes /* wrong but we need something */ , node.children); + mem.push(React__default.createElement(node.name, { - key: `${node.name}-${i}` - }, inner)); + key: "".concat(node.name, "-").concat(i) + }, _inner2)); } } else if (typeof child === 'object' && !isElement) { - const content = node.children[0] ? translationContent : null; // v1 + var content = node.children[0] ? translationContent : null; // v1 // as interpolation was done already we just have a regular content node // in the translation AST while having an object in reactNodes // -> push the content no need to interpolate again @@ -643,11 +622,11 @@ } else if (node.children.length === 1 && translationContent) { // If component does not have children, but translation - has // with this in component could be components={[]} and in translation - 'some text <0>some highlighted message' - mem.push(React__default.cloneElement(child, _objectSpread({}, child.props, { + mem.push(React__default.cloneElement(child, _objectSpread2({}, child.props, { key: i }), translationContent)); } else { - mem.push(React__default.cloneElement(child, _objectSpread({}, child.props, { + mem.push(React__default.cloneElement(child, _objectSpread2({}, child.props, { key: i }))); } @@ -662,7 +641,7 @@ // return the children of that extra node to get expected result - const result = mapAST([{ + var result = mapAST([{ dummy: true, children }], ast); @@ -670,74 +649,79 @@ } function Trans(_ref) { - let children = _ref.children, - count = _ref.count, - parent = _ref.parent, - i18nKey = _ref.i18nKey, - tOptions = _ref.tOptions, - values = _ref.values, - defaults = _ref.defaults, - components = _ref.components, - ns = _ref.ns, - i18nFromProps = _ref.i18n, - tFromProps = _ref.t, + var { + children, + count, + parent, + i18nKey, + tOptions, + values, + defaults, + components, + ns, + i18n: i18nFromProps, + t: tFromProps + } = _ref, additionalProps = _objectWithoutProperties(_ref, ["children", "count", "parent", "i18nKey", "tOptions", "values", "defaults", "components", "ns", "i18n", "t"]); - const _ref2 = getHasUsedI18nextProvider() ? React.useContext(I18nContext) || {} : {}, - i18nFromContext = _ref2.i18n, - defaultNSFromContext = _ref2.defaultNS; - - const i18n = i18nFromProps || i18nFromContext || getI18n(); + var { + i18n: i18nFromContext, + defaultNS: defaultNSFromContext + } = getHasUsedI18nextProvider() ? React.useContext(I18nContext) || {} : {}; + var i18n = i18nFromProps || i18nFromContext || getI18n(); if (!i18n) { warnOnce('You will need pass in an i18next instance by using i18nextReactModule'); return children; } - const t = tFromProps || i18n.t.bind(i18n) || (k => k); + var t = tFromProps || i18n.t.bind(i18n) || (k => k); - const reactI18nextOptions = _objectSpread({}, getDefaults(), i18n.options && i18n.options.react); + var reactI18nextOptions = _objectSpread2({}, getDefaults(), {}, i18n.options && i18n.options.react); - const useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent; // prepare having a namespace + var useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent; // prepare having a namespace - let namespaces = ns || t.ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS; + var namespaces = ns || t.ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS; namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation']; - const defaultValue = defaults || nodesToString('', children, 0, reactI18nextOptions) || reactI18nextOptions.transEmptyNodeValue; - const hashTransKey = reactI18nextOptions.hashTransKey; - const key = i18nKey || (hashTransKey ? hashTransKey(defaultValue) : defaultValue); - const interpolationOverride = values ? {} : { + var defaultValue = defaults || nodesToString('', children, 0, reactI18nextOptions) || reactI18nextOptions.transEmptyNodeValue; + var { + hashTransKey + } = reactI18nextOptions; + var key = i18nKey || (hashTransKey ? hashTransKey(defaultValue) : defaultValue); + var interpolationOverride = values ? {} : { interpolation: { prefix: '#$?', suffix: '?$#' } }; - const combinedTOpts = _objectSpread({}, tOptions, values, interpolationOverride, { + var combinedTOpts = _objectSpread2({}, tOptions, {}, values, {}, interpolationOverride, { defaultValue, count, ns: namespaces }); - const translation = key ? t(key, combinedTOpts) : defaultValue; + var translation = key ? t(key, combinedTOpts) : defaultValue; if (!useAsParent) return renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts); return React__default.createElement(useAsParent, additionalProps, renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts)); } function useTranslation(ns) { - let props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; // assert we have the needed i18nInstance - const i18nFromProps = props.i18n; - - const _ref = getHasUsedI18nextProvider() ? React.useContext(I18nContext) || {} : {}, - i18nFromContext = _ref.i18n, - defaultNSFromContext = _ref.defaultNS; - - const i18n = i18nFromProps || i18nFromContext || getI18n(); + var { + i18n: i18nFromProps + } = props; + var { + i18n: i18nFromContext, + defaultNS: defaultNSFromContext + } = getHasUsedI18nextProvider() ? React.useContext(I18nContext) || {} : {}; + var i18n = i18nFromProps || i18nFromContext || getI18n(); if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces(); if (!i18n) { warnOnce('You will need pass in an i18next instance by using initReactI18next'); - const retNotReady = [k => k, {}, false]; + var retNotReady = [k => k, {}, false]; retNotReady.t = k => k; @@ -746,17 +730,18 @@ return retNotReady; } - const i18nOptions = _objectSpread({}, getDefaults(), i18n.options.react); + var i18nOptions = _objectSpread2({}, getDefaults(), {}, i18n.options.react); - const _props$useSuspense = props.useSuspense, - useSuspense = _props$useSuspense === void 0 ? i18nOptions.useSuspense : _props$useSuspense; // prepare having a namespace + var { + useSuspense = i18nOptions.useSuspense + } = props; // prepare having a namespace - let namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS; + var namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS; namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation']; // report namespaces as used if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces); // are we ready? yes if all namespaces in first language are loaded already (either with data or empty object on failed load) - const ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(n => hasLoadedNamespace(n, i18n)); // binding t function to namespace (acts also as rerender trigger) + var ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(n => hasLoadedNamespace(n, i18n)); // binding t function to namespace (acts also as rerender trigger) function getT() { return { @@ -764,16 +749,14 @@ }; } - const _useState = React.useState(getT()), - _useState2 = _slicedToArray(_useState, 2), - t = _useState2[0], - setT = _useState2[1]; // seems we can't have functions as value -> wrap it in obj - + var [t, setT] = React.useState(getT()); // seems we can't have functions as value -> wrap it in obj React.useEffect(() => { - let isMounted = true; - const bindI18n = i18nOptions.bindI18n, - bindI18nStore = i18nOptions.bindI18nStore; // if not ready and not using suspense load the namespaces + var isMounted = true; + var { + bindI18n, + bindI18nStore + } = i18nOptions; // if not ready and not using suspense load the namespaces // in side effect and do not call resetT if unmounted if (!ready && !useSuspense) { @@ -797,7 +780,7 @@ }; }, [namespaces.join()]); // re-run effect whenever list of namespaces changes - const ret = [t.t, i18n, ready]; + var ret = [t.t, i18n, ready]; ret.t = t.t; ret.i18n = i18n; ret.ready = ready; // return hook stuff if ready @@ -815,16 +798,12 @@ } function withTranslation(ns) { - let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; return function Extend(WrappedComponent) { function I18nextWithTranslation(props, ref) { - const _useTranslation = useTranslation(ns, props), - _useTranslation2 = _slicedToArray(_useTranslation, 3), - t = _useTranslation2[0], - i18n = _useTranslation2[1], - ready = _useTranslation2[2]; + var [t, i18n, ready] = useTranslation(ns, props); - const passDownProps = _objectSpread({}, props, { + var passDownProps = _objectSpread2({}, props, { t, i18n, tReady: ready @@ -837,23 +816,20 @@ return React__default.createElement(WrappedComponent, passDownProps); } - I18nextWithTranslation.displayName = `withI18nextTranslation(${getDisplayName(WrappedComponent)})`; + I18nextWithTranslation.displayName = "withI18nextTranslation(".concat(getDisplayName(WrappedComponent), ")"); I18nextWithTranslation.WrappedComponent = WrappedComponent; return options.withRef ? React__default.forwardRef(I18nextWithTranslation) : I18nextWithTranslation; }; } function Translation(props) { - const ns = props.ns, - children = props.children, - options = _objectWithoutProperties(props, ["ns", "children"]); - - const _useTranslation = useTranslation(ns, options), - _useTranslation2 = _slicedToArray(_useTranslation, 3), - t = _useTranslation2[0], - i18n = _useTranslation2[1], - ready = _useTranslation2[2]; + var { + ns, + children + } = props, + options = _objectWithoutProperties(props, ["ns", "children"]); + var [t, i18n, ready] = useTranslation(ns, options); return children(t, { i18n, lng: i18n.language @@ -861,9 +837,11 @@ } function I18nextProvider(_ref) { - let i18n = _ref.i18n, - defaultNS = _ref.defaultNS, - children = _ref.children; + var { + i18n, + defaultNS, + children + } = _ref; usedI18nextProvider(true); return React__default.createElement(I18nContext.Provider, { value: { @@ -874,13 +852,14 @@ } function useSSR(initialI18nStore, initialLanguage) { - let props = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; - const i18nFromProps = props.i18n; - - const _ref = getHasUsedI18nextProvider() ? React.useContext(I18nContext) : {}, - i18nFromContext = _ref.i18n; - - const i18n = i18nFromProps || i18nFromContext || getI18n(); // opt out if is a cloned instance, eg. created by i18next-express-middleware on request + var props = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + var { + i18n: i18nFromProps + } = props; + var { + i18n: i18nFromContext + } = getHasUsedI18nextProvider() ? React.useContext(I18nContext) : {}; + var i18n = i18nFromProps || i18nFromContext || getI18n(); // opt out if is a cloned instance, eg. created by i18next-express-middleware on request // -> do not set initial stuff on server side if (i18n.options && i18n.options.isClone) return; // nextjs / SSR: getting data from next.js or other ssr stack @@ -899,36 +878,38 @@ function withSSR() { return function Extend(WrappedComponent) { function I18nextWithSSR(_ref) { - let initialI18nStore = _ref.initialI18nStore, - initialLanguage = _ref.initialLanguage, + var { + initialI18nStore, + initialLanguage + } = _ref, rest = _objectWithoutProperties(_ref, ["initialI18nStore", "initialLanguage"]); useSSR(initialI18nStore, initialLanguage); - return React__default.createElement(WrappedComponent, _objectSpread({}, rest)); + return React__default.createElement(WrappedComponent, _objectSpread2({}, rest)); } I18nextWithSSR.getInitialProps = composeInitialProps(WrappedComponent); - I18nextWithSSR.displayName = `withI18nextSSR(${getDisplayName(WrappedComponent)})`; + I18nextWithSSR.displayName = "withI18nextSSR(".concat(getDisplayName(WrappedComponent), ")"); I18nextWithSSR.WrappedComponent = WrappedComponent; return I18nextWithSSR; }; } + exports.I18nContext = I18nContext; + exports.I18nextProvider = I18nextProvider; exports.Trans = Trans; - exports.useTranslation = useTranslation; - exports.withTranslation = withTranslation; exports.Translation = Translation; - exports.I18nextProvider = I18nextProvider; - exports.withSSR = withSSR; - exports.useSSR = useSSR; - exports.I18nContext = I18nContext; - exports.initReactI18next = initReactI18next; - exports.setDefaults = setDefaults; + exports.composeInitialProps = composeInitialProps; exports.getDefaults = getDefaults; - exports.setI18n = setI18n; exports.getI18n = getI18n; - exports.composeInitialProps = composeInitialProps; exports.getInitialProps = getInitialProps; + exports.initReactI18next = initReactI18next; + exports.setDefaults = setDefaults; + exports.setI18n = setI18n; + exports.useSSR = useSSR; + exports.useTranslation = useTranslation; + exports.withSSR = withSSR; + exports.withTranslation = withTranslation; Object.defineProperty(exports, '__esModule', { value: true }); diff --git a/react-i18next.min.js b/react-i18next.min.js index 2f7fec63a..34b9fac1c 100644 --- a/react-i18next.min.js +++ b/react-i18next.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e=e||self).ReactI18next={},e.React)}(this,function(e,t){"use strict";var n="default"in t?t.default:t;function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e){for(var t=1;t=0||(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function a(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=[],r=!0,i=!1,o=void 0;try{for(var a,s=e[Symbol.iterator]();!(r=(a=s.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(e){i=!0,o=e}finally{try{r||null==s.return||s.return()}finally{if(i)throw o}}return n}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var s={area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,menuitem:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0},c=/([\w-]+)|=|(['"])([.\s\S]*?)\2/g,l=/(?:|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g,u=Object.create?Object.create(null):{};function p(e,t,n,r,i){var o=t.indexOf("<",r),a=t.slice(r,-1===o?void 0:o);/^\s*$/.test(a)&&(a=" "),(!i&&o>-1&&n+e.length>=0||" "!==a)&&e.push({type:"text",content:a})}function f(e,t){switch(t.type){case"text":return e+t.content;case"tag":return e+="<"+t.name+(t.attrs?function(e){var t=[];for(var n in e)t.push(n+'="'+e[n]+'"');return t.length?" "+t.join(" "):""}(t.attrs):"")+(t.voidElement?"/>":">"),t.voidElement?e:e+t.children.reduce(f,"")+""}}var d={parse:function(e,t){t||(t={}),t.components||(t.components=u);var n,r=[],i=-1,o=[],a={},f=!1;return e.replace(l,function(l,u){if(f){if(l!=="")return;f=!1}var d,g="/"!==l.charAt(1),h=0===l.indexOf("\x3c!--"),m=u+l.length,y=e.charAt(m);g&&!h&&(i++,"tag"===(n=function(e){var t,n=0,r=!0,i={type:"tag",name:"",voidElement:!1,attrs:{},children:[]};return e.replace(c,function(o){if("="===o)return r=!0,void n++;r?0===n?((s[o]||"/"===e.charAt(e.length-2))&&(i.voidElement=!0),i.name=o):(i.attrs[t]=o.replace(/^['"]|['"]$/g,""),t=void 0):(t&&(i.attrs[t]=t),t=o),n++,r=!1}),i}(l)).type&&t.components[n.name]&&(n.type="component",f=!0),n.voidElement||f||!y||"<"===y||p(n.children,e,i,m,t.ignoreWhitespace),a[n.tagName]=n,0===i&&r.push(n),(d=o[i-1])&&d.children.push(n),o[i]=n),(h||!g||n.voidElement)&&(h||i--,!f&&"<"!==y&&y&&p(d=-1===i?r:o[i].children,e,i,m,t.ignoreWhitespace))}),!r.length&&e.length&&p(r,e,0,0,t.ignoreWhitespace),r},stringify:function(e){return e.reduce(function(e,t){return e+f("",t)},"")}};let g,h,m={bindI18n:"languageChanging languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0};const y=n.createContext();function b(){return h}function v(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};m=i({},m,e)}function O(){return m}class S{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach(e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)})}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}function j(e){g=e}function w(){return g}const E={type:"3rdParty",init(e){v(e.options.react),j(e)}};function N(e){return t=>new Promise(n=>{const r=x();e.getInitialProps?e.getInitialProps(t).then(e=>{n(i({},e,r))}):n(r)})}function x(){const e=w(),t=e.reportNamespaces?e.reportNamespaces.getUsedNamespaces():[],n={},r={};return e.languages.forEach(n=>{r[n]={},t.forEach(t=>{r[n][t]=e.getResourceBundle(n,t)||{}})}),n.initialI18nStore=r,n.initialLanguage=e.language,n}function $(){if(console&&console.warn){for(var e=arguments.length,t=new Array(e),n=0;n{if(e.isInitialized)n();else{const t=()=>{setTimeout(()=>{e.off("initialized",t)},0),n()};e.on("initialized",t)}})}function R(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}function C(e){return e&&(e.children||e.props&&e.props.children)}function A(e){return e?e&&e.children?e.children:e.props&&e.props.children:[]}function T(e,t,r,o,a){if(""===t)return[];const s=o.transKeepBasicHtmlNodesFor||[],c=t&&new RegExp(s.join("|")).test(t);if(!e&&!c)return[t];const l={};!function e(t){"[object Array]"!==Object.prototype.toString.call(t)&&(t=[t]),t.forEach(t=>{"string"!=typeof t&&(C(t)?e(A(t)):"object"!=typeof t||n.isValidElement(t)||Object.assign(l,t))})}(e),t=r.services.interpolator.interpolate(t,i({},l,a),r.language);const u=function e(t,r){return"[object Array]"!==Object.prototype.toString.call(t)&&(t=[t]),"[object Array]"!==Object.prototype.toString.call(r)&&(r=[r]),r.reduce((r,a,s)=>{const l=a.children&&a.children[0]&&a.children[0].content;if("tag"===a.type){const u=t[parseInt(a.name,10)]||{},p=n.isValidElement(u);if("string"==typeof u)r.push(u);else if(C(u)){const t=A(u),o=e(t,a.children),c=function(e){return"[object Array]"===Object.prototype.toString.call(e)&&e.every(e=>n.isValidElement(e))}(t)&&0===o.length?t:o;u.dummy&&(u.children=c),r.push(n.cloneElement(u,i({},u.props,{key:s}),c))}else if(c&&"object"==typeof u&&u.dummy&&!p){const o=e(t,a.children);r.push(n.cloneElement(u,i({},u.props,{key:s}),o))}else if(isNaN(a.name)&&o.transSupportBasicHtmlNodes)if(a.voidElement)r.push(n.createElement(a.name,{key:`${a.name}-${s}`}));else{const i=e(t,a.children);r.push(n.createElement(a.name,{key:`${a.name}-${s}`},i))}else if("object"!=typeof u||p)1===a.children.length&&l?r.push(n.cloneElement(u,i({},u.props,{key:s}),l)):r.push(n.cloneElement(u,i({},u.props,{key:s})));else{const e=a.children[0]?l:null;e&&r.push(e)}}else"text"===a.type&&r.push(a.content);return r},[])}([{dummy:!0,children:e}],d.parse(`<0>${t}`));return A(u[0])}function z(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const r=n.i18n,o=b()&&t.useContext(y)||{},s=o.i18n,c=o.defaultNS,l=r||s||w();if(l&&!l.reportNamespaces&&(l.reportNamespaces=new S),!l){k("You will need pass in an i18next instance by using initReactI18next");const e=[e=>e,{},!1];return e.t=(e=>e),e.i18n={},e.ready=!1,e}const u=i({},O(),l.options.react),p=n.useSuspense,f=void 0===p?u.useSuspense:p;let d=e||c||l.options&&l.options.defaultNS;d="string"==typeof d?[d]:d||["translation"],l.reportNamespaces.addUsedNamespaces&&l.reportNamespaces.addUsedNamespaces(d);const g=(l.isInitialized||l.initializedStoreOnce)&&d.every(e=>(function(e,t){if(!t.languages||!t.languages.length)return k("i18n.languages were undefined or empty",t.languages),!0;const n=t.languages[0],r=!!t.options&&t.options.fallbackLng,i=t.languages[t.languages.length-1];if("cimode"===n.toLowerCase())return!0;const o=(e,n)=>{const r=t.services.backendConnector.state[`${e}|${n}`];return-1===r||2===r};return!!t.hasResourceBundle(n,e)||!t.services.backendConnector.backend||!(!o(n,e)||r&&!o(i,e))})(e,l));function h(){return{t:l.getFixedT(null,"fallback"===u.nsMode?d:d[0])}}const m=a(t.useState(h()),2),v=m[0],j=m[1];t.useEffect(()=>{let e=!0;const t=u.bindI18n,n=u.bindI18nStore;function r(){e&&j(h())}return g||f||P(l,d,()=>{e&&j(h())}),t&&l&&l.on(t,r),n&&l&&l.store.on(n,r),()=>{e=!1,t&&l&&t.split(" ").forEach(e=>l.off(e,r)),n&&l&&n.split(" ").forEach(e=>l.store.off(e,r))}},[d.join()]);const E=[v.t,l,g];if(E.t=v.t,E.i18n=l,E.ready=g,g)return E;if(!g&&!f)return E;throw new Promise(e=>{P(l,d,()=>{j(h()),e()})})}function L(e,n){const r=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).i18n,i=(b()?t.useContext(y):{}).i18n,o=r||i||w();o.options&&o.options.isClone||(e&&!o.initializedStoreOnce&&(o.services.resourceStore.data=e,o.initializedStoreOnce=!0),n&&!o.initializedLanguageOnce&&(o.changeLanguage(n),o.initializedLanguageOnce=!0))}e.Trans=function(e){let r=e.children,a=e.count,s=e.parent,c=e.i18nKey,l=e.tOptions,u=e.values,p=e.defaults,f=e.components,d=e.ns,g=e.i18n,h=e.t,m=o(e,["children","count","parent","i18nKey","tOptions","values","defaults","components","ns","i18n","t"]);const v=b()&&t.useContext(y)||{},S=v.i18n,j=v.defaultNS,E=g||S||w();if(!E)return k("You will need pass in an i18next instance by using i18nextReactModule"),r;const N=h||E.t.bind(E)||(e=>e),x=i({},O(),E.options&&E.options.react),I=void 0!==s?s:x.defaultTransParent;let P=d||N.ns||j||E.options&&E.options.defaultNS;P="string"==typeof P?[P]:P||["translation"];const R=p||function e(t,r,o,a){if(!r)return"";"[object Array]"!==Object.prototype.toString.call(r)&&(r=[r]);const s=a.transKeepBasicHtmlNodesFor||[];return r.forEach((r,o)=>{const c=`${o}`;if("string"==typeof r)t=`${t}${r}`;else if(C(r)){const n=s.indexOf(r.type)>-1&&1===Object.keys(r.props).length&&"string"==typeof C(r)?r.type:c;t=r.props&&r.props.i18nIsDynamicList?`${t}<${n}>`:`${t}<${n}>${e("",A(r),o+1,a)}`}else if(n.isValidElement(r))t=s.indexOf(r.type)>-1&&0===Object.keys(r.props).length?`${t}<${r.type}/>`:`${t}<${c}>`;else if("object"==typeof r){const e=i({},r),n=e.format;delete e.format;const o=Object.keys(e);n&&1===o.length?t=`${t}{{${o[0]}, ${n}}}`:1===o.length?t=`${t}{{${o[0]}}}`:$("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",r)}else $("Trans: the passed in value is invalid - seems you passed in a variable like {number} - please pass in variables for interpolation as full objects like {{number}}.",r)}),t}("",r,0,x)||x.transEmptyNodeValue,z=x.hashTransKey,L=c||(z?z(R):R),B=i({},l,u,u?{}:{interpolation:{prefix:"#$?",suffix:"?$#"}},{defaultValue:R,count:a,ns:P}),V=L?N(L,B):R;return I?n.createElement(I,m,T(f||r,V,E,x,B)):T(f||r,V,E,x,B)},e.useTranslation=z,e.withTranslation=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(r){function o(o,s){const c=a(z(e,o),3),l=i({},o,{t:c[0],i18n:c[1],tReady:c[2]});return t.withRef&&s&&(l.ref=s),n.createElement(r,l)}return o.displayName=`withI18nextTranslation(${R(r)})`,o.WrappedComponent=r,t.withRef?n.forwardRef(o):o}},e.Translation=function(e){const t=e.ns,n=e.children,r=a(z(t,o(e,["ns","children"])),3),i=r[0],s=r[1],c=r[2];return n(i,{i18n:s,lng:s.language},c)},e.I18nextProvider=function(e){let t=e.i18n,r=e.defaultNS,i=e.children;return h=!0,n.createElement(y.Provider,{value:{i18n:t,defaultNS:r}},i)},e.withSSR=function(){return function(e){function t(t){let r=t.initialI18nStore,a=t.initialLanguage,s=o(t,["initialI18nStore","initialLanguage"]);return L(r,a),n.createElement(e,i({},s))}return t.getInitialProps=N(e),t.displayName=`withI18nextSSR(${R(e)})`,t.WrappedComponent=e,t}},e.useSSR=L,e.I18nContext=y,e.initReactI18next=E,e.setDefaults=v,e.getDefaults=O,e.setI18n=j,e.getI18n=w,e.composeInitialProps=N,e.getInitialProps=x,Object.defineProperty(e,"__esModule",{value:!0})}); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e=e||self).ReactI18next={},e.React)}(this,function(e,t){"use strict";var n="default"in t?t.default:t;function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var c={area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,menuitem:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0},s=/([\w-]+)|=|(['"])([.\s\S]*?)\2/g,l=/(?:|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g,u=Object.create?Object.create(null):{};function p(e,t,n,r,a){var i=t.indexOf("<",r),o=t.slice(r,-1===i?void 0:i);/^\s*$/.test(o)&&(o=" "),(!a&&i>-1&&n+e.length>=0||" "!==o)&&e.push({type:"text",content:o})}function f(e,t){switch(t.type){case"text":return e+t.content;case"tag":return e+="<"+t.name+(t.attrs?function(e){var t=[];for(var n in e)t.push(n+'="'+e[n]+'"');return t.length?" "+t.join(" "):""}(t.attrs):"")+(t.voidElement?"/>":">"),t.voidElement?e:e+t.children.reduce(f,"")+""}}var d,g,h={parse:function(e,t){t||(t={}),t.components||(t.components=u);var n,r=[],a=-1,i=[],o={},f=!1;return e.replace(l,function(l,u){if(f){if(l!=="")return;f=!1}var d,g="/"!==l.charAt(1),h=0===l.indexOf("\x3c!--"),m=u+l.length,y=e.charAt(m);g&&!h&&(a++,"tag"===(n=function(e){var t,n=0,r=!0,a={type:"tag",name:"",voidElement:!1,attrs:{},children:[]};return e.replace(s,function(i){if("="===i)return r=!0,void n++;r?0===n?((c[i]||"/"===e.charAt(e.length-2))&&(a.voidElement=!0),a.name=i):(a.attrs[t]=i.replace(/^['"]|['"]$/g,""),t=void 0):(t&&(a.attrs[t]=t),t=i),n++,r=!1}),a}(l)).type&&t.components[n.name]&&(n.type="component",f=!0),n.voidElement||f||!y||"<"===y||p(n.children,e,a,m,t.ignoreWhitespace),o[n.tagName]=n,0===a&&r.push(n),(d=i[a-1])&&d.children.push(n),i[a]=n),(h||!g||n.voidElement)&&(h||a--,!f&&"<"!==y&&y&&p(d=-1===a?r:i[a].children,e,a,m,t.ignoreWhitespace))}),!r.length&&e.length&&p(r,e,0,0,t.ignoreWhitespace),r},stringify:function(e){return e.reduce(function(e,t){return e+f("",t)},"")}},m={bindI18n:"languageChanging languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0},y=n.createContext();function v(){return g}function b(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};m=i({},m,{},e)}function O(){return m}class j{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach(e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)})}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}function S(e){d=e}function w(){return d}var E={type:"3rdParty",init(e){b(e.options.react),S(e)}};function N(e){return t=>new Promise(n=>{var r=x();e.getInitialProps?e.getInitialProps(t).then(e=>{n(i({},e,{},r))}):n(r)})}function x(){var e=w(),t=e.reportNamespaces?e.reportNamespaces.getUsedNamespaces():[],n={},r={};return e.languages.forEach(n=>{r[n]={},t.forEach(t=>{r[n][t]=e.getResourceBundle(n,t)||{}})}),n.initialI18nStore=r,n.initialLanguage=e.language,n}function I(){if(console&&console.warn){for(var e=arguments.length,t=new Array(e),n=0;n{if(e.isInitialized)n();else{var t=()=>{setTimeout(()=>{e.off("initialized",t)},0),n()};e.on("initialized",t)}})}function C(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}function A(e){return e&&(e.children||e.props&&e.props.children)}function T(e){return e?e&&e.children?e.children:e.props&&e.props.children:[]}function z(e,t,r,a,o){if(""===t)return[];var c=a.transKeepBasicHtmlNodesFor||[],s=t&&new RegExp(c.join("|")).test(t);if(!e&&!s)return[t];var l={};!function e(t){"[object Array]"!==Object.prototype.toString.call(t)&&(t=[t]),t.forEach(t=>{"string"!=typeof t&&(A(t)?e(T(t)):"object"!=typeof t||n.isValidElement(t)||Object.assign(l,t))})}(e),t=r.services.interpolator.interpolate(t,i({},l,{},o),r.language);var u=function e(t,r){return"[object Array]"!==Object.prototype.toString.call(t)&&(t=[t]),"[object Array]"!==Object.prototype.toString.call(r)&&(r=[r]),r.reduce((r,o,c)=>{var l=o.children&&o.children[0]&&o.children[0].content;if("tag"===o.type){var u=t[parseInt(o.name,10)]||{},p=n.isValidElement(u);if("string"==typeof u)r.push(u);else if(A(u)){var f=T(u),d=e(f,o.children),g=function(e){return"[object Array]"===Object.prototype.toString.call(e)&&e.every(e=>n.isValidElement(e))}(f)&&0===d.length?f:d;u.dummy&&(u.children=g),r.push(n.cloneElement(u,i({},u.props,{key:c}),g))}else if(s&&"object"==typeof u&&u.dummy&&!p){var h=e(t,o.children);r.push(n.cloneElement(u,i({},u.props,{key:c}),h))}else if(isNaN(o.name)&&a.transSupportBasicHtmlNodes)if(o.voidElement)r.push(n.createElement(o.name,{key:"".concat(o.name,"-").concat(c)}));else{var m=e(t,o.children);r.push(n.createElement(o.name,{key:"".concat(o.name,"-").concat(c)},m))}else if("object"!=typeof u||p)1===o.children.length&&l?r.push(n.cloneElement(u,i({},u.props,{key:c}),l)):r.push(n.cloneElement(u,i({},u.props,{key:c})));else{var y=o.children[0]?l:null;y&&r.push(y)}}else"text"===o.type&&r.push(o.content);return r},[])}([{dummy:!0,children:e}],h.parse("<0>".concat(t,"")));return T(u[0])}function L(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{i18n:r}=n,{i18n:a,defaultNS:o}=v()&&t.useContext(y)||{},c=r||a||w();if(c&&!c.reportNamespaces&&(c.reportNamespaces=new j),!c){P("You will need pass in an i18next instance by using initReactI18next");var s=[e=>e,{},!1];return s.t=e=>e,s.i18n={},s.ready=!1,s}var l=i({},O(),{},c.options.react),{useSuspense:u=l.useSuspense}=n,p=e||o||c.options&&c.options.defaultNS;p="string"==typeof p?[p]:p||["translation"],c.reportNamespaces.addUsedNamespaces&&c.reportNamespaces.addUsedNamespaces(p);var f=(c.isInitialized||c.initializedStoreOnce)&&p.every(e=>(function(e,t){if(!t.languages||!t.languages.length)return P("i18n.languages were undefined or empty",t.languages),!0;var n=t.languages[0],r=!!t.options&&t.options.fallbackLng,a=t.languages[t.languages.length-1];if("cimode"===n.toLowerCase())return!0;var i=(e,n)=>{var r=t.services.backendConnector.state["".concat(e,"|").concat(n)];return-1===r||2===r};return!!t.hasResourceBundle(n,e)||(!t.services.backendConnector.backend||!(!i(n,e)||r&&!i(a,e)))})(e,c));function d(){return{t:c.getFixedT(null,"fallback"===l.nsMode?p:p[0])}}var[g,h]=t.useState(d());t.useEffect(()=>{var e=!0,{bindI18n:t,bindI18nStore:n}=l;function r(){e&&h(d())}return f||u||R(c,p,()=>{e&&h(d())}),t&&c&&c.on(t,r),n&&c&&c.store.on(n,r),()=>{e=!1,t&&c&&t.split(" ").forEach(e=>c.off(e,r)),n&&c&&n.split(" ").forEach(e=>c.store.off(e,r))}},[p.join()]);var m=[g.t,c,f];if(m.t=g.t,m.i18n=c,m.ready=f,f)return m;if(!f&&!u)return m;throw new Promise(e=>{R(c,p,()=>{h(d()),e()})})}function D(e,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},{i18n:a}=r,{i18n:i}=v()?t.useContext(y):{},o=a||i||w();o.options&&o.options.isClone||(e&&!o.initializedStoreOnce&&(o.services.resourceStore.data=e,o.initializedStoreOnce=!0),n&&!o.initializedLanguageOnce&&(o.changeLanguage(n),o.initializedLanguageOnce=!0))}e.I18nContext=y,e.I18nextProvider=function(e){var{i18n:t,defaultNS:r,children:a}=e;return g=!0,n.createElement(y.Provider,{value:{i18n:t,defaultNS:r}},a)},e.Trans=function(e){var{children:r,count:a,parent:c,i18nKey:s,tOptions:l,values:u,defaults:p,components:f,ns:d,i18n:g,t:h}=e,m=o(e,["children","count","parent","i18nKey","tOptions","values","defaults","components","ns","i18n","t"]),{i18n:b,defaultNS:j}=v()&&t.useContext(y)||{},S=g||b||w();if(!S)return P("You will need pass in an i18next instance by using i18nextReactModule"),r;var E=h||S.t.bind(S)||(e=>e),N=i({},O(),{},S.options&&S.options.react),x=void 0!==c?c:N.defaultTransParent,k=d||E.ns||j||S.options&&S.options.defaultNS;k="string"==typeof k?[k]:k||["translation"];var R=p||function e(t,r,a,o){if(!r)return"";"[object Array]"!==Object.prototype.toString.call(r)&&(r=[r]);var c=o.transKeepBasicHtmlNodesFor||[];return r.forEach((r,a)=>{var s="".concat(a);if("string"==typeof r)t="".concat(t).concat(r);else if(A(r)){var l=c.indexOf(r.type)>-1&&1===Object.keys(r.props).length&&"string"==typeof A(r)?r.type:s;t=r.props&&r.props.i18nIsDynamicList?"".concat(t,"<").concat(l,">"):"".concat(t,"<").concat(l,">").concat(e("",T(r),a+1,o),"")}else if(n.isValidElement(r))t=c.indexOf(r.type)>-1&&0===Object.keys(r.props).length?"".concat(t,"<").concat(r.type,"/>"):"".concat(t,"<").concat(s,">");else if("object"==typeof r){var u=i({},r),p=u.format;delete u.format;var f=Object.keys(u);p&&1===f.length?t="".concat(t,"{{").concat(f[0],", ").concat(p,"}}"):1===f.length?t="".concat(t,"{{").concat(f[0],"}}"):I("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",r)}else I("Trans: the passed in value is invalid - seems you passed in a variable like {number} - please pass in variables for interpolation as full objects like {{number}}.",r)}),t}("",r,0,N)||N.transEmptyNodeValue,{hashTransKey:C}=N,L=s||(C?C(R):R),D=i({},l,{},u,{},u?{}:{interpolation:{prefix:"#$?",suffix:"?$#"}},{defaultValue:R,count:a,ns:k}),B=L?E(L,D):R;return x?n.createElement(x,m,z(f||r,B,S,N,D)):z(f||r,B,S,N,D)},e.Translation=function(e){var{ns:t,children:n}=e,r=o(e,["ns","children"]),[a,i,c]=L(t,r);return n(a,{i18n:i,lng:i.language},c)},e.composeInitialProps=N,e.getDefaults=O,e.getI18n=w,e.getInitialProps=x,e.initReactI18next=E,e.setDefaults=b,e.setI18n=S,e.useSSR=D,e.useTranslation=L,e.withSSR=function(){return function(e){function t(t){var{initialI18nStore:r,initialLanguage:a}=t,c=o(t,["initialI18nStore","initialLanguage"]);return D(r,a),n.createElement(e,i({},c))}return t.getInitialProps=N(e),t.displayName="withI18nextSSR(".concat(C(e),")"),t.WrappedComponent=e,t}},e.withTranslation=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(r){function a(a,o){var[c,s,l]=L(e,a),u=i({},a,{t:c,i18n:s,tReady:l});return t.withRef&&o&&(u.ref=o),n.createElement(r,u)}return a.displayName="withI18nextTranslation(".concat(C(r),")"),a.WrappedComponent=r,t.withRef?n.forwardRef(a):a}},Object.defineProperty(e,"__esModule",{value:!0})});