From 1df77dd08a27a03753b6c8aa7b6e3dc3c12ec02f Mon Sep 17 00:00:00 2001 From: Adriano Raiano Date: Sat, 20 Jan 2024 13:05:12 +0100 Subject: [PATCH] build --- react-i18next.js | 1676 +++++++++++++++++++++--------------------- react-i18next.min.js | 2 +- 2 files changed, 831 insertions(+), 847 deletions(-) diff --git a/react-i18next.js b/react-i18next.js index d911fdda3..ef3deb0cc 100644 --- a/react-i18next.js +++ b/react-i18next.js @@ -1,869 +1,853 @@ (function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) : - typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) : - (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactI18next = {}, global.React)); -})(this, (function (exports, React) { 'use strict'; + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) : + typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) : + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactI18next = {}, global.React)); +})(this, (function (exports, react) { 'use strict'; - function _extends() { - _extends = Object.assign ? Object.assign.bind() : function (target) { - for (var i = 1; i < arguments.length; i++) { - var source = arguments[i]; - for (var key in source) { - if (Object.prototype.hasOwnProperty.call(source, key)) { - target[key] = source[key]; - } - } - } - return target; - }; - return _extends.apply(this, arguments); - } + function getDefaultExportFromCjs (x) { + return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; + } - function getDefaultExportFromCjs (x) { - return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; - } + var voidElements = { + "area": true, + "base": true, + "br": true, + "col": true, + "embed": true, + "hr": true, + "img": true, + "input": true, + "link": true, + "meta": true, + "param": true, + "source": true, + "track": true, + "wbr": true + }; - var voidElements = { - "area": true, - "base": true, - "br": true, - "col": true, - "embed": true, - "hr": true, - "img": true, - "input": true, - "link": true, - "meta": true, - "param": true, - "source": true, - "track": true, - "wbr": true - }; + var e = /*@__PURE__*/getDefaultExportFromCjs(voidElements); - var e = /*@__PURE__*/getDefaultExportFromCjs(voidElements); + var t = /\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g; + function n(n) { + var r = { + type: "tag", + name: "", + voidElement: !1, + attrs: {}, + children: [] + }, + i = n.match(/<\/?([^\s]+?)[/\s>]/); + if (i && (r.name = i[1], (e[i[1]] || "/" === n.charAt(n.length - 2)) && (r.voidElement = !0), r.name.startsWith("!--"))) { + var s = n.indexOf("--\x3e"); + return { + type: "comment", + comment: -1 !== s ? n.slice(4, s) : "" + }; + } + for (var a = new RegExp(t), c = null; null !== (c = a.exec(n));) if (c[0].trim()) if (c[1]) { + var o = c[1].trim(), + l = [o, ""]; + o.indexOf("=") > -1 && (l = o.split("=")), r.attrs[l[0]] = l[1], a.lastIndex--; + } else c[2] && (r.attrs[c[2]] = c[3].trim().substring(1, c[3].length - 1)); + return r; + } + var r = /<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g, + i = /^\s*$/, + s = Object.create(null); + function a(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(a, "") + ""; + case "comment": + return e + "\x3c!--" + t.comment + "--\x3e"; + } + } + var c = { + parse: function (e, t) { + t || (t = {}), t.components || (t.components = s); + var a, + c = [], + o = [], + l = -1, + m = !1; + if (0 !== e.indexOf("<")) { + var u = e.indexOf("<"); + c.push({ + type: "text", + content: -1 === u ? e : e.substring(0, u) + }); + } + return e.replace(r, function (r, s) { + if (m) { + if (r !== "") return; + m = !1; + } + var u, + f = "/" !== r.charAt(1), + h = r.startsWith("\x3c!--"), + p = s + r.length, + d = e.charAt(p); + if (h) { + var v = n(r); + return l < 0 ? (c.push(v), c) : ((u = o[l]).children.push(v), c); + } + if (f && (l++, "tag" === (a = n(r)).type && t.components[a.name] && (a.type = "component", m = !0), a.voidElement || m || !d || "<" === d || a.children.push({ + type: "text", + content: e.slice(p, e.indexOf("<", p)) + }), 0 === l && c.push(a), (u = o[l - 1]) && u.children.push(a), o[l] = a), (!f || a.voidElement) && (l > -1 && (a.voidElement || a.name === r.slice(2, -1)) && (l--, a = -1 === l ? c : o[l]), !m && "<" !== d && d)) { + u = -1 === l ? c : o[l].children; + var x = e.indexOf("<", p), + g = e.slice(p, -1 === x ? void 0 : x); + i.test(g) && (g = " "), (x > -1 && l + u.length >= 0 || " " !== g) && u.push({ + type: "text", + content: g + }); + } + }), c; + }, + stringify: function (e) { + return e.reduce(function (e, t) { + return e + a("", t); + }, ""); + } + }; - var t = /\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g; - function n(n) { - var r = { - type: "tag", - name: "", - voidElement: !1, - attrs: {}, - children: [] - }, - i = n.match(/<\/?([^\s]+?)[/\s>]/); - if (i && (r.name = i[1], (e[i[1]] || "/" === n.charAt(n.length - 2)) && (r.voidElement = !0), r.name.startsWith("!--"))) { - var s = n.indexOf("--\x3e"); - return { - type: "comment", - comment: -1 !== s ? n.slice(4, s) : "" - }; - } - for (var a = new RegExp(t), c = null; null !== (c = a.exec(n));) if (c[0].trim()) if (c[1]) { - var o = c[1].trim(), - l = [o, ""]; - o.indexOf("=") > -1 && (l = o.split("=")), r.attrs[l[0]] = l[1], a.lastIndex--; - } else c[2] && (r.attrs[c[2]] = c[3].trim().substring(1, c[3].length - 1)); - return r; - } - var r = /<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g, - i = /^\s*$/, - s = Object.create(null); - function a(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(a, "") + ""; - case "comment": - return e + "\x3c!--" + t.comment + "--\x3e"; - } - } - var c = { - parse: function (e, t) { - t || (t = {}), t.components || (t.components = s); - var a, - c = [], - o = [], - l = -1, - m = !1; - if (0 !== e.indexOf("<")) { - var u = e.indexOf("<"); - c.push({ - type: "text", - content: -1 === u ? e : e.substring(0, u) - }); - } - return e.replace(r, function (r, s) { - if (m) { - if (r !== "") return; - m = !1; - } - var u, - f = "/" !== r.charAt(1), - h = r.startsWith("\x3c!--"), - p = s + r.length, - d = e.charAt(p); - if (h) { - var v = n(r); - return l < 0 ? (c.push(v), c) : ((u = o[l]).children.push(v), c); - } - if (f && (l++, "tag" === (a = n(r)).type && t.components[a.name] && (a.type = "component", m = !0), a.voidElement || m || !d || "<" === d || a.children.push({ - type: "text", - content: e.slice(p, e.indexOf("<", p)) - }), 0 === l && c.push(a), (u = o[l - 1]) && u.children.push(a), o[l] = a), (!f || a.voidElement) && (l > -1 && (a.voidElement || a.name === r.slice(2, -1)) && (l--, a = -1 === l ? c : o[l]), !m && "<" !== d && d)) { - u = -1 === l ? c : o[l].children; - var x = e.indexOf("<", p), - g = e.slice(p, -1 === x ? void 0 : x); - i.test(g) && (g = " "), (x > -1 && l + u.length >= 0 || " " !== g) && u.push({ - type: "text", - content: g - }); - } - }), c; - }, - stringify: function (e) { - return e.reduce(function (e, t) { - return e + a("", t); - }, ""); - } - }; + function warn() { + if (console && console.warn) { + for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + if (typeof args[0] === 'string') args[0] = `react-i18next:: ${args[0]}`; + console.warn(...args); + } + } + const alreadyWarned = {}; + function warnOnce() { + for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { + args[_key2] = arguments[_key2]; + } + if (typeof args[0] === 'string' && alreadyWarned[args[0]]) return; + if (typeof args[0] === 'string') alreadyWarned[args[0]] = new Date(); + warn(...args); + } + const loadedClb = (i18n, cb) => () => { + if (i18n.isInitialized) { + cb(); + } else { + const initialized = () => { + setTimeout(() => { + i18n.off('initialized', initialized); + }, 0); + cb(); + }; + i18n.on('initialized', initialized); + } + }; + function loadNamespaces(i18n, ns, cb) { + i18n.loadNamespaces(ns, loadedClb(i18n, cb)); + } + function loadLanguages(i18n, lng, ns, cb) { + if (typeof ns === 'string') ns = [ns]; + ns.forEach(n => { + if (i18n.options.ns.indexOf(n) < 0) i18n.options.ns.push(n); + }); + i18n.loadLanguages(lng, loadedClb(i18n, cb)); + } + function oldI18nextHasLoadedNamespace(ns, i18n) { + let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + const lng = i18n.languages[0]; + const fallbackLng = i18n.options ? i18n.options.fallbackLng : false; + const lastLng = i18n.languages[i18n.languages.length - 1]; + if (lng.toLowerCase() === 'cimode') return true; + const loadNotPending = (l, n) => { + const loadState = i18n.services.backendConnector.state[`${l}|${n}`]; + return loadState === -1 || loadState === 2; + }; + if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18n.services.backendConnector.backend && i18n.isLanguageChangingTo && !loadNotPending(i18n.isLanguageChangingTo, ns)) return false; + if (i18n.hasResourceBundle(lng, ns)) return true; + if (!i18n.services.backendConnector.backend || i18n.options.resources && !i18n.options.partialBundledLanguages) return true; + if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true; + return false; + } + function hasLoadedNamespace(ns, i18n) { + let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + if (!i18n.languages || !i18n.languages.length) { + warnOnce('i18n.languages were undefined or empty', i18n.languages); + return true; + } + const isNewerI18next = i18n.options.ignoreJSONStructure !== undefined; + if (!isNewerI18next) { + return oldI18nextHasLoadedNamespace(ns, i18n, options); + } + return i18n.hasLoadedNamespace(ns, { + lng: options.lng, + precheck: (i18nInstance, loadNotPending) => { + if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18nInstance.services.backendConnector.backend && i18nInstance.isLanguageChangingTo && !loadNotPending(i18nInstance.isLanguageChangingTo, ns)) return false; + } + }); + } + function getDisplayName(Component) { + return Component.displayName || Component.name || (typeof Component === 'string' && Component.length > 0 ? Component : 'Unknown'); + } - function warn() { - if (console && console.warn) { - for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { - args[_key] = arguments[_key]; - } - if (typeof args[0] === 'string') args[0] = `react-i18next:: ${args[0]}`; - console.warn(...args); - } - } - const alreadyWarned = {}; - function warnOnce() { - for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { - args[_key2] = arguments[_key2]; - } - if (typeof args[0] === 'string' && alreadyWarned[args[0]]) return; - if (typeof args[0] === 'string') alreadyWarned[args[0]] = new Date(); - warn(...args); - } - const loadedClb = (i18n, cb) => () => { - if (i18n.isInitialized) { - cb(); - } else { - const initialized = () => { - setTimeout(() => { - i18n.off('initialized', initialized); - }, 0); - cb(); - }; - i18n.on('initialized', initialized); - } - }; - function loadNamespaces(i18n, ns, cb) { - i18n.loadNamespaces(ns, loadedClb(i18n, cb)); - } - function loadLanguages(i18n, lng, ns, cb) { - if (typeof ns === 'string') ns = [ns]; - ns.forEach(n => { - if (i18n.options.ns.indexOf(n) < 0) i18n.options.ns.push(n); - }); - i18n.loadLanguages(lng, loadedClb(i18n, cb)); - } - function oldI18nextHasLoadedNamespace(ns, i18n) { - let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; - const lng = i18n.languages[0]; - const fallbackLng = i18n.options ? i18n.options.fallbackLng : false; - const lastLng = i18n.languages[i18n.languages.length - 1]; - if (lng.toLowerCase() === 'cimode') return true; - const loadNotPending = (l, n) => { - const loadState = i18n.services.backendConnector.state[`${l}|${n}`]; - return loadState === -1 || loadState === 2; - }; - if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18n.services.backendConnector.backend && i18n.isLanguageChangingTo && !loadNotPending(i18n.isLanguageChangingTo, ns)) return false; - if (i18n.hasResourceBundle(lng, ns)) return true; - if (!i18n.services.backendConnector.backend || i18n.options.resources && !i18n.options.partialBundledLanguages) return true; - if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true; - return false; - } - function hasLoadedNamespace(ns, i18n) { - let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; - if (!i18n.languages || !i18n.languages.length) { - warnOnce('i18n.languages were undefined or empty', i18n.languages); - return true; - } - const isNewerI18next = i18n.options.ignoreJSONStructure !== undefined; - if (!isNewerI18next) { - return oldI18nextHasLoadedNamespace(ns, i18n, options); - } - return i18n.hasLoadedNamespace(ns, { - lng: options.lng, - precheck: (i18nInstance, loadNotPending) => { - if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18nInstance.services.backendConnector.backend && i18nInstance.isLanguageChangingTo && !loadNotPending(i18nInstance.isLanguageChangingTo, ns)) return false; - } - }); - } - function getDisplayName(Component) { - return Component.displayName || Component.name || (typeof Component === 'string' && Component.length > 0 ? Component : 'Unknown'); - } + const matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g; + const htmlEntities = { + '&': '&', + '&': '&', + '<': '<', + '<': '<', + '>': '>', + '>': '>', + ''': "'", + ''': "'", + '"': '"', + '"': '"', + ' ': ' ', + ' ': ' ', + '©': '©', + '©': '©', + '®': '®', + '®': '®', + '…': '…', + '…': '…', + '/': '/', + '/': '/' + }; + const unescapeHtmlEntity = m => htmlEntities[m]; + const unescape = text => text.replace(matchHtmlEntity, unescapeHtmlEntity); - const matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g; - const htmlEntities = { - '&': '&', - '&': '&', - '<': '<', - '<': '<', - '>': '>', - '>': '>', - ''': "'", - ''': "'", - '"': '"', - '"': '"', - ' ': ' ', - ' ': ' ', - '©': '©', - '©': '©', - '®': '®', - '®': '®', - '…': '…', - '…': '…', - '/': '/', - '/': '/' - }; - const unescapeHtmlEntity = m => htmlEntities[m]; - const unescape = text => text.replace(matchHtmlEntity, unescapeHtmlEntity); + let defaultOptions = { + bindI18n: 'languageChanged', + bindI18nStore: '', + transEmptyNodeValue: '', + transSupportBasicHtmlNodes: true, + transWrapTextNodes: '', + transKeepBasicHtmlNodesFor: ['br', 'strong', 'i', 'p'], + useSuspense: true, + unescape + }; + function setDefaults() { + let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + defaultOptions = { + ...defaultOptions, + ...options + }; + } + function getDefaults() { + return defaultOptions; + } - let defaultOptions = { - bindI18n: 'languageChanged', - bindI18nStore: '', - transEmptyNodeValue: '', - transSupportBasicHtmlNodes: true, - transWrapTextNodes: '', - transKeepBasicHtmlNodesFor: ['br', 'strong', 'i', 'p'], - useSuspense: true, - unescape - }; - function setDefaults() { - let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - defaultOptions = { - ...defaultOptions, - ...options - }; - } - function getDefaults() { - return defaultOptions; - } + let i18nInstance; + function setI18n(instance) { + i18nInstance = instance; + } + function getI18n() { + return i18nInstance; + } - let i18nInstance; - function setI18n(instance) { - i18nInstance = instance; - } - function getI18n() { - return i18nInstance; - } + function hasChildren(node, checkLength) { + if (!node) return false; + const base = node.props ? node.props.children : node.children; + if (checkLength) return base.length > 0; + return !!base; + } + function getChildren(node) { + if (!node) return []; + const children = node.props ? node.props.children : node.children; + return node.props && node.props.i18nIsDynamicList ? getAsArray(children) : children; + } + function hasValidReactChildren(children) { + if (Object.prototype.toString.call(children) !== '[object Array]') return false; + return children.every(child => react.isValidElement(child)); + } + function getAsArray(data) { + return Array.isArray(data) ? data : [data]; + } + function mergeProps(source, target) { + const newTarget = { + ...target + }; + newTarget.props = Object.assign(source.props, target.props); + return newTarget; + } + function nodesToString(children, i18nOptions) { + if (!children) return ''; + let stringNode = ''; + const childrenArray = getAsArray(children); + const keepArray = i18nOptions.transSupportBasicHtmlNodes && i18nOptions.transKeepBasicHtmlNodesFor ? i18nOptions.transKeepBasicHtmlNodesFor : []; + childrenArray.forEach((child, childIndex) => { + if (typeof child === 'string') { + stringNode += `${child}`; + } else if (react.isValidElement(child)) { + const childPropsCount = Object.keys(child.props).length; + const shouldKeepChild = keepArray.indexOf(child.type) > -1; + const childChildren = child.props.children; + if (!childChildren && shouldKeepChild && childPropsCount === 0) { + stringNode += `<${child.type}/>`; + } else if (!childChildren && (!shouldKeepChild || childPropsCount !== 0)) { + stringNode += `<${childIndex}>`; + } else if (child.props.i18nIsDynamicList) { + stringNode += `<${childIndex}>`; + } else if (shouldKeepChild && childPropsCount === 1 && typeof childChildren === 'string') { + stringNode += `<${child.type}>${childChildren}`; + } else { + const content = nodesToString(childChildren, i18nOptions); + stringNode += `<${childIndex}>${content}`; + } + } else if (child === null) { + warn(`Trans: the passed in value is invalid - seems you passed in a null child.`); + } else if (typeof child === 'object') { + const { + format, + ...clone + } = child; + const keys = Object.keys(clone); + if (keys.length === 1) { + const value = format ? `${keys[0]}, ${format}` : keys[0]; + stringNode += `{{${value}}}`; + } else { + 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); + } + }); + return stringNode; + } + function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, shouldUnescape) { + if (targetString === '') return []; + const keepArray = i18nOptions.transKeepBasicHtmlNodesFor || []; + const emptyChildrenButNeedsHandling = targetString && new RegExp(keepArray.map(keep => `<${keep}`).join('|')).test(targetString); + if (!children && !emptyChildrenButNeedsHandling && !shouldUnescape) return [targetString]; + const data = {}; + function getData(childs) { + const childrenArray = getAsArray(childs); + childrenArray.forEach(child => { + if (typeof child === 'string') return; + if (hasChildren(child)) getData(getChildren(child));else if (typeof child === 'object' && !react.isValidElement(child)) Object.assign(data, child); + }); + } + getData(children); + const ast = c.parse(`<0>${targetString}`); + const opts = { + ...data, + ...combinedTOpts + }; + function renderInner(child, node, rootReactNode) { + const childs = getChildren(child); + const mappedChildren = mapAST(childs, node.children, rootReactNode); + return hasValidReactChildren(childs) && mappedChildren.length === 0 || child.props && child.props.i18nIsDynamicList ? childs : mappedChildren; + } + function pushTranslatedJSX(child, inner, mem, i, isVoid) { + if (child.dummy) { + child.children = inner; + mem.push(react.cloneElement(child, { + key: i + }, isVoid ? undefined : inner)); + } else { + mem.push(...react.Children.map([child], c => { + const props = { + ...c.props + }; + delete props.i18nIsDynamicList; + return react.createElement(c.type, { + ...props, + key: i, + ref: c.ref + }, isVoid ? null : inner); + })); + } + } + function mapAST(reactNode, astNode, rootReactNode) { + const reactNodes = getAsArray(reactNode); + const astNodes = getAsArray(astNode); + return astNodes.reduce((mem, node, i) => { + const translationContent = node.children && node.children[0] && node.children[0].content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language); + if (node.type === 'tag') { + let tmp = reactNodes[parseInt(node.name, 10)]; + if (rootReactNode.length === 1 && !tmp) tmp = rootReactNode[0][node.name]; + if (!tmp) tmp = {}; + const child = Object.keys(node.attrs).length !== 0 ? mergeProps({ + props: node.attrs + }, tmp) : tmp; + const isElement = react.isValidElement(child); + const isValidTranslationWithChildren = isElement && hasChildren(node, true) && !node.voidElement; + const isEmptyTransWithHTML = emptyChildrenButNeedsHandling && typeof child === 'object' && child.dummy && !isElement; + const isKnownComponent = typeof children === 'object' && children !== null && Object.hasOwnProperty.call(children, node.name); + if (typeof child === 'string') { + const value = i18n.services.interpolator.interpolate(child, opts, i18n.language); + mem.push(value); + } else if (hasChildren(child) || isValidTranslationWithChildren) { + const inner = renderInner(child, node, rootReactNode); + pushTranslatedJSX(child, inner, mem, i); + } else if (isEmptyTransWithHTML) { + const inner = mapAST(reactNodes, node.children, rootReactNode); + pushTranslatedJSX(child, inner, mem, i); + } else if (Number.isNaN(parseFloat(node.name))) { + if (isKnownComponent) { + const inner = renderInner(child, node, rootReactNode); + pushTranslatedJSX(child, inner, mem, i, node.voidElement); + } else if (i18nOptions.transSupportBasicHtmlNodes && keepArray.indexOf(node.name) > -1) { + if (node.voidElement) { + mem.push(react.createElement(node.name, { + key: `${node.name}-${i}` + })); + } else { + const inner = mapAST(reactNodes, node.children, rootReactNode); + mem.push(react.createElement(node.name, { + key: `${node.name}-${i}` + }, inner)); + } + } else if (node.voidElement) { + mem.push(`<${node.name} />`); + } else { + const inner = mapAST(reactNodes, node.children, rootReactNode); + mem.push(`<${node.name}>${inner}`); + } + } else if (typeof child === 'object' && !isElement) { + const content = node.children[0] ? translationContent : null; + if (content) mem.push(content); + } else { + pushTranslatedJSX(child, translationContent, mem, i, node.children.length !== 1 || !translationContent); + } + } else if (node.type === 'text') { + const wrapTextNodes = i18nOptions.transWrapTextNodes; + const content = shouldUnescape ? i18nOptions.unescape(i18n.services.interpolator.interpolate(node.content, opts, i18n.language)) : i18n.services.interpolator.interpolate(node.content, opts, i18n.language); + if (wrapTextNodes) { + mem.push(react.createElement(wrapTextNodes, { + key: `${node.name}-${i}` + }, content)); + } else { + mem.push(content); + } + } + return mem; + }, []); + } + const result = mapAST([{ + dummy: true, + children: children || [] + }], ast, getAsArray(children || [])); + return getChildren(result[0]); + } + function Trans$1(_ref) { + let { + children, + count, + parent, + i18nKey, + context, + tOptions = {}, + values, + defaults, + components, + ns, + i18n: i18nFromProps, + t: tFromProps, + shouldUnescape, + ...additionalProps + } = _ref; + const i18n = i18nFromProps || getI18n(); + if (!i18n) { + warnOnce('You will need to pass in an i18next instance by using i18nextReactModule'); + return children; + } + const t = tFromProps || i18n.t.bind(i18n) || (k => k); + if (context) tOptions.context = context; + const reactI18nextOptions = { + ...getDefaults(), + ...(i18n.options && i18n.options.react) + }; + let namespaces = ns || t.ns || i18n.options && i18n.options.defaultNS; + namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation']; + const nodeAsString = nodesToString(children, reactI18nextOptions); + const defaultValue = defaults || nodeAsString || reactI18nextOptions.transEmptyNodeValue || i18nKey; + const { + hashTransKey + } = reactI18nextOptions; + const key = i18nKey || (hashTransKey ? hashTransKey(nodeAsString || defaultValue) : nodeAsString || defaultValue); + if (i18n.options && i18n.options.interpolation && i18n.options.interpolation.defaultVariables) { + values = values && Object.keys(values).length > 0 ? { + ...values, + ...i18n.options.interpolation.defaultVariables + } : { + ...i18n.options.interpolation.defaultVariables + }; + } + const interpolationOverride = values ? tOptions.interpolation : { + interpolation: { + ...tOptions.interpolation, + prefix: '#$?', + suffix: '?$#' + } + }; + const combinedTOpts = { + ...tOptions, + count, + ...values, + ...interpolationOverride, + defaultValue, + ns: namespaces + }; + const translation = key ? t(key, combinedTOpts) : defaultValue; + if (components) { + Object.keys(components).forEach(c => { + const comp = components[c]; + if (typeof comp.type === 'function' || !comp.props || !comp.props.children || translation.indexOf(`${c}/>`) < 0 && translation.indexOf(`${c} />`) < 0) return; + function Componentized() { + return react.createElement(react.Fragment, null, comp); + } + components[c] = react.createElement(Componentized); + }); + } + const content = renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape); + const useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent; + return useAsParent ? react.createElement(useAsParent, additionalProps, content) : content; + } - function hasChildren(node, checkLength) { - if (!node) return false; - const base = node.props ? node.props.children : node.children; - if (checkLength) return base.length > 0; - return !!base; - } - function getChildren(node) { - if (!node) return []; - const children = node.props ? node.props.children : node.children; - return node.props && node.props.i18nIsDynamicList ? getAsArray(children) : children; - } - function hasValidReactChildren(children) { - if (Object.prototype.toString.call(children) !== '[object Array]') return false; - return children.every(child => React.isValidElement(child)); - } - function getAsArray(data) { - return Array.isArray(data) ? data : [data]; - } - function mergeProps(source, target) { - const newTarget = { - ...target - }; - newTarget.props = Object.assign(source.props, target.props); - return newTarget; - } - function nodesToString(children, i18nOptions) { - if (!children) return ''; - let stringNode = ''; - const childrenArray = getAsArray(children); - const keepArray = i18nOptions.transSupportBasicHtmlNodes && i18nOptions.transKeepBasicHtmlNodesFor ? i18nOptions.transKeepBasicHtmlNodesFor : []; - childrenArray.forEach((child, childIndex) => { - if (typeof child === 'string') { - stringNode += `${child}`; - } else if (React.isValidElement(child)) { - const childPropsCount = Object.keys(child.props).length; - const shouldKeepChild = keepArray.indexOf(child.type) > -1; - const childChildren = child.props.children; - if (!childChildren && shouldKeepChild && childPropsCount === 0) { - stringNode += `<${child.type}/>`; - } else if (!childChildren && (!shouldKeepChild || childPropsCount !== 0)) { - stringNode += `<${childIndex}>`; - } else if (child.props.i18nIsDynamicList) { - stringNode += `<${childIndex}>`; - } else if (shouldKeepChild && childPropsCount === 1 && typeof childChildren === 'string') { - stringNode += `<${child.type}>${childChildren}`; - } else { - const content = nodesToString(childChildren, i18nOptions); - stringNode += `<${childIndex}>${content}`; - } - } else if (child === null) { - warn(`Trans: the passed in value is invalid - seems you passed in a null child.`); - } else if (typeof child === 'object') { - const { - format, - ...clone - } = child; - const keys = Object.keys(clone); - if (keys.length === 1) { - const value = format ? `${keys[0]}, ${format}` : keys[0]; - stringNode += `{{${value}}}`; - } else { - 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); - } - }); - return stringNode; - } - function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, shouldUnescape) { - if (targetString === '') return []; - const keepArray = i18nOptions.transKeepBasicHtmlNodesFor || []; - const emptyChildrenButNeedsHandling = targetString && new RegExp(keepArray.map(keep => `<${keep}`).join('|')).test(targetString); - if (!children && !emptyChildrenButNeedsHandling && !shouldUnescape) return [targetString]; - const data = {}; - function getData(childs) { - const childrenArray = getAsArray(childs); - childrenArray.forEach(child => { - if (typeof child === 'string') return; - if (hasChildren(child)) getData(getChildren(child));else if (typeof child === 'object' && !React.isValidElement(child)) Object.assign(data, child); - }); - } - getData(children); - const ast = c.parse(`<0>${targetString}`); - const opts = { - ...data, - ...combinedTOpts - }; - function renderInner(child, node, rootReactNode) { - const childs = getChildren(child); - const mappedChildren = mapAST(childs, node.children, rootReactNode); - return hasValidReactChildren(childs) && mappedChildren.length === 0 || child.props && child.props.i18nIsDynamicList ? childs : mappedChildren; - } - function pushTranslatedJSX(child, inner, mem, i, isVoid) { - if (child.dummy) { - child.children = inner; - mem.push(React.cloneElement(child, { - key: i - }, isVoid ? undefined : inner)); - } else { - mem.push(...React.Children.map([child], c => { - const props = { - ...c.props - }; - delete props.i18nIsDynamicList; - return React.createElement(c.type, _extends({}, props, { - key: i, - ref: c.ref - }, isVoid ? {} : { - children: inner - })); - })); - } - } - function mapAST(reactNode, astNode, rootReactNode) { - const reactNodes = getAsArray(reactNode); - const astNodes = getAsArray(astNode); - return astNodes.reduce((mem, node, i) => { - const translationContent = node.children && node.children[0] && node.children[0].content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language); - if (node.type === 'tag') { - let tmp = reactNodes[parseInt(node.name, 10)]; - if (rootReactNode.length === 1 && !tmp) tmp = rootReactNode[0][node.name]; - if (!tmp) tmp = {}; - const child = Object.keys(node.attrs).length !== 0 ? mergeProps({ - props: node.attrs - }, tmp) : tmp; - const isElement = React.isValidElement(child); - const isValidTranslationWithChildren = isElement && hasChildren(node, true) && !node.voidElement; - const isEmptyTransWithHTML = emptyChildrenButNeedsHandling && typeof child === 'object' && child.dummy && !isElement; - const isKnownComponent = typeof children === 'object' && children !== null && Object.hasOwnProperty.call(children, node.name); - if (typeof child === 'string') { - const value = i18n.services.interpolator.interpolate(child, opts, i18n.language); - mem.push(value); - } else if (hasChildren(child) || isValidTranslationWithChildren) { - const inner = renderInner(child, node, rootReactNode); - pushTranslatedJSX(child, inner, mem, i); - } else if (isEmptyTransWithHTML) { - const inner = mapAST(reactNodes, node.children, rootReactNode); - pushTranslatedJSX(child, inner, mem, i); - } else if (Number.isNaN(parseFloat(node.name))) { - if (isKnownComponent) { - const inner = renderInner(child, node, rootReactNode); - pushTranslatedJSX(child, inner, mem, i, node.voidElement); - } else if (i18nOptions.transSupportBasicHtmlNodes && keepArray.indexOf(node.name) > -1) { - if (node.voidElement) { - mem.push(React.createElement(node.name, { - key: `${node.name}-${i}` - })); - } else { - const inner = mapAST(reactNodes, node.children, rootReactNode); - mem.push(React.createElement(node.name, { - key: `${node.name}-${i}` - }, inner)); - } - } else if (node.voidElement) { - mem.push(`<${node.name} />`); - } else { - const inner = mapAST(reactNodes, node.children, rootReactNode); - mem.push(`<${node.name}>${inner}`); - } - } else if (typeof child === 'object' && !isElement) { - const content = node.children[0] ? translationContent : null; - if (content) mem.push(content); - } else { - pushTranslatedJSX(child, translationContent, mem, i, node.children.length !== 1 || !translationContent); - } - } else if (node.type === 'text') { - const wrapTextNodes = i18nOptions.transWrapTextNodes; - const content = shouldUnescape ? i18nOptions.unescape(i18n.services.interpolator.interpolate(node.content, opts, i18n.language)) : i18n.services.interpolator.interpolate(node.content, opts, i18n.language); - if (wrapTextNodes) { - mem.push(React.createElement(wrapTextNodes, { - key: `${node.name}-${i}` - }, content)); - } else { - mem.push(content); - } - } - return mem; - }, []); - } - const result = mapAST([{ - dummy: true, - children: children || [] - }], ast, getAsArray(children || [])); - return getChildren(result[0]); - } - function Trans$1(_ref) { - let { - children, - count, - parent, - i18nKey, - context, - tOptions = {}, - values, - defaults, - components, - ns, - i18n: i18nFromProps, - t: tFromProps, - shouldUnescape, - ...additionalProps - } = _ref; - const i18n = i18nFromProps || getI18n(); - if (!i18n) { - warnOnce('You will need to pass in an i18next instance by using i18nextReactModule'); - return children; - } - const t = tFromProps || i18n.t.bind(i18n) || (k => k); - if (context) tOptions.context = context; - const reactI18nextOptions = { - ...getDefaults(), - ...(i18n.options && i18n.options.react) - }; - let namespaces = ns || t.ns || i18n.options && i18n.options.defaultNS; - namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation']; - const nodeAsString = nodesToString(children, reactI18nextOptions); - const defaultValue = defaults || nodeAsString || reactI18nextOptions.transEmptyNodeValue || i18nKey; - const { - hashTransKey - } = reactI18nextOptions; - const key = i18nKey || (hashTransKey ? hashTransKey(nodeAsString || defaultValue) : nodeAsString || defaultValue); - if (i18n.options && i18n.options.interpolation && i18n.options.interpolation.defaultVariables) { - values = values && Object.keys(values).length > 0 ? { - ...values, - ...i18n.options.interpolation.defaultVariables - } : { - ...i18n.options.interpolation.defaultVariables - }; - } - const interpolationOverride = values ? tOptions.interpolation : { - interpolation: { - ...tOptions.interpolation, - prefix: '#$?', - suffix: '?$#' - } - }; - const combinedTOpts = { - ...tOptions, - count, - ...values, - ...interpolationOverride, - defaultValue, - ns: namespaces - }; - const translation = key ? t(key, combinedTOpts) : defaultValue; - if (components) { - Object.keys(components).forEach(c => { - const comp = components[c]; - if (typeof comp.type === 'function' || !comp.props || !comp.props.children || translation.indexOf(`${c}/>`) < 0 && translation.indexOf(`${c} />`) < 0) return; - function Componentized() { - return React.createElement(React.Fragment, null, comp); - } - components[c] = React.createElement(Componentized, null); - }); - } - const content = renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape); - const useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent; - return useAsParent ? React.createElement(useAsParent, additionalProps, content) : content; - } + const initReactI18next = { + type: '3rdParty', + init(instance) { + setDefaults(instance.options.react); + setI18n(instance); + } + }; - const initReactI18next = { - type: '3rdParty', - init(instance) { - setDefaults(instance.options.react); - setI18n(instance); - } - }; + const I18nContext = react.createContext(); + class ReportNamespaces { + constructor() { + this.usedNamespaces = {}; + } + addUsedNamespaces(namespaces) { + namespaces.forEach(ns => { + if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true; + }); + } + getUsedNamespaces() { + return Object.keys(this.usedNamespaces); + } + } + function composeInitialProps(ForComponent) { + return ctx => new Promise(resolve => { + const i18nInitialProps = getInitialProps(); + if (ForComponent.getInitialProps) { + ForComponent.getInitialProps(ctx).then(componentsInitialProps => { + resolve({ + ...componentsInitialProps, + ...i18nInitialProps + }); + }); + } else { + resolve(i18nInitialProps); + } + }); + } + function getInitialProps() { + const i18n = getI18n(); + const namespaces = i18n.reportNamespaces ? i18n.reportNamespaces.getUsedNamespaces() : []; + const ret = {}; + const initialI18nStore = {}; + i18n.languages.forEach(l => { + initialI18nStore[l] = {}; + namespaces.forEach(ns => { + initialI18nStore[l][ns] = i18n.getResourceBundle(l, ns) || {}; + }); + }); + ret.initialI18nStore = initialI18nStore; + ret.initialLanguage = i18n.language; + return ret; + } - const I18nContext = React.createContext(); - class ReportNamespaces { - constructor() { - this.usedNamespaces = {}; - } - addUsedNamespaces(namespaces) { - namespaces.forEach(ns => { - if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true; - }); - } - getUsedNamespaces() { - return Object.keys(this.usedNamespaces); - } - } - function composeInitialProps(ForComponent) { - return ctx => new Promise(resolve => { - const i18nInitialProps = getInitialProps(); - if (ForComponent.getInitialProps) { - ForComponent.getInitialProps(ctx).then(componentsInitialProps => { - resolve({ - ...componentsInitialProps, - ...i18nInitialProps - }); - }); - } else { - resolve(i18nInitialProps); - } - }); - } - function getInitialProps() { - const i18n = getI18n(); - const namespaces = i18n.reportNamespaces ? i18n.reportNamespaces.getUsedNamespaces() : []; - const ret = {}; - const initialI18nStore = {}; - i18n.languages.forEach(l => { - initialI18nStore[l] = {}; - namespaces.forEach(ns => { - initialI18nStore[l][ns] = i18n.getResourceBundle(l, ns) || {}; - }); - }); - ret.initialI18nStore = initialI18nStore; - ret.initialLanguage = i18n.language; - return ret; - } + function Trans(_ref) { + let { + children, + count, + parent, + i18nKey, + context, + tOptions = {}, + values, + defaults, + components, + ns, + i18n: i18nFromProps, + t: tFromProps, + shouldUnescape, + ...additionalProps + } = _ref; + const { + i18n: i18nFromContext, + defaultNS: defaultNSFromContext + } = react.useContext(I18nContext) || {}; + const i18n = i18nFromProps || i18nFromContext || getI18n(); + const t = tFromProps || i18n && i18n.t.bind(i18n); + return Trans$1({ + children, + count, + parent, + i18nKey, + context, + tOptions, + values, + defaults, + components, + ns: ns || t && t.ns || defaultNSFromContext || i18n && i18n.options && i18n.options.defaultNS, + i18n, + t: tFromProps, + shouldUnescape, + ...additionalProps + }); + } - function Trans(_ref) { - let { - children, - count, - parent, - i18nKey, - context, - tOptions = {}, - values, - defaults, - components, - ns, - i18n: i18nFromProps, - t: tFromProps, - shouldUnescape, - ...additionalProps - } = _ref; - const { - i18n: i18nFromContext, - defaultNS: defaultNSFromContext - } = React.useContext(I18nContext) || {}; - const i18n = i18nFromProps || i18nFromContext || getI18n(); - const t = tFromProps || i18n && i18n.t.bind(i18n); - return Trans$1({ - children, - count, - parent, - i18nKey, - context, - tOptions, - values, - defaults, - components, - ns: ns || t && t.ns || defaultNSFromContext || i18n && i18n.options && i18n.options.defaultNS, - i18n, - t: tFromProps, - shouldUnescape, - ...additionalProps - }); - } + const usePrevious = (value, ignore) => { + const ref = react.useRef(); + react.useEffect(() => { + ref.current = ignore ? ref.current : value; + }, [value, ignore]); + return ref.current; + }; + function useTranslation(ns) { + let props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + const { + i18n: i18nFromProps + } = props; + const { + i18n: i18nFromContext, + defaultNS: defaultNSFromContext + } = react.useContext(I18nContext) || {}; + const i18n = i18nFromProps || i18nFromContext || getI18n(); + if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces(); + if (!i18n) { + warnOnce('You will need to pass in an i18next instance by using initReactI18next'); + const notReadyT = (k, optsOrDefaultValue) => { + if (typeof optsOrDefaultValue === 'string') return optsOrDefaultValue; + if (optsOrDefaultValue && typeof optsOrDefaultValue === 'object' && typeof optsOrDefaultValue.defaultValue === 'string') return optsOrDefaultValue.defaultValue; + return Array.isArray(k) ? k[k.length - 1] : k; + }; + const retNotReady = [notReadyT, {}, false]; + retNotReady.t = notReadyT; + retNotReady.i18n = {}; + retNotReady.ready = false; + return retNotReady; + } + if (i18n.options.react && i18n.options.react.wait !== undefined) warnOnce('It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.'); + const i18nOptions = { + ...getDefaults(), + ...i18n.options.react, + ...props + }; + const { + useSuspense, + keyPrefix + } = i18nOptions; + let namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS; + namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation']; + if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces); + const ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(n => hasLoadedNamespace(n, i18n, i18nOptions)); + function getT() { + return i18n.getFixedT(props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix); + } + const [t, setT] = react.useState(getT); + let joinedNS = namespaces.join(); + if (props.lng) joinedNS = `${props.lng}${joinedNS}`; + const previousJoinedNS = usePrevious(joinedNS); + const isMounted = react.useRef(true); + react.useEffect(() => { + const { + bindI18n, + bindI18nStore + } = i18nOptions; + isMounted.current = true; + if (!ready && !useSuspense) { + if (props.lng) { + loadLanguages(i18n, props.lng, namespaces, () => { + if (isMounted.current) setT(getT); + }); + } else { + loadNamespaces(i18n, namespaces, () => { + if (isMounted.current) setT(getT); + }); + } + } + if (ready && previousJoinedNS && previousJoinedNS !== joinedNS && isMounted.current) { + setT(getT); + } + function boundReset() { + if (isMounted.current) setT(getT); + } + if (bindI18n && i18n) i18n.on(bindI18n, boundReset); + if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset); + return () => { + isMounted.current = false; + if (bindI18n && i18n) bindI18n.split(' ').forEach(e => i18n.off(e, boundReset)); + if (bindI18nStore && i18n) bindI18nStore.split(' ').forEach(e => i18n.store.off(e, boundReset)); + }; + }, [i18n, joinedNS]); + const isInitial = react.useRef(true); + react.useEffect(() => { + if (isMounted.current && !isInitial.current) { + setT(getT); + } + isInitial.current = false; + }, [i18n, keyPrefix]); + const ret = [t, i18n, ready]; + ret.t = t; + ret.i18n = i18n; + ret.ready = ready; + if (ready) return ret; + if (!ready && !useSuspense) return ret; + throw new Promise(resolve => { + if (props.lng) { + loadLanguages(i18n, props.lng, namespaces, () => resolve()); + } else { + loadNamespaces(i18n, namespaces, () => resolve()); + } + }); + } - const usePrevious = (value, ignore) => { - const ref = React.useRef(); - React.useEffect(() => { - ref.current = ignore ? ref.current : value; - }, [value, ignore]); - return ref.current; - }; - function useTranslation(ns) { - let props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - const { - i18n: i18nFromProps - } = props; - const { - i18n: i18nFromContext, - defaultNS: defaultNSFromContext - } = React.useContext(I18nContext) || {}; - const i18n = i18nFromProps || i18nFromContext || getI18n(); - if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces(); - if (!i18n) { - warnOnce('You will need to pass in an i18next instance by using initReactI18next'); - const notReadyT = (k, optsOrDefaultValue) => { - if (typeof optsOrDefaultValue === 'string') return optsOrDefaultValue; - if (optsOrDefaultValue && typeof optsOrDefaultValue === 'object' && typeof optsOrDefaultValue.defaultValue === 'string') return optsOrDefaultValue.defaultValue; - return Array.isArray(k) ? k[k.length - 1] : k; - }; - const retNotReady = [notReadyT, {}, false]; - retNotReady.t = notReadyT; - retNotReady.i18n = {}; - retNotReady.ready = false; - return retNotReady; - } - if (i18n.options.react && i18n.options.react.wait !== undefined) warnOnce('It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.'); - const i18nOptions = { - ...getDefaults(), - ...i18n.options.react, - ...props - }; - const { - useSuspense, - keyPrefix - } = i18nOptions; - let namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS; - namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation']; - if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces); - const ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(n => hasLoadedNamespace(n, i18n, i18nOptions)); - function getT() { - return i18n.getFixedT(props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix); - } - const [t, setT] = React.useState(getT); - let joinedNS = namespaces.join(); - if (props.lng) joinedNS = `${props.lng}${joinedNS}`; - const previousJoinedNS = usePrevious(joinedNS); - const isMounted = React.useRef(true); - React.useEffect(() => { - const { - bindI18n, - bindI18nStore - } = i18nOptions; - isMounted.current = true; - if (!ready && !useSuspense) { - if (props.lng) { - loadLanguages(i18n, props.lng, namespaces, () => { - if (isMounted.current) setT(getT); - }); - } else { - loadNamespaces(i18n, namespaces, () => { - if (isMounted.current) setT(getT); - }); - } - } - if (ready && previousJoinedNS && previousJoinedNS !== joinedNS && isMounted.current) { - setT(getT); - } - function boundReset() { - if (isMounted.current) setT(getT); - } - if (bindI18n && i18n) i18n.on(bindI18n, boundReset); - if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset); - return () => { - isMounted.current = false; - if (bindI18n && i18n) bindI18n.split(' ').forEach(e => i18n.off(e, boundReset)); - if (bindI18nStore && i18n) bindI18nStore.split(' ').forEach(e => i18n.store.off(e, boundReset)); - }; - }, [i18n, joinedNS]); - const isInitial = React.useRef(true); - React.useEffect(() => { - if (isMounted.current && !isInitial.current) { - setT(getT); - } - isInitial.current = false; - }, [i18n, keyPrefix]); - const ret = [t, i18n, ready]; - ret.t = t; - ret.i18n = i18n; - ret.ready = ready; - if (ready) return ret; - if (!ready && !useSuspense) return ret; - throw new Promise(resolve => { - if (props.lng) { - loadLanguages(i18n, props.lng, namespaces, () => resolve()); - } else { - loadNamespaces(i18n, namespaces, () => resolve()); - } - }); - } + function withTranslation(ns) { + let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + return function Extend(WrappedComponent) { + function I18nextWithTranslation(_ref) { + let { + forwardedRef, + ...rest + } = _ref; + const [t, i18n, ready] = useTranslation(ns, { + ...rest, + keyPrefix: options.keyPrefix + }); + const passDownProps = { + ...rest, + t, + i18n, + tReady: ready + }; + if (options.withRef && forwardedRef) { + passDownProps.ref = forwardedRef; + } else if (!options.withRef && forwardedRef) { + passDownProps.forwardedRef = forwardedRef; + } + return react.createElement(WrappedComponent, passDownProps); + } + I18nextWithTranslation.displayName = `withI18nextTranslation(${getDisplayName(WrappedComponent)})`; + I18nextWithTranslation.WrappedComponent = WrappedComponent; + const forwardRef = (props, ref) => react.createElement(I18nextWithTranslation, Object.assign({}, props, { + forwardedRef: ref + })); + return options.withRef ? react.forwardRef(forwardRef) : I18nextWithTranslation; + }; + } - function withTranslation(ns) { - let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - return function Extend(WrappedComponent) { - function I18nextWithTranslation(_ref) { - let { - forwardedRef, - ...rest - } = _ref; - const [t, i18n, ready] = useTranslation(ns, { - ...rest, - keyPrefix: options.keyPrefix - }); - const passDownProps = { - ...rest, - t, - i18n, - tReady: ready - }; - if (options.withRef && forwardedRef) { - passDownProps.ref = forwardedRef; - } else if (!options.withRef && forwardedRef) { - passDownProps.forwardedRef = forwardedRef; - } - return React.createElement(WrappedComponent, passDownProps); - } - I18nextWithTranslation.displayName = `withI18nextTranslation(${getDisplayName(WrappedComponent)})`; - I18nextWithTranslation.WrappedComponent = WrappedComponent; - const forwardRef = (props, ref) => React.createElement(I18nextWithTranslation, Object.assign({}, props, { - forwardedRef: ref - })); - return options.withRef ? React.forwardRef(forwardRef) : I18nextWithTranslation; - }; - } + function Translation(props) { + const { + ns, + children, + ...options + } = props; + const [t, i18n, ready] = useTranslation(ns, options); + return children(t, { + i18n, + lng: i18n.language + }, ready); + } - function Translation(props) { - const { - ns, - children, - ...options - } = props; - const [t, i18n, ready] = useTranslation(ns, options); - return children(t, { - i18n, - lng: i18n.language - }, ready); - } + function I18nextProvider(_ref) { + let { + i18n, + defaultNS, + children + } = _ref; + const value = react.useMemo(() => ({ + i18n, + defaultNS + }), [i18n, defaultNS]); + return react.createElement(I18nContext.Provider, { + value + }, children); + } - function I18nextProvider(_ref) { - let { - i18n, - defaultNS, - children - } = _ref; - const value = React.useMemo(() => ({ - i18n, - defaultNS - }), [i18n, defaultNS]); - return React.createElement(I18nContext.Provider, { - value - }, children); - } + function useSSR(initialI18nStore, initialLanguage) { + let props = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + const { + i18n: i18nFromProps + } = props; + const { + i18n: i18nFromContext + } = react.useContext(I18nContext) || {}; + const i18n = i18nFromProps || i18nFromContext || getI18n(); + if (i18n.options && i18n.options.isClone) return; + if (initialI18nStore && !i18n.initializedStoreOnce) { + i18n.services.resourceStore.data = initialI18nStore; + i18n.options.ns = Object.values(initialI18nStore).reduce((mem, lngResources) => { + Object.keys(lngResources).forEach(ns => { + if (mem.indexOf(ns) < 0) mem.push(ns); + }); + return mem; + }, i18n.options.ns); + i18n.initializedStoreOnce = true; + i18n.isInitialized = true; + } + if (initialLanguage && !i18n.initializedLanguageOnce) { + i18n.changeLanguage(initialLanguage); + i18n.initializedLanguageOnce = true; + } + } - function useSSR(initialI18nStore, initialLanguage) { - let props = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; - const { - i18n: i18nFromProps - } = props; - const { - i18n: i18nFromContext - } = React.useContext(I18nContext) || {}; - const i18n = i18nFromProps || i18nFromContext || getI18n(); - if (i18n.options && i18n.options.isClone) return; - if (initialI18nStore && !i18n.initializedStoreOnce) { - i18n.services.resourceStore.data = initialI18nStore; - i18n.options.ns = Object.values(initialI18nStore).reduce((mem, lngResources) => { - Object.keys(lngResources).forEach(ns => { - if (mem.indexOf(ns) < 0) mem.push(ns); - }); - return mem; - }, i18n.options.ns); - i18n.initializedStoreOnce = true; - i18n.isInitialized = true; - } - if (initialLanguage && !i18n.initializedLanguageOnce) { - i18n.changeLanguage(initialLanguage); - i18n.initializedLanguageOnce = true; - } - } + function withSSR() { + return function Extend(WrappedComponent) { + function I18nextWithSSR(_ref) { + let { + initialI18nStore, + initialLanguage, + ...rest + } = _ref; + useSSR(initialI18nStore, initialLanguage); + return react.createElement(WrappedComponent, { + ...rest + }); + } + I18nextWithSSR.getInitialProps = composeInitialProps(WrappedComponent); + I18nextWithSSR.displayName = `withI18nextSSR(${getDisplayName(WrappedComponent)})`; + I18nextWithSSR.WrappedComponent = WrappedComponent; + return I18nextWithSSR; + }; + } - function withSSR() { - return function Extend(WrappedComponent) { - function I18nextWithSSR(_ref) { - let { - initialI18nStore, - initialLanguage, - ...rest - } = _ref; - useSSR(initialI18nStore, initialLanguage); - return React.createElement(WrappedComponent, { - ...rest - }); - } - I18nextWithSSR.getInitialProps = composeInitialProps(WrappedComponent); - I18nextWithSSR.displayName = `withI18nextSSR(${getDisplayName(WrappedComponent)})`; - I18nextWithSSR.WrappedComponent = WrappedComponent; - return I18nextWithSSR; - }; - } + const date = () => ''; + const time = () => ''; + const number = () => ''; + const select = () => ''; + const plural = () => ''; + const selectOrdinal = () => ''; - const date = () => ''; - const time = () => ''; - const number = () => ''; - const select = () => ''; - const plural = () => ''; - const selectOrdinal = () => ''; - - exports.I18nContext = I18nContext; - exports.I18nextProvider = I18nextProvider; - exports.Trans = Trans; - exports.TransWithoutContext = Trans$1; - exports.Translation = Translation; - exports.composeInitialProps = composeInitialProps; - exports.date = date; - exports.getDefaults = getDefaults; - exports.getI18n = getI18n; - exports.getInitialProps = getInitialProps; - exports.initReactI18next = initReactI18next; - exports.number = number; - exports.plural = plural; - exports.select = select; - exports.selectOrdinal = selectOrdinal; - exports.setDefaults = setDefaults; - exports.setI18n = setI18n; - exports.time = time; - exports.useSSR = useSSR; - exports.useTranslation = useTranslation; - exports.withSSR = withSSR; - exports.withTranslation = withTranslation; + exports.I18nContext = I18nContext; + exports.I18nextProvider = I18nextProvider; + exports.Trans = Trans; + exports.TransWithoutContext = Trans$1; + exports.Translation = Translation; + exports.composeInitialProps = composeInitialProps; + exports.date = date; + exports.getDefaults = getDefaults; + exports.getI18n = getI18n; + exports.getInitialProps = getInitialProps; + exports.initReactI18next = initReactI18next; + exports.number = number; + exports.plural = plural; + exports.select = select; + exports.selectOrdinal = selectOrdinal; + exports.setDefaults = setDefaults; + exports.setI18n = setI18n; + exports.time = time; + exports.useSSR = useSSR; + exports.useTranslation = useTranslation; + exports.withSSR = withSSR; + exports.withTranslation = withTranslation; })); diff --git a/react-i18next.min.js b/react-i18next.min.js index ce47fdf01..ed13d9807 100644 --- a/react-i18next.min.js +++ b/react-i18next.min.js @@ -1 +1 @@ -!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).ReactI18next={},e.React)}(this,(function(e,n){"use strict";function t(){return t=Object.assign?Object.assign.bind():function(e){for(var n=1;n<]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function o(e){var n={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},t=e.match(/<\/?([^\s]+?)[/\s>]/);if(t&&(n.name=t[1],(s[t[1]]||"/"===e.charAt(e.length-2))&&(n.voidElement=!0),n.name.startsWith("!--"))){var i=e.indexOf("--\x3e");return{type:"comment",comment:-1!==i?e.slice(4,i):""}}for(var o=new RegExp(r),a=null;null!==(a=o.exec(e));)if(a[0].trim())if(a[1]){var c=a[1].trim(),l=[c,""];c.indexOf("=")>-1&&(l=c.split("=")),n.attrs[l[0]]=l[1],o.lastIndex--}else a[2]&&(n.attrs[a[2]]=a[3].trim().substring(1,a[3].length-1));return n}var a=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,c=/^\s*$/,l=Object.create(null);function u(e,n){switch(n.type){case"text":return e+n.content;case"tag":return e+="<"+n.name+(n.attrs?function(e){var n=[];for(var t in e)n.push(t+'="'+e[t]+'"');return n.length?" "+n.join(" "):""}(n.attrs):"")+(n.voidElement?"/>":">"),n.voidElement?e:e+n.children.reduce(u,"")+"";case"comment":return e+"\x3c!--"+n.comment+"--\x3e"}}var p={parse:function(e,n){n||(n={}),n.components||(n.components=l);var t,i=[],s=[],r=-1,u=!1;if(0!==e.indexOf("<")){var p=e.indexOf("<");i.push({type:"text",content:-1===p?e:e.substring(0,p)})}return e.replace(a,(function(a,l){if(u){if(a!=="")return;u=!1}var p,f="/"!==a.charAt(1),d=a.startsWith("\x3c!--"),g=l+a.length,h=e.charAt(g);if(d){var m=o(a);return r<0?(i.push(m),i):((p=s[r]).children.push(m),i)}if(f&&(r++,"tag"===(t=o(a)).type&&n.components[t.name]&&(t.type="component",u=!0),t.voidElement||u||!h||"<"===h||t.children.push({type:"text",content:e.slice(g,e.indexOf("<",g))}),0===r&&i.push(t),(p=s[r-1])&&p.children.push(t),s[r]=t),(!f||t.voidElement)&&(r>-1&&(t.voidElement||t.name===a.slice(2,-1))&&(r--,t=-1===r?i:s[r]),!u&&"<"!==h&&h)){p=-1===r?i:s[r].children;var y=e.indexOf("<",g),b=e.slice(g,-1===y?void 0:y);c.test(b)&&(b=" "),(y>-1&&r+p.length>=0||" "!==b)&&p.push({type:"text",content:b})}})),i},stringify:function(e){return e.reduce((function(e,n){return e+u("",n)}),"")}};function f(){if(console&&console.warn){for(var e=arguments.length,n=new Array(e),t=0;t()=>{if(e.isInitialized)n();else{const t=()=>{setTimeout((()=>{e.off("initialized",t)}),0),n()};e.on("initialized",t)}};function m(e,n,t){e.loadNamespaces(n,h(e,t))}function y(e,n,t,i){"string"==typeof t&&(t=[t]),t.forEach((n=>{e.options.ns.indexOf(n)<0&&e.options.ns.push(n)})),e.loadLanguages(n,h(e,i))}function b(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}const v=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,x={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'," ":" "," ":" ","©":"©","©":"©","®":"®","®":"®","…":"…","…":"…","/":"/","/":"/"},O=e=>x[e];let E,N={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:e=>e.replace(v,O)};function $(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};N={...N,...e}}function w(){return N}function I(e){E=e}function j(){return E}function k(e,n){if(!e)return!1;const t=e.props?e.props.children:e.children;return n?t.length>0:!!t}function S(e){if(!e)return[];const n=e.props?e.props.children:e.children;return e.props&&e.props.i18nIsDynamicList?R(n):n}function R(e){return Array.isArray(e)?e:[e]}function C(e,t){if(!e)return"";let i="";const s=R(e),r=t.transSupportBasicHtmlNodes&&t.transKeepBasicHtmlNodesFor?t.transKeepBasicHtmlNodesFor:[];return s.forEach(((e,s)=>{if("string"==typeof e)i+=`${e}`;else if(n.isValidElement(e)){const n=Object.keys(e.props).length,o=r.indexOf(e.type)>-1,a=e.props.children;if(!a&&o&&0===n)i+=`<${e.type}/>`;else if(a||o&&0===n)if(e.props.i18nIsDynamicList)i+=`<${s}>`;else if(o&&1===n&&"string"==typeof a)i+=`<${e.type}>${a}`;else{const e=C(a,t);i+=`<${s}>${e}`}else i+=`<${s}>`}else if(null===e)f("Trans: the passed in value is invalid - seems you passed in a null child.");else if("object"==typeof e){const{format:n,...t}=e,s=Object.keys(t);if(1===s.length){const e=n?`${s[0]}, ${n}`:s[0];i+=`{{${e}}}`}else f("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",e)}else f("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}}.",e)})),i}function T(e,i,s,r,o,a){if(""===i)return[];const c=r.transKeepBasicHtmlNodesFor||[],l=i&&new RegExp(c.map((e=>`<${e}`)).join("|")).test(i);if(!e&&!l&&!a)return[i];const u={};!function e(t){R(t).forEach((t=>{"string"!=typeof t&&(k(t)?e(S(t)):"object"!=typeof t||n.isValidElement(t)||Object.assign(u,t))}))}(e);const f=p.parse(`<0>${i}`),d={...u,...o};function g(e,t,i){const s=S(e),r=m(s,t.children,i);return function(e){return"[object Array]"===Object.prototype.toString.call(e)&&e.every((e=>n.isValidElement(e)))}(s)&&0===r.length||e.props&&e.props.i18nIsDynamicList?s:r}function h(e,i,s,r,o){e.dummy?(e.children=i,s.push(n.cloneElement(e,{key:r},o?void 0:i))):s.push(...n.Children.map([e],(e=>{const s={...e.props};return delete s.i18nIsDynamicList,n.createElement(e.type,t({},s,{key:r,ref:e.ref},o?{}:{children:i}))})))}function m(t,i,o){const u=R(t);return R(i).reduce(((t,i,p)=>{const f=i.children&&i.children[0]&&i.children[0].content&&s.services.interpolator.interpolate(i.children[0].content,d,s.language);if("tag"===i.type){let a=u[parseInt(i.name,10)];1!==o.length||a||(a=o[0][i.name]),a||(a={});const y=0!==Object.keys(i.attrs).length?function(e,n){const t={...n};return t.props=Object.assign(e.props,n.props),t}({props:i.attrs},a):a,b=n.isValidElement(y),v=b&&k(i,!0)&&!i.voidElement,x=l&&"object"==typeof y&&y.dummy&&!b,O="object"==typeof e&&null!==e&&Object.hasOwnProperty.call(e,i.name);if("string"==typeof y){const e=s.services.interpolator.interpolate(y,d,s.language);t.push(e)}else if(k(y)||v){h(y,g(y,i,o),t,p)}else if(x){h(y,m(u,i.children,o),t,p)}else if(Number.isNaN(parseFloat(i.name)))if(O){h(y,g(y,i,o),t,p,i.voidElement)}else if(r.transSupportBasicHtmlNodes&&c.indexOf(i.name)>-1)if(i.voidElement)t.push(n.createElement(i.name,{key:`${i.name}-${p}`}));else{const e=m(u,i.children,o);t.push(n.createElement(i.name,{key:`${i.name}-${p}`},e))}else if(i.voidElement)t.push(`<${i.name} />`);else{const e=m(u,i.children,o);t.push(`<${i.name}>${e}`)}else if("object"!=typeof y||b)h(y,f,t,p,1!==i.children.length||!f);else{const e=i.children[0]?f:null;e&&t.push(e)}}else if("text"===i.type){const e=r.transWrapTextNodes,o=a?r.unescape(s.services.interpolator.interpolate(i.content,d,s.language)):s.services.interpolator.interpolate(i.content,d,s.language);e?t.push(n.createElement(e,{key:`${i.name}-${p}`},o)):t.push(o)}return t}),[])}return S(m([{dummy:!0,children:e||[]}],f,R(e||[]))[0])}function L(e){let{children:t,count:i,parent:s,i18nKey:r,context:o,tOptions:a={},values:c,defaults:l,components:u,ns:p,i18n:f,t:d,shouldUnescape:h,...m}=e;const y=f||j();if(!y)return g("You will need to pass in an i18next instance by using i18nextReactModule"),t;const b=d||y.t.bind(y)||(e=>e);o&&(a.context=o);const v={...w(),...y.options&&y.options.react};let x=p||b.ns||y.options&&y.options.defaultNS;x="string"==typeof x?[x]:x||["translation"];const O=C(t,v),E=l||O||v.transEmptyNodeValue||r,{hashTransKey:N}=v,$=r||(N?N(O||E):O||E);y.options&&y.options.interpolation&&y.options.interpolation.defaultVariables&&(c=c&&Object.keys(c).length>0?{...c,...y.options.interpolation.defaultVariables}:{...y.options.interpolation.defaultVariables});const I=c?a.interpolation:{interpolation:{...a.interpolation,prefix:"#$?",suffix:"?$#"}},k={...a,count:i,...c,...I,defaultValue:E,ns:x},S=$?b($,k):E;u&&Object.keys(u).forEach((e=>{const t=u[e];"function"==typeof t.type||!t.props||!t.props.children||S.indexOf(`${e}/>`)<0&&S.indexOf(`${e} />`)<0||(u[e]=n.createElement((function(){return n.createElement(n.Fragment,null,t)}),null))}));const R=T(u||t,S,y,v,k,h),L=void 0!==s?s:v.defaultTransParent;return L?n.createElement(L,m,R):R}const P={type:"3rdParty",init(e){$(e.options.react),I(e)}},V=n.createContext();class z{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach((e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)}))}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}function A(e){return n=>new Promise((t=>{const i=B();e.getInitialProps?e.getInitialProps(n).then((e=>{t({...e,...i})})):t(i)}))}function B(){const e=j(),n=e.reportNamespaces?e.reportNamespaces.getUsedNamespaces():[],t={},i={};return e.languages.forEach((t=>{i[t]={},n.forEach((n=>{i[t][n]=e.getResourceBundle(t,n)||{}}))})),t.initialI18nStore=i,t.initialLanguage=e.language,t}const F=(e,t)=>{const i=n.useRef();return n.useEffect((()=>{i.current=t?i.current:e}),[e,t]),i.current};function U(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{i18n:i}=t,{i18n:s,defaultNS:r}=n.useContext(V)||{},o=i||s||j();if(o&&!o.reportNamespaces&&(o.reportNamespaces=new z),!o){g("You will need to pass in an i18next instance by using initReactI18next");const e=(e,n)=>"string"==typeof n?n:n&&"object"==typeof n&&"string"==typeof n.defaultValue?n.defaultValue:Array.isArray(e)?e[e.length-1]:e,n=[e,{},!1];return n.t=e,n.i18n={},n.ready=!1,n}o.options.react&&void 0!==o.options.react.wait&&g("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const a={...w(),...o.options.react,...t},{useSuspense:c,keyPrefix:l}=a;let u=e||r||o.options&&o.options.defaultNS;u="string"==typeof u?[u]:u||["translation"],o.reportNamespaces.addUsedNamespaces&&o.reportNamespaces.addUsedNamespaces(u);const p=(o.isInitialized||o.initializedStoreOnce)&&u.every((e=>function(e,n){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return n.languages&&n.languages.length?void 0!==n.options.ignoreJSONStructure?n.hasLoadedNamespace(e,{lng:t.lng,precheck:(n,i)=>{if(t.bindI18n&&t.bindI18n.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!i(n.isLanguageChangingTo,e))return!1}}):function(e,n){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const i=n.languages[0],s=!!n.options&&n.options.fallbackLng,r=n.languages[n.languages.length-1];if("cimode"===i.toLowerCase())return!0;const o=(e,t)=>{const i=n.services.backendConnector.state[`${e}|${t}`];return-1===i||2===i};return!(t.bindI18n&&t.bindI18n.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!o(n.isLanguageChangingTo,e)||!n.hasResourceBundle(i,e)&&n.services.backendConnector.backend&&(!n.options.resources||n.options.partialBundledLanguages)&&(!o(i,e)||s&&!o(r,e)))}(e,n,t):(g("i18n.languages were undefined or empty",n.languages),!0)}(e,o,a)));function f(){return o.getFixedT(t.lng||null,"fallback"===a.nsMode?u:u[0],l)}const[d,h]=n.useState(f);let b=u.join();t.lng&&(b=`${t.lng}${b}`);const v=F(b),x=n.useRef(!0);n.useEffect((()=>{const{bindI18n:e,bindI18nStore:n}=a;function i(){x.current&&h(f)}return x.current=!0,p||c||(t.lng?y(o,t.lng,u,(()=>{x.current&&h(f)})):m(o,u,(()=>{x.current&&h(f)}))),p&&v&&v!==b&&x.current&&h(f),e&&o&&o.on(e,i),n&&o&&o.store.on(n,i),()=>{x.current=!1,e&&o&&e.split(" ").forEach((e=>o.off(e,i))),n&&o&&n.split(" ").forEach((e=>o.store.off(e,i)))}}),[o,b]);const O=n.useRef(!0);n.useEffect((()=>{x.current&&!O.current&&h(f),O.current=!1}),[o,l]);const E=[d,o,p];if(E.t=d,E.i18n=o,E.ready=p,p)return E;if(!p&&!c)return E;throw new Promise((e=>{t.lng?y(o,t.lng,u,(()=>e())):m(o,u,(()=>e()))}))}function K(e,t){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const{i18n:s}=i,{i18n:r}=n.useContext(V)||{},o=s||r||j();o.options&&o.options.isClone||(e&&!o.initializedStoreOnce&&(o.services.resourceStore.data=e,o.options.ns=Object.values(e).reduce(((e,n)=>(Object.keys(n).forEach((n=>{e.indexOf(n)<0&&e.push(n)})),e)),o.options.ns),o.initializedStoreOnce=!0,o.isInitialized=!0),t&&!o.initializedLanguageOnce&&(o.changeLanguage(t),o.initializedLanguageOnce=!0))}e.I18nContext=V,e.I18nextProvider=function(e){let{i18n:t,defaultNS:i,children:s}=e;const r=n.useMemo((()=>({i18n:t,defaultNS:i})),[t,i]);return n.createElement(V.Provider,{value:r},s)},e.Trans=function(e){let{children:t,count:i,parent:s,i18nKey:r,context:o,tOptions:a={},values:c,defaults:l,components:u,ns:p,i18n:f,t:d,shouldUnescape:g,...h}=e;const{i18n:m,defaultNS:y}=n.useContext(V)||{},b=f||m||j(),v=d||b&&b.t.bind(b);return L({children:t,count:i,parent:s,i18nKey:r,context:o,tOptions:a,values:c,defaults:l,components:u,ns:p||v&&v.ns||y||b&&b.options&&b.options.defaultNS,i18n:b,t:d,shouldUnescape:g,...h})},e.TransWithoutContext=L,e.Translation=function(e){const{ns:n,children:t,...i}=e,[s,r,o]=U(n,i);return t(s,{i18n:r,lng:r.language},o)},e.composeInitialProps=A,e.date=()=>"",e.getDefaults=w,e.getI18n=j,e.getInitialProps=B,e.initReactI18next=P,e.number=()=>"",e.plural=()=>"",e.select=()=>"",e.selectOrdinal=()=>"",e.setDefaults=$,e.setI18n=I,e.time=()=>"",e.useSSR=K,e.useTranslation=U,e.withSSR=function(){return function(e){function t(t){let{initialI18nStore:i,initialLanguage:s,...r}=t;return K(i,s),n.createElement(e,{...r})}return t.getInitialProps=A(e),t.displayName=`withI18nextSSR(${b(e)})`,t.WrappedComponent=e,t}},e.withTranslation=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(i){function s(s){let{forwardedRef:r,...o}=s;const[a,c,l]=U(e,{...o,keyPrefix:t.keyPrefix}),u={...o,t:a,i18n:c,tReady:l};return t.withRef&&r?u.ref=r:!t.withRef&&r&&(u.forwardedRef=r),n.createElement(i,u)}s.displayName=`withI18nextTranslation(${b(i)})`,s.WrappedComponent=i;return t.withRef?n.forwardRef(((e,t)=>n.createElement(s,Object.assign({},e,{forwardedRef:t})))):s}}})); +!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).ReactI18next={},e.React)}(this,(function(e,n){"use strict";function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s=t({area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0}),i=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function r(e){var n={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},t=e.match(/<\/?([^\s]+?)[/\s>]/);if(t&&(n.name=t[1],(s[t[1]]||"/"===e.charAt(e.length-2))&&(n.voidElement=!0),n.name.startsWith("!--"))){var r=e.indexOf("--\x3e");return{type:"comment",comment:-1!==r?e.slice(4,r):""}}for(var o=new RegExp(i),a=null;null!==(a=o.exec(e));)if(a[0].trim())if(a[1]){var c=a[1].trim(),l=[c,""];c.indexOf("=")>-1&&(l=c.split("=")),n.attrs[l[0]]=l[1],o.lastIndex--}else a[2]&&(n.attrs[a[2]]=a[3].trim().substring(1,a[3].length-1));return n}var o=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,a=/^\s*$/,c=Object.create(null);function l(e,n){switch(n.type){case"text":return e+n.content;case"tag":return e+="<"+n.name+(n.attrs?function(e){var n=[];for(var t in e)n.push(t+'="'+e[t]+'"');return n.length?" "+n.join(" "):""}(n.attrs):"")+(n.voidElement?"/>":">"),n.voidElement?e:e+n.children.reduce(l,"")+"";case"comment":return e+"\x3c!--"+n.comment+"--\x3e"}}var u={parse:function(e,n){n||(n={}),n.components||(n.components=c);var t,s=[],i=[],l=-1,u=!1;if(0!==e.indexOf("<")){var p=e.indexOf("<");s.push({type:"text",content:-1===p?e:e.substring(0,p)})}return e.replace(o,(function(o,c){if(u){if(o!=="")return;u=!1}var p,f="/"!==o.charAt(1),d=o.startsWith("\x3c!--"),g=c+o.length,h=e.charAt(g);if(d){var m=r(o);return l<0?(s.push(m),s):((p=i[l]).children.push(m),s)}if(f&&(l++,"tag"===(t=r(o)).type&&n.components[t.name]&&(t.type="component",u=!0),t.voidElement||u||!h||"<"===h||t.children.push({type:"text",content:e.slice(g,e.indexOf("<",g))}),0===l&&s.push(t),(p=i[l-1])&&p.children.push(t),i[l]=t),(!f||t.voidElement)&&(l>-1&&(t.voidElement||t.name===o.slice(2,-1))&&(l--,t=-1===l?s:i[l]),!u&&"<"!==h&&h)){p=-1===l?s:i[l].children;var y=e.indexOf("<",g),b=e.slice(g,-1===y?void 0:y);a.test(b)&&(b=" "),(y>-1&&l+p.length>=0||" "!==b)&&p.push({type:"text",content:b})}})),s},stringify:function(e){return e.reduce((function(e,n){return e+l("",n)}),"")}};function p(){if(console&&console.warn){for(var e=arguments.length,n=new Array(e),t=0;t()=>{if(e.isInitialized)n();else{const t=()=>{setTimeout((()=>{e.off("initialized",t)}),0),n()};e.on("initialized",t)}};function h(e,n,t){e.loadNamespaces(n,g(e,t))}function m(e,n,t,s){"string"==typeof t&&(t=[t]),t.forEach((n=>{e.options.ns.indexOf(n)<0&&e.options.ns.push(n)})),e.loadLanguages(n,g(e,s))}function y(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}const b=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,v={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'," ":" "," ":" ","©":"©","©":"©","®":"®","®":"®","…":"…","…":"…","/":"/","/":"/"},x=e=>v[e];let E,N={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:e=>e.replace(b,x)};function O(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};N={...N,...e}}function $(){return N}function w(e){E=e}function I(){return E}function k(e,n){if(!e)return!1;const t=e.props?e.props.children:e.children;return n?t.length>0:!!t}function S(e){if(!e)return[];const n=e.props?e.props.children:e.children;return e.props&&e.props.i18nIsDynamicList?j(n):n}function j(e){return Array.isArray(e)?e:[e]}function R(e,t){if(!e)return"";let s="";const i=j(e),r=t.transSupportBasicHtmlNodes&&t.transKeepBasicHtmlNodesFor?t.transKeepBasicHtmlNodesFor:[];return i.forEach(((e,i)=>{if("string"==typeof e)s+=`${e}`;else if(n.isValidElement(e)){const n=Object.keys(e.props).length,o=r.indexOf(e.type)>-1,a=e.props.children;if(!a&&o&&0===n)s+=`<${e.type}/>`;else if(a||o&&0===n)if(e.props.i18nIsDynamicList)s+=`<${i}>`;else if(o&&1===n&&"string"==typeof a)s+=`<${e.type}>${a}`;else{const e=R(a,t);s+=`<${i}>${e}`}else s+=`<${i}>`}else if(null===e)p("Trans: the passed in value is invalid - seems you passed in a null child.");else if("object"==typeof e){const{format:n,...t}=e,i=Object.keys(t);if(1===i.length){const e=n?`${i[0]}, ${n}`:i[0];s+=`{{${e}}}`}else p("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",e)}else p("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}}.",e)})),s}function C(e,t,s,i,r,o){if(""===t)return[];const a=i.transKeepBasicHtmlNodesFor||[],c=t&&new RegExp(a.map((e=>`<${e}`)).join("|")).test(t);if(!e&&!c&&!o)return[t];const l={};!function e(t){j(t).forEach((t=>{"string"!=typeof t&&(k(t)?e(S(t)):"object"!=typeof t||n.isValidElement(t)||Object.assign(l,t))}))}(e);const p=u.parse(`<0>${t}`),f={...l,...r};function d(e,t,s){const i=S(e),r=h(i,t.children,s);return function(e){return"[object Array]"===Object.prototype.toString.call(e)&&e.every((e=>n.isValidElement(e)))}(i)&&0===r.length||e.props&&e.props.i18nIsDynamicList?i:r}function g(e,t,s,i,r){e.dummy?(e.children=t,s.push(n.cloneElement(e,{key:i},r?void 0:t))):s.push(...n.Children.map([e],(e=>{const s={...e.props};return delete s.i18nIsDynamicList,n.createElement(e.type,{...s,key:i,ref:e.ref},r?null:t)})))}function h(t,r,l){const u=j(t);return j(r).reduce(((t,r,p)=>{const m=r.children&&r.children[0]&&r.children[0].content&&s.services.interpolator.interpolate(r.children[0].content,f,s.language);if("tag"===r.type){let o=u[parseInt(r.name,10)];1!==l.length||o||(o=l[0][r.name]),o||(o={});const y=0!==Object.keys(r.attrs).length?function(e,n){const t={...n};return t.props=Object.assign(e.props,n.props),t}({props:r.attrs},o):o,b=n.isValidElement(y),v=b&&k(r,!0)&&!r.voidElement,x=c&&"object"==typeof y&&y.dummy&&!b,E="object"==typeof e&&null!==e&&Object.hasOwnProperty.call(e,r.name);if("string"==typeof y){const e=s.services.interpolator.interpolate(y,f,s.language);t.push(e)}else if(k(y)||v){g(y,d(y,r,l),t,p)}else if(x){g(y,h(u,r.children,l),t,p)}else if(Number.isNaN(parseFloat(r.name)))if(E){g(y,d(y,r,l),t,p,r.voidElement)}else if(i.transSupportBasicHtmlNodes&&a.indexOf(r.name)>-1)if(r.voidElement)t.push(n.createElement(r.name,{key:`${r.name}-${p}`}));else{const e=h(u,r.children,l);t.push(n.createElement(r.name,{key:`${r.name}-${p}`},e))}else if(r.voidElement)t.push(`<${r.name} />`);else{const e=h(u,r.children,l);t.push(`<${r.name}>${e}`)}else if("object"!=typeof y||b)g(y,m,t,p,1!==r.children.length||!m);else{const e=r.children[0]?m:null;e&&t.push(e)}}else if("text"===r.type){const e=i.transWrapTextNodes,a=o?i.unescape(s.services.interpolator.interpolate(r.content,f,s.language)):s.services.interpolator.interpolate(r.content,f,s.language);e?t.push(n.createElement(e,{key:`${r.name}-${p}`},a)):t.push(a)}return t}),[])}return S(h([{dummy:!0,children:e||[]}],p,j(e||[]))[0])}function T(e){let{children:t,count:s,parent:i,i18nKey:r,context:o,tOptions:a={},values:c,defaults:l,components:u,ns:p,i18n:f,t:g,shouldUnescape:h,...m}=e;const y=f||I();if(!y)return d("You will need to pass in an i18next instance by using i18nextReactModule"),t;const b=g||y.t.bind(y)||(e=>e);o&&(a.context=o);const v={...$(),...y.options&&y.options.react};let x=p||b.ns||y.options&&y.options.defaultNS;x="string"==typeof x?[x]:x||["translation"];const E=R(t,v),N=l||E||v.transEmptyNodeValue||r,{hashTransKey:O}=v,w=r||(O?O(E||N):E||N);y.options&&y.options.interpolation&&y.options.interpolation.defaultVariables&&(c=c&&Object.keys(c).length>0?{...c,...y.options.interpolation.defaultVariables}:{...y.options.interpolation.defaultVariables});const k=c?a.interpolation:{interpolation:{...a.interpolation,prefix:"#$?",suffix:"?$#"}},S={...a,count:s,...c,...k,defaultValue:N,ns:x},j=w?b(w,S):N;u&&Object.keys(u).forEach((e=>{const t=u[e];"function"==typeof t.type||!t.props||!t.props.children||j.indexOf(`${e}/>`)<0&&j.indexOf(`${e} />`)<0||(u[e]=n.createElement((function(){return n.createElement(n.Fragment,null,t)})))}));const T=C(u||t,j,y,v,S,h),L=void 0!==i?i:v.defaultTransParent;return L?n.createElement(L,m,T):T}const L={type:"3rdParty",init(e){O(e.options.react),w(e)}},P=n.createContext();class V{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach((e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)}))}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}function z(e){return n=>new Promise((t=>{const s=A();e.getInitialProps?e.getInitialProps(n).then((e=>{t({...e,...s})})):t(s)}))}function A(){const e=I(),n=e.reportNamespaces?e.reportNamespaces.getUsedNamespaces():[],t={},s={};return e.languages.forEach((t=>{s[t]={},n.forEach((n=>{s[t][n]=e.getResourceBundle(t,n)||{}}))})),t.initialI18nStore=s,t.initialLanguage=e.language,t}const B=(e,t)=>{const s=n.useRef();return n.useEffect((()=>{s.current=t?s.current:e}),[e,t]),s.current};function F(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{i18n:s}=t,{i18n:i,defaultNS:r}=n.useContext(P)||{},o=s||i||I();if(o&&!o.reportNamespaces&&(o.reportNamespaces=new V),!o){d("You will need to pass in an i18next instance by using initReactI18next");const e=(e,n)=>"string"==typeof n?n:n&&"object"==typeof n&&"string"==typeof n.defaultValue?n.defaultValue:Array.isArray(e)?e[e.length-1]:e,n=[e,{},!1];return n.t=e,n.i18n={},n.ready=!1,n}o.options.react&&void 0!==o.options.react.wait&&d("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const a={...$(),...o.options.react,...t},{useSuspense:c,keyPrefix:l}=a;let u=e||r||o.options&&o.options.defaultNS;u="string"==typeof u?[u]:u||["translation"],o.reportNamespaces.addUsedNamespaces&&o.reportNamespaces.addUsedNamespaces(u);const p=(o.isInitialized||o.initializedStoreOnce)&&u.every((e=>function(e,n){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return n.languages&&n.languages.length?void 0!==n.options.ignoreJSONStructure?n.hasLoadedNamespace(e,{lng:t.lng,precheck:(n,s)=>{if(t.bindI18n&&t.bindI18n.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!s(n.isLanguageChangingTo,e))return!1}}):function(e,n){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const s=n.languages[0],i=!!n.options&&n.options.fallbackLng,r=n.languages[n.languages.length-1];if("cimode"===s.toLowerCase())return!0;const o=(e,t)=>{const s=n.services.backendConnector.state[`${e}|${t}`];return-1===s||2===s};return!(t.bindI18n&&t.bindI18n.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!o(n.isLanguageChangingTo,e)||!n.hasResourceBundle(s,e)&&n.services.backendConnector.backend&&(!n.options.resources||n.options.partialBundledLanguages)&&(!o(s,e)||i&&!o(r,e)))}(e,n,t):(d("i18n.languages were undefined or empty",n.languages),!0)}(e,o,a)));function f(){return o.getFixedT(t.lng||null,"fallback"===a.nsMode?u:u[0],l)}const[g,y]=n.useState(f);let b=u.join();t.lng&&(b=`${t.lng}${b}`);const v=B(b),x=n.useRef(!0);n.useEffect((()=>{const{bindI18n:e,bindI18nStore:n}=a;function s(){x.current&&y(f)}return x.current=!0,p||c||(t.lng?m(o,t.lng,u,(()=>{x.current&&y(f)})):h(o,u,(()=>{x.current&&y(f)}))),p&&v&&v!==b&&x.current&&y(f),e&&o&&o.on(e,s),n&&o&&o.store.on(n,s),()=>{x.current=!1,e&&o&&e.split(" ").forEach((e=>o.off(e,s))),n&&o&&n.split(" ").forEach((e=>o.store.off(e,s)))}}),[o,b]);const E=n.useRef(!0);n.useEffect((()=>{x.current&&!E.current&&y(f),E.current=!1}),[o,l]);const N=[g,o,p];if(N.t=g,N.i18n=o,N.ready=p,p)return N;if(!p&&!c)return N;throw new Promise((e=>{t.lng?m(o,t.lng,u,(()=>e())):h(o,u,(()=>e()))}))}function U(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const{i18n:i}=s,{i18n:r}=n.useContext(P)||{},o=i||r||I();o.options&&o.options.isClone||(e&&!o.initializedStoreOnce&&(o.services.resourceStore.data=e,o.options.ns=Object.values(e).reduce(((e,n)=>(Object.keys(n).forEach((n=>{e.indexOf(n)<0&&e.push(n)})),e)),o.options.ns),o.initializedStoreOnce=!0,o.isInitialized=!0),t&&!o.initializedLanguageOnce&&(o.changeLanguage(t),o.initializedLanguageOnce=!0))}e.I18nContext=P,e.I18nextProvider=function(e){let{i18n:t,defaultNS:s,children:i}=e;const r=n.useMemo((()=>({i18n:t,defaultNS:s})),[t,s]);return n.createElement(P.Provider,{value:r},i)},e.Trans=function(e){let{children:t,count:s,parent:i,i18nKey:r,context:o,tOptions:a={},values:c,defaults:l,components:u,ns:p,i18n:f,t:d,shouldUnescape:g,...h}=e;const{i18n:m,defaultNS:y}=n.useContext(P)||{},b=f||m||I(),v=d||b&&b.t.bind(b);return T({children:t,count:s,parent:i,i18nKey:r,context:o,tOptions:a,values:c,defaults:l,components:u,ns:p||v&&v.ns||y||b&&b.options&&b.options.defaultNS,i18n:b,t:d,shouldUnescape:g,...h})},e.TransWithoutContext=T,e.Translation=function(e){const{ns:n,children:t,...s}=e,[i,r,o]=F(n,s);return t(i,{i18n:r,lng:r.language},o)},e.composeInitialProps=z,e.date=()=>"",e.getDefaults=$,e.getI18n=I,e.getInitialProps=A,e.initReactI18next=L,e.number=()=>"",e.plural=()=>"",e.select=()=>"",e.selectOrdinal=()=>"",e.setDefaults=O,e.setI18n=w,e.time=()=>"",e.useSSR=U,e.useTranslation=F,e.withSSR=function(){return function(e){function t(t){let{initialI18nStore:s,initialLanguage:i,...r}=t;return U(s,i),n.createElement(e,{...r})}return t.getInitialProps=z(e),t.displayName=`withI18nextSSR(${y(e)})`,t.WrappedComponent=e,t}},e.withTranslation=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(s){function i(i){let{forwardedRef:r,...o}=i;const[a,c,l]=F(e,{...o,keyPrefix:t.keyPrefix}),u={...o,t:a,i18n:c,tReady:l};return t.withRef&&r?u.ref=r:!t.withRef&&r&&(u.forwardedRef=r),n.createElement(s,u)}i.displayName=`withI18nextTranslation(${y(s)})`,i.WrappedComponent=s;return t.withRef?n.forwardRef(((e,t)=>n.createElement(i,Object.assign({},e,{forwardedRef:t})))):i}}}));