@trii/components 2.0.11 → 2.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/cjs/index.js +2814 -45
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/cjs/types/components/ContactInfoPopup/ContactInfoPopup.d.ts +1 -2
  4. package/dist/cjs/types/components/ContactInfoPopup/components/Header/Header.d.ts +6 -6
  5. package/dist/cjs/types/components/ContactInfoPopup/hooks/useContactInfoPopupTranslation.d.ts +24 -0
  6. package/dist/cjs/types/components/LanguageSelector.d.ts +2 -0
  7. package/dist/cjs/types/contexts/LanguageContext.d.ts +10 -0
  8. package/dist/cjs/types/i18n.d.ts +2 -0
  9. package/dist/cjs/types/index.d.ts +5 -0
  10. package/dist/cjs/types/translations/en.d.ts +31 -0
  11. package/dist/cjs/types/translations/es.d.ts +31 -0
  12. package/dist/cjs/types/translations/index.d.ts +2 -0
  13. package/dist/cjs/types/types/translations.d.ts +25 -0
  14. package/dist/cjs/types/utils/translation.d.ts +7 -0
  15. package/dist/esm/index.js +2811 -48
  16. package/dist/esm/index.js.map +1 -1
  17. package/dist/esm/types/components/ContactInfoPopup/ContactInfoPopup.d.ts +1 -2
  18. package/dist/esm/types/components/ContactInfoPopup/components/Header/Header.d.ts +6 -6
  19. package/dist/esm/types/components/ContactInfoPopup/hooks/useContactInfoPopupTranslation.d.ts +24 -0
  20. package/dist/esm/types/components/LanguageSelector.d.ts +2 -0
  21. package/dist/esm/types/contexts/LanguageContext.d.ts +10 -0
  22. package/dist/esm/types/i18n.d.ts +2 -0
  23. package/dist/esm/types/index.d.ts +5 -0
  24. package/dist/esm/types/translations/en.d.ts +31 -0
  25. package/dist/esm/types/translations/es.d.ts +31 -0
  26. package/dist/esm/types/translations/index.d.ts +2 -0
  27. package/dist/esm/types/types/translations.d.ts +25 -0
  28. package/dist/esm/types/utils/translation.d.ts +7 -0
  29. package/dist/index.d.ts +84 -3
  30. package/package.json +6 -2
  31. package/readme +42 -0
package/dist/cjs/index.js CHANGED
@@ -3030,16 +3030,16 @@ var getDisplayName = /*#__PURE__*/Object.freeze({
3030
3030
  //
3031
3031
  // A strict capitalization should uppercase the first letter of each word in the sentence.
3032
3032
  // We only handle the first word.
3033
- function capitalize$1(string) {
3033
+ function capitalize$2(string) {
3034
3034
  if (typeof string !== 'string') {
3035
3035
  throw new Error(process.env.NODE_ENV !== "production" ? `MUI: \`capitalize(string)\` expects a string argument.` : formatMuiErrorMessage$1(7));
3036
3036
  }
3037
3037
  return string.charAt(0).toUpperCase() + string.slice(1);
3038
3038
  }
3039
3039
 
3040
- var capitalize = /*#__PURE__*/Object.freeze({
3040
+ var capitalize$1 = /*#__PURE__*/Object.freeze({
3041
3041
  __proto__: null,
3042
- default: capitalize$1
3042
+ default: capitalize$2
3043
3043
  });
3044
3044
 
3045
3045
  /**
@@ -3755,7 +3755,7 @@ function removeUnusedBreakpoints(breakpointKeys, style) {
3755
3755
  }, style);
3756
3756
  }
3757
3757
 
3758
- function getPath(obj, path, checkVars = true) {
3758
+ function getPath$1(obj, path, checkVars = true) {
3759
3759
  if (!path || typeof path !== 'string') {
3760
3760
  return null;
3761
3761
  }
@@ -3781,7 +3781,7 @@ function getStyleValue(themeMapping, transform, propValueFinal, userValue = prop
3781
3781
  } else if (Array.isArray(themeMapping)) {
3782
3782
  value = themeMapping[propValueFinal] || userValue;
3783
3783
  } else {
3784
- value = getPath(themeMapping, propValueFinal) || userValue;
3784
+ value = getPath$1(themeMapping, propValueFinal) || userValue;
3785
3785
  }
3786
3786
  if (transform) {
3787
3787
  value = transform(value, userValue, themeMapping);
@@ -3804,12 +3804,12 @@ function style$1(options) {
3804
3804
  }
3805
3805
  const propValue = props[prop];
3806
3806
  const theme = props.theme;
3807
- const themeMapping = getPath(theme, themeKey) || {};
3807
+ const themeMapping = getPath$1(theme, themeKey) || {};
3808
3808
  const styleFromPropValue = propValueFinal => {
3809
3809
  let value = getStyleValue(themeMapping, transform, propValueFinal);
3810
3810
  if (propValueFinal === value && typeof propValueFinal === 'string') {
3811
3811
  // Haven't found value
3812
- value = getStyleValue(themeMapping, transform, `${prop}${propValueFinal === 'default' ? '' : capitalize$1(propValueFinal)}`, propValueFinal);
3812
+ value = getStyleValue(themeMapping, transform, `${prop}${propValueFinal === 'default' ? '' : capitalize$2(propValueFinal)}`, propValueFinal);
3813
3813
  }
3814
3814
  if (cssProperty === false) {
3815
3815
  return value;
@@ -3878,7 +3878,7 @@ const paddingKeys = ['p', 'pt', 'pr', 'pb', 'pl', 'px', 'py', 'padding', 'paddin
3878
3878
  const spacingKeys = [...marginKeys, ...paddingKeys];
3879
3879
  function createUnaryUnit(theme, themeKey, defaultValue, propName) {
3880
3880
  var _getPath;
3881
- const themeSpacing = (_getPath = getPath(theme, themeKey, false)) != null ? _getPath : defaultValue;
3881
+ const themeSpacing = (_getPath = getPath$1(theme, themeKey, false)) != null ? _getPath : defaultValue;
3882
3882
  if (typeof themeSpacing === 'number') {
3883
3883
  return abs => {
3884
3884
  if (typeof abs === 'string') {
@@ -4562,7 +4562,7 @@ function unstable_createStyleFunctionSx() {
4562
4562
  [prop]: val
4563
4563
  };
4564
4564
  }
4565
- const themeMapping = getPath(theme, themeKey) || {};
4565
+ const themeMapping = getPath$1(theme, themeKey) || {};
4566
4566
  if (style) {
4567
4567
  return style(props);
4568
4568
  }
@@ -4570,7 +4570,7 @@ function unstable_createStyleFunctionSx() {
4570
4570
  let value = getStyleValue(themeMapping, transform, propValueFinal);
4571
4571
  if (propValueFinal === value && typeof propValueFinal === 'string') {
4572
4572
  // Haven't found value
4573
- value = getStyleValue(themeMapping, transform, `${prop}${propValueFinal === 'default' ? '' : capitalize$1(propValueFinal)}`, propValueFinal);
4573
+ value = getStyleValue(themeMapping, transform, `${prop}${propValueFinal === 'default' ? '' : capitalize$2(propValueFinal)}`, propValueFinal);
4574
4574
  }
4575
4575
  if (cssProperty === false) {
4576
4576
  return value;
@@ -5758,7 +5758,7 @@ function node (value, root, parent, type, props, children, length) {
5758
5758
  * @param {object} props
5759
5759
  * @return {object}
5760
5760
  */
5761
- function copy (root, props) {
5761
+ function copy$1 (root, props) {
5762
5762
  return assign(node('', null, null, '', null, null, 0), root, {length: -root.length}, props)
5763
5763
  }
5764
5764
 
@@ -6634,7 +6634,7 @@ var prefixer = function prefixer(element, index, children, callback) {
6634
6634
  break;
6635
6635
 
6636
6636
  case KEYFRAMES:
6637
- return serialize([copy(element, {
6637
+ return serialize([copy$1(element, {
6638
6638
  value: replace(element.value, '@', '@' + WEBKIT)
6639
6639
  })], callback);
6640
6640
 
@@ -6644,17 +6644,17 @@ var prefixer = function prefixer(element, index, children, callback) {
6644
6644
  // :read-(only|write)
6645
6645
  case ':read-only':
6646
6646
  case ':read-write':
6647
- return serialize([copy(element, {
6647
+ return serialize([copy$1(element, {
6648
6648
  props: [replace(value, /:(read-\w+)/, ':' + MOZ + '$1')]
6649
6649
  })], callback);
6650
6650
  // :placeholder
6651
6651
 
6652
6652
  case '::placeholder':
6653
- return serialize([copy(element, {
6653
+ return serialize([copy$1(element, {
6654
6654
  props: [replace(value, /:(plac\w+)/, ':' + WEBKIT + 'input-$1')]
6655
- }), copy(element, {
6655
+ }), copy$1(element, {
6656
6656
  props: [replace(value, /:(plac\w+)/, ':' + MOZ + '$1')]
6657
- }), copy(element, {
6657
+ }), copy$1(element, {
6658
6658
  props: [replace(value, /:(plac\w+)/, MS + 'input-$1')]
6659
6659
  })], callback);
6660
6660
  }
@@ -8208,7 +8208,7 @@ var require$$3 = /*@__PURE__*/getAugmentedNamespace(styledEngine);
8208
8208
 
8209
8209
  var require$$4 = /*@__PURE__*/getAugmentedNamespace(deepmerge);
8210
8210
 
8211
- var require$$5 = /*@__PURE__*/getAugmentedNamespace(capitalize);
8211
+ var require$$5 = /*@__PURE__*/getAugmentedNamespace(capitalize$1);
8212
8212
 
8213
8213
  var require$$6 = /*@__PURE__*/getAugmentedNamespace(getDisplayName);
8214
8214
 
@@ -8494,7 +8494,7 @@ const useUtilityClasses = ownerState => {
8494
8494
  classes
8495
8495
  } = ownerState;
8496
8496
  const slots = {
8497
- root: ['root', color !== 'inherit' && `color${capitalize$1(color)}`, `fontSize${capitalize$1(fontSize)}`]
8497
+ root: ['root', color !== 'inherit' && `color${capitalize$2(color)}`, `fontSize${capitalize$2(fontSize)}`]
8498
8498
  };
8499
8499
  return composeClasses(slots, getSvgIconUtilityClass, classes);
8500
8500
  };
@@ -8505,7 +8505,7 @@ const SvgIconRoot = styled$1('svg', {
8505
8505
  const {
8506
8506
  ownerState
8507
8507
  } = props;
8508
- return [styles.root, ownerState.color !== 'inherit' && styles[`color${capitalize$1(ownerState.color)}`], styles[`fontSize${capitalize$1(ownerState.fontSize)}`]];
8508
+ return [styles.root, ownerState.color !== 'inherit' && styles[`color${capitalize$2(ownerState.color)}`], styles[`fontSize${capitalize$2(ownerState.fontSize)}`]];
8509
8509
  }
8510
8510
  })(({
8511
8511
  theme,
@@ -8691,7 +8691,7 @@ const unstable_ClassNameGenerator = {
8691
8691
 
8692
8692
  var utils = /*#__PURE__*/Object.freeze({
8693
8693
  __proto__: null,
8694
- capitalize: capitalize$1,
8694
+ capitalize: capitalize$2,
8695
8695
  createChainedFunction: createChainedFunction,
8696
8696
  createSvgIcon: createSvgIcon$1,
8697
8697
  debounce: debounce,
@@ -8737,10 +8737,6 @@ var PhoneEnabled = createSvgIcon$1( /*#__PURE__*/jsxRuntimeExports.jsx("path", {
8737
8737
  d: "m17.38 10.79-2.2-2.2c-.28-.28-.36-.67-.25-1.02.37-1.12.57-2.32.57-3.57 0-.55.45-1 1-1H20c.55 0 1 .45 1 1 0 9.39-7.61 17-17 17-.55 0-1-.45-1-1v-3.49c0-.55.45-1 1-1 1.24 0 2.45-.2 3.57-.57.35-.12.75-.03 1.02.24l2.2 2.2c2.83-1.45 5.15-3.76 6.59-6.59"
8738
8738
  }), 'PhoneEnabled');
8739
8739
 
8740
- var ThreeP = createSvgIcon$1( /*#__PURE__*/jsxRuntimeExports.jsx("path", {
8741
- d: "M20 2H4.01c-1.1 0-2 .9-2 2L2 22l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2m-8 4c1.1 0 2 .9 2 2s-.9 2-2 2-2-.9-2-2 .9-2 2-2m4 8H8v-.57c0-.81.48-1.53 1.22-1.85.85-.37 1.79-.58 2.78-.58.99 0 1.93.21 2.78.58.74.32 1.22 1.04 1.22 1.85z"
8742
- }), 'ThreeP');
8743
-
8744
8740
  var WhatsApp = createSvgIcon$1( /*#__PURE__*/jsxRuntimeExports.jsx("path", {
8745
8741
  d: "M16.75 13.96c.25.13.41.2.46.3.06.11.04.61-.21 1.18-.2.56-1.24 1.1-1.7 1.12-.46.02-.47.36-2.96-.73-2.49-1.09-3.99-3.75-4.11-3.92-.12-.17-.96-1.38-.92-2.61.05-1.22.69-1.8.95-2.04.24-.26.51-.29.68-.26h.47c.15 0 .36-.06.55.45l.69 1.87c.06.13.1.28.01.44l-.27.41-.39.42c-.12.12-.26.25-.12.5.12.26.62 1.09 1.32 1.78.91.88 1.71 1.17 1.95 1.3.24.14.39.12.54-.04l.81-.94c.19-.25.35-.19.58-.11l1.67.88M12 2a10 10 0 0 1 10 10 10 10 0 0 1-10 10c-1.97 0-3.8-.57-5.35-1.55L2 22l1.55-4.65A9.969 9.969 0 0 1 2 12 10 10 0 0 1 12 2m0 2a8 8 0 0 0-8 8c0 1.72.54 3.31 1.46 4.61L4.5 19.5l2.89-.96A7.95 7.95 0 0 0 12 20a8 8 0 0 0 8-8 8 8 0 0 0-8-8z"
8746
8742
  }), 'WhatsApp');
@@ -8816,7 +8812,7 @@ const ContactName = material.styled(material.Typography)({
8816
8812
  maxWidth: 200,
8817
8813
  textAlign: 'center',
8818
8814
  });
8819
- const Header = ({ imgUrl, name, contactId, navigate }) => {
8815
+ const Header = ({ contactId, imgUrl, name, navigate }) => {
8820
8816
  const handleOpenInNewTab = (event) => {
8821
8817
  event.preventDefault();
8822
8818
  event.stopPropagation();
@@ -14831,6 +14827,289 @@ const MembersSection = ({ contactData, title }) => {
14831
14827
  return (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsx(SectionTitle, { gutterBottom: true, mt: 2, variant: "subtitle1", children: title }), jsxRuntimeExports.jsx(material.Typography, { variant: "body2", color: "text.secondary", children: contactData?.members.map((member) => (jsxRuntimeExports.jsx(MemberItem, { name: member.name }, member.id))) })] }));
14832
14828
  };
14833
14829
 
14830
+ function warn() {
14831
+ if (console && console.warn) {
14832
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
14833
+ args[_key] = arguments[_key];
14834
+ }
14835
+ if (isString$1(args[0])) args[0] = `react-i18next:: ${args[0]}`;
14836
+ console.warn(...args);
14837
+ }
14838
+ }
14839
+ const alreadyWarned = {};
14840
+ function warnOnce() {
14841
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
14842
+ args[_key2] = arguments[_key2];
14843
+ }
14844
+ if (isString$1(args[0]) && alreadyWarned[args[0]]) return;
14845
+ if (isString$1(args[0])) alreadyWarned[args[0]] = new Date();
14846
+ warn(...args);
14847
+ }
14848
+ const loadedClb = (i18n, cb) => () => {
14849
+ if (i18n.isInitialized) {
14850
+ cb();
14851
+ } else {
14852
+ const initialized = () => {
14853
+ setTimeout(() => {
14854
+ i18n.off('initialized', initialized);
14855
+ }, 0);
14856
+ cb();
14857
+ };
14858
+ i18n.on('initialized', initialized);
14859
+ }
14860
+ };
14861
+ const loadNamespaces = (i18n, ns, cb) => {
14862
+ i18n.loadNamespaces(ns, loadedClb(i18n, cb));
14863
+ };
14864
+ const loadLanguages = (i18n, lng, ns, cb) => {
14865
+ if (isString$1(ns)) ns = [ns];
14866
+ ns.forEach(n => {
14867
+ if (i18n.options.ns.indexOf(n) < 0) i18n.options.ns.push(n);
14868
+ });
14869
+ i18n.loadLanguages(lng, loadedClb(i18n, cb));
14870
+ };
14871
+ const oldI18nextHasLoadedNamespace = function (ns, i18n) {
14872
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
14873
+ const lng = i18n.languages[0];
14874
+ const fallbackLng = i18n.options ? i18n.options.fallbackLng : false;
14875
+ const lastLng = i18n.languages[i18n.languages.length - 1];
14876
+ if (lng.toLowerCase() === 'cimode') return true;
14877
+ const loadNotPending = (l, n) => {
14878
+ const loadState = i18n.services.backendConnector.state[`${l}|${n}`];
14879
+ return loadState === -1 || loadState === 2;
14880
+ };
14881
+ if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18n.services.backendConnector.backend && i18n.isLanguageChangingTo && !loadNotPending(i18n.isLanguageChangingTo, ns)) return false;
14882
+ if (i18n.hasResourceBundle(lng, ns)) return true;
14883
+ if (!i18n.services.backendConnector.backend || i18n.options.resources && !i18n.options.partialBundledLanguages) return true;
14884
+ if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
14885
+ return false;
14886
+ };
14887
+ const hasLoadedNamespace = function (ns, i18n) {
14888
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
14889
+ if (!i18n.languages || !i18n.languages.length) {
14890
+ warnOnce('i18n.languages were undefined or empty', i18n.languages);
14891
+ return true;
14892
+ }
14893
+ const isNewerI18next = i18n.options.ignoreJSONStructure !== undefined;
14894
+ if (!isNewerI18next) {
14895
+ return oldI18nextHasLoadedNamespace(ns, i18n, options);
14896
+ }
14897
+ return i18n.hasLoadedNamespace(ns, {
14898
+ lng: options.lng,
14899
+ precheck: (i18nInstance, loadNotPending) => {
14900
+ if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18nInstance.services.backendConnector.backend && i18nInstance.isLanguageChangingTo && !loadNotPending(i18nInstance.isLanguageChangingTo, ns)) return false;
14901
+ }
14902
+ });
14903
+ };
14904
+ const isString$1 = obj => typeof obj === 'string';
14905
+ const isObject = obj => typeof obj === 'object' && obj !== null;
14906
+
14907
+ const matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g;
14908
+ const htmlEntities = {
14909
+ '&amp;': '&',
14910
+ '&#38;': '&',
14911
+ '&lt;': '<',
14912
+ '&#60;': '<',
14913
+ '&gt;': '>',
14914
+ '&#62;': '>',
14915
+ '&apos;': "'",
14916
+ '&#39;': "'",
14917
+ '&quot;': '"',
14918
+ '&#34;': '"',
14919
+ '&nbsp;': ' ',
14920
+ '&#160;': ' ',
14921
+ '&copy;': '©',
14922
+ '&#169;': '©',
14923
+ '&reg;': '®',
14924
+ '&#174;': '®',
14925
+ '&hellip;': '…',
14926
+ '&#8230;': '…',
14927
+ '&#x2F;': '/',
14928
+ '&#47;': '/'
14929
+ };
14930
+ const unescapeHtmlEntity = m => htmlEntities[m];
14931
+ const unescape = text => text.replace(matchHtmlEntity, unescapeHtmlEntity);
14932
+
14933
+ let defaultOptions = {
14934
+ bindI18n: 'languageChanged',
14935
+ bindI18nStore: '',
14936
+ transEmptyNodeValue: '',
14937
+ transSupportBasicHtmlNodes: true,
14938
+ transWrapTextNodes: '',
14939
+ transKeepBasicHtmlNodesFor: ['br', 'strong', 'i', 'p'],
14940
+ useSuspense: true,
14941
+ unescape
14942
+ };
14943
+ const setDefaults = function () {
14944
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
14945
+ defaultOptions = {
14946
+ ...defaultOptions,
14947
+ ...options
14948
+ };
14949
+ };
14950
+ const getDefaults = () => defaultOptions;
14951
+
14952
+ let i18nInstance;
14953
+ const setI18n = instance => {
14954
+ i18nInstance = instance;
14955
+ };
14956
+ const getI18n = () => i18nInstance;
14957
+
14958
+ const initReactI18next = {
14959
+ type: '3rdParty',
14960
+ init(instance) {
14961
+ setDefaults(instance.options.react);
14962
+ setI18n(instance);
14963
+ }
14964
+ };
14965
+
14966
+ const I18nContext = React.createContext();
14967
+ class ReportNamespaces {
14968
+ constructor() {
14969
+ this.usedNamespaces = {};
14970
+ }
14971
+ addUsedNamespaces(namespaces) {
14972
+ namespaces.forEach(ns => {
14973
+ if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true;
14974
+ });
14975
+ }
14976
+ getUsedNamespaces = () => Object.keys(this.usedNamespaces);
14977
+ }
14978
+
14979
+ const usePrevious = (value, ignore) => {
14980
+ const ref = React.useRef();
14981
+ React.useEffect(() => {
14982
+ ref.current = ignore ? ref.current : value;
14983
+ }, [value, ignore]);
14984
+ return ref.current;
14985
+ };
14986
+ const alwaysNewT = (i18n, language, namespace, keyPrefix) => i18n.getFixedT(language, namespace, keyPrefix);
14987
+ const useMemoizedT = (i18n, language, namespace, keyPrefix) => React.useCallback(alwaysNewT(i18n, language, namespace, keyPrefix), [i18n, language, namespace, keyPrefix]);
14988
+ const useTranslation = function (ns) {
14989
+ let props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
14990
+ const {
14991
+ i18n: i18nFromProps
14992
+ } = props;
14993
+ const {
14994
+ i18n: i18nFromContext,
14995
+ defaultNS: defaultNSFromContext
14996
+ } = React.useContext(I18nContext) || {};
14997
+ const i18n = i18nFromProps || i18nFromContext || getI18n();
14998
+ if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
14999
+ if (!i18n) {
15000
+ warnOnce('You will need to pass in an i18next instance by using initReactI18next');
15001
+ const notReadyT = (k, optsOrDefaultValue) => {
15002
+ if (isString$1(optsOrDefaultValue)) return optsOrDefaultValue;
15003
+ if (isObject(optsOrDefaultValue) && isString$1(optsOrDefaultValue.defaultValue)) return optsOrDefaultValue.defaultValue;
15004
+ return Array.isArray(k) ? k[k.length - 1] : k;
15005
+ };
15006
+ const retNotReady = [notReadyT, {}, false];
15007
+ retNotReady.t = notReadyT;
15008
+ retNotReady.i18n = {};
15009
+ retNotReady.ready = false;
15010
+ return retNotReady;
15011
+ }
15012
+ 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.');
15013
+ const i18nOptions = {
15014
+ ...getDefaults(),
15015
+ ...i18n.options.react,
15016
+ ...props
15017
+ };
15018
+ const {
15019
+ useSuspense,
15020
+ keyPrefix
15021
+ } = i18nOptions;
15022
+ let namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
15023
+ namespaces = isString$1(namespaces) ? [namespaces] : namespaces || ['translation'];
15024
+ if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces);
15025
+ const ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(n => hasLoadedNamespace(n, i18n, i18nOptions));
15026
+ const memoGetT = useMemoizedT(i18n, props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix);
15027
+ const getT = () => memoGetT;
15028
+ const getNewT = () => alwaysNewT(i18n, props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix);
15029
+ const [t, setT] = React.useState(getT);
15030
+ let joinedNS = namespaces.join();
15031
+ if (props.lng) joinedNS = `${props.lng}${joinedNS}`;
15032
+ const previousJoinedNS = usePrevious(joinedNS);
15033
+ const isMounted = React.useRef(true);
15034
+ React.useEffect(() => {
15035
+ const {
15036
+ bindI18n,
15037
+ bindI18nStore
15038
+ } = i18nOptions;
15039
+ isMounted.current = true;
15040
+ if (!ready && !useSuspense) {
15041
+ if (props.lng) {
15042
+ loadLanguages(i18n, props.lng, namespaces, () => {
15043
+ if (isMounted.current) setT(getNewT);
15044
+ });
15045
+ } else {
15046
+ loadNamespaces(i18n, namespaces, () => {
15047
+ if (isMounted.current) setT(getNewT);
15048
+ });
15049
+ }
15050
+ }
15051
+ if (ready && previousJoinedNS && previousJoinedNS !== joinedNS && isMounted.current) {
15052
+ setT(getNewT);
15053
+ }
15054
+ const boundReset = () => {
15055
+ if (isMounted.current) setT(getNewT);
15056
+ };
15057
+ if (bindI18n && i18n) i18n.on(bindI18n, boundReset);
15058
+ if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset);
15059
+ return () => {
15060
+ isMounted.current = false;
15061
+ if (bindI18n && i18n) bindI18n.split(' ').forEach(e => i18n.off(e, boundReset));
15062
+ if (bindI18nStore && i18n) bindI18nStore.split(' ').forEach(e => i18n.store.off(e, boundReset));
15063
+ };
15064
+ }, [i18n, joinedNS]);
15065
+ React.useEffect(() => {
15066
+ if (isMounted.current && ready) {
15067
+ setT(getT);
15068
+ }
15069
+ }, [i18n, keyPrefix, ready]);
15070
+ const ret = [t, i18n, ready];
15071
+ ret.t = t;
15072
+ ret.i18n = i18n;
15073
+ ret.ready = ready;
15074
+ if (ready) return ret;
15075
+ if (!ready && !useSuspense) return ret;
15076
+ throw new Promise(resolve => {
15077
+ if (props.lng) {
15078
+ loadLanguages(i18n, props.lng, namespaces, () => resolve());
15079
+ } else {
15080
+ loadNamespaces(i18n, namespaces, () => resolve());
15081
+ }
15082
+ });
15083
+ };
15084
+
15085
+ const useContactInfoPopupTranslation = () => {
15086
+ const { t } = useTranslation();
15087
+ return {
15088
+ businessSection: {
15089
+ title: t('components.contactInfoPopup.businessSection.title'),
15090
+ description: t('components.contactInfoPopup.businessSection.description'),
15091
+ },
15092
+ contactMethod: {
15093
+ email: t('components.contactInfoPopup.contactMethod.email'),
15094
+ phone: t('components.contactInfoPopup.contactMethod.phone'),
15095
+ website: t('components.contactInfoPopup.contactMethod.website'),
15096
+ },
15097
+ labelsSection: {
15098
+ title: t('components.contactInfoPopup.labelsSection.title'),
15099
+ },
15100
+ membersSection: {
15101
+ title: t('components.contactInfoPopup.membersSection.title'),
15102
+ noMembers: t('components.contactInfoPopup.membersSection.noMembers'),
15103
+ },
15104
+ global: {
15105
+ properties: t('components.contactInfoPopup.global.properties'),
15106
+ business: t('components.contactInfoPopup.global.business'),
15107
+ businessMembers: t('components.contactInfoPopup.global.businessMembers'),
15108
+ labels: t('components.contactInfoPopup.global.labels'),
15109
+ },
15110
+ };
15111
+ };
15112
+
14834
15113
  const PopupContainer = material.styled(material.Box)(({ theme }) => ({
14835
15114
  //@ts-ignore
14836
15115
  backgroundColor: theme.palette.background.panel,
@@ -14858,50 +15137,40 @@ const PopupContainer = material.styled(material.Box)(({ theme }) => ({
14858
15137
  background: '#616161',
14859
15138
  },
14860
15139
  }));
14861
- const ContactInfoPopup = ({ open, anchorEl, onClose, contactData, avatarImgUrl, navigate, t = (key) => ({
14862
- labels: 'Etiquetas',
14863
- phone: 'Teléfono',
14864
- business: 'Empresa',
14865
- businessMembers: 'Miembros de la empresa',
14866
- properties: 'Propiedades',
14867
- view: 'Ver',
14868
- email: 'Correo Electrónico',
14869
- }[key] || key), }) => {
15140
+ const ContactInfoPopup = ({ open, anchorEl, onClose, contactData, avatarImgUrl, navigate, }) => {
14870
15141
  const dataIsBusiness = isBusiness(contactData);
14871
15142
  const dataIsContact = isContact(contactData);
15143
+ const translations = useContactInfoPopupTranslation();
14872
15144
  const contactMethods = [
14873
15145
  {
14874
15146
  icon: jsxRuntimeExports.jsx(PhoneEnabled, { fontSize: "small" }),
14875
- title: t('phone'),
15147
+ title: translations.contactMethod.phone,
14876
15148
  contactList: contactData?.phones || [],
14877
15149
  showTitle: true,
14878
15150
  },
14879
15151
  {
14880
15152
  icon: jsxRuntimeExports.jsx(Email, { fontSize: "small" }),
14881
- title: t('email'),
15153
+ title: translations.contactMethod.email,
14882
15154
  contactList: contactData?.emails || [],
14883
15155
  showTitle: true,
14884
15156
  },
14885
15157
  {
14886
15158
  icon: jsxRuntimeExports.jsx(WhatsApp, { fontSize: "small" }),
14887
- title: 'IM',
15159
+ title: 'WhatsApp',
14888
15160
  contactList: contactData?.ims_whatsapp || [],
14889
15161
  showTitle: true,
14890
15162
  },
14891
15163
  {
14892
15164
  icon: jsxRuntimeExports.jsx(Facebook, { fontSize: "small" }),
15165
+ title: 'Facebook',
14893
15166
  contactList: contactData?.ims_facebook || [],
14894
- showTitle: false,
15167
+ showTitle: true,
14895
15168
  },
14896
15169
  {
14897
15170
  icon: jsxRuntimeExports.jsx(Instagram, { fontSize: "small" }),
15171
+ title: 'Instagram',
14898
15172
  contactList: contactData?.ims_instagram || [],
14899
- showTitle: false,
14900
- },
14901
- {
14902
- icon: jsxRuntimeExports.jsx(ThreeP, { fontSize: "small" }),
14903
- contactList: contactData?.ims_webchat || [],
14904
- showTitle: false,
15173
+ showTitle: true,
14905
15174
  },
14906
15175
  ];
14907
15176
  React.useEffect(() => {
@@ -14917,9 +15186,2509 @@ const ContactInfoPopup = ({ open, anchorEl, onClose, contactData, avatarImgUrl,
14917
15186
  window.removeEventListener('keydown', handleKeyDown);
14918
15187
  };
14919
15188
  }, [open, onClose]);
14920
- return (jsxRuntimeExports.jsx(material.Popper, { sx: { zIndex: 1300 }, open: open, anchorEl: anchorEl, placement: "bottom-start", "data-popper-child": "true", children: jsxRuntimeExports.jsx(material.ClickAwayListener, { onClickAway: onClose, children: jsxRuntimeExports.jsx(PopupContainer, { children: jsxRuntimeExports.jsxs(material.CardContent, { children: [jsxRuntimeExports.jsx(Header, { navigate: navigate, contactId: contactData?.id, imgUrl: avatarImgUrl, name: contactData?.name }), jsxRuntimeExports.jsx(LabelsSection, { contactData: contactData, title: t('labels') }), dataIsContact && (jsxRuntimeExports.jsx(BusinessSection, { contactData: contactData, title: t('business') })), dataIsBusiness && (jsxRuntimeExports.jsx(MembersSection, { contactData: contactData, title: t('businessMembers') })), contactMethods.map((method, index) => (jsxRuntimeExports.jsx(ContactMethod, { icon: method.icon, title: method.title, contactList: method.contactList, showTitle: method.showTitle }, index))), jsxRuntimeExports.jsx(Properties, { properties: contactData?.properties, title: t('global.properties') })] }) }) }) }));
15189
+ return (jsxRuntimeExports.jsx(material.Popper, { sx: { zIndex: 1300 }, open: open, anchorEl: anchorEl, placement: "bottom-start", "data-popper-child": "true", children: jsxRuntimeExports.jsx(material.ClickAwayListener, { onClickAway: onClose, children: jsxRuntimeExports.jsx(PopupContainer, { children: jsxRuntimeExports.jsxs(material.CardContent, { children: [jsxRuntimeExports.jsx(Header, { contactId: contactData?.id, imgUrl: avatarImgUrl, name: contactData?.name, navigate: navigate }), jsxRuntimeExports.jsx(LabelsSection, { contactData: contactData, title: translations.global.labels }), dataIsContact && (jsxRuntimeExports.jsx(BusinessSection, { contactData: contactData, title: translations.global.business })), dataIsBusiness && (jsxRuntimeExports.jsx(MembersSection, { contactData: contactData, title: translations.global.businessMembers })), contactMethods.map((method, index) => (jsxRuntimeExports.jsx(ContactMethod, { icon: method.icon, title: method.title, contactList: method.contactList, showTitle: method.showTitle }, index))), jsxRuntimeExports.jsx(Properties, { properties: contactData?.properties, title: translations.global.properties })] }) }) }) }));
15190
+ };
15191
+
15192
+ const isString = obj => typeof obj === 'string';
15193
+ const defer = () => {
15194
+ let res;
15195
+ let rej;
15196
+ const promise = new Promise((resolve, reject) => {
15197
+ res = resolve;
15198
+ rej = reject;
15199
+ });
15200
+ promise.resolve = res;
15201
+ promise.reject = rej;
15202
+ return promise;
15203
+ };
15204
+ const makeString = object => {
15205
+ if (object == null) return '';
15206
+ return '' + object;
15207
+ };
15208
+ const copy = (a, s, t) => {
15209
+ a.forEach(m => {
15210
+ if (s[m]) t[m] = s[m];
15211
+ });
15212
+ };
15213
+ const lastOfPathSeparatorRegExp = /###/g;
15214
+ const cleanKey = key => key && key.indexOf('###') > -1 ? key.replace(lastOfPathSeparatorRegExp, '.') : key;
15215
+ const canNotTraverseDeeper = object => !object || isString(object);
15216
+ const getLastOfPath = (object, path, Empty) => {
15217
+ const stack = !isString(path) ? path : path.split('.');
15218
+ let stackIndex = 0;
15219
+ while (stackIndex < stack.length - 1) {
15220
+ if (canNotTraverseDeeper(object)) return {};
15221
+ const key = cleanKey(stack[stackIndex]);
15222
+ if (!object[key] && Empty) object[key] = new Empty();
15223
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
15224
+ object = object[key];
15225
+ } else {
15226
+ object = {};
15227
+ }
15228
+ ++stackIndex;
15229
+ }
15230
+ if (canNotTraverseDeeper(object)) return {};
15231
+ return {
15232
+ obj: object,
15233
+ k: cleanKey(stack[stackIndex])
15234
+ };
15235
+ };
15236
+ const setPath = (object, path, newValue) => {
15237
+ const {
15238
+ obj,
15239
+ k
15240
+ } = getLastOfPath(object, path, Object);
15241
+ if (obj !== undefined || path.length === 1) {
15242
+ obj[k] = newValue;
15243
+ return;
15244
+ }
15245
+ let e = path[path.length - 1];
15246
+ let p = path.slice(0, path.length - 1);
15247
+ let last = getLastOfPath(object, p, Object);
15248
+ while (last.obj === undefined && p.length) {
15249
+ e = `${p[p.length - 1]}.${e}`;
15250
+ p = p.slice(0, p.length - 1);
15251
+ last = getLastOfPath(object, p, Object);
15252
+ if (last && last.obj && typeof last.obj[`${last.k}.${e}`] !== 'undefined') {
15253
+ last.obj = undefined;
15254
+ }
15255
+ }
15256
+ last.obj[`${last.k}.${e}`] = newValue;
15257
+ };
15258
+ const pushPath = (object, path, newValue, concat) => {
15259
+ const {
15260
+ obj,
15261
+ k
15262
+ } = getLastOfPath(object, path, Object);
15263
+ obj[k] = obj[k] || [];
15264
+ obj[k].push(newValue);
15265
+ };
15266
+ const getPath = (object, path) => {
15267
+ const {
15268
+ obj,
15269
+ k
15270
+ } = getLastOfPath(object, path);
15271
+ if (!obj) return undefined;
15272
+ return obj[k];
15273
+ };
15274
+ const getPathWithDefaults = (data, defaultData, key) => {
15275
+ const value = getPath(data, key);
15276
+ if (value !== undefined) {
15277
+ return value;
15278
+ }
15279
+ return getPath(defaultData, key);
15280
+ };
15281
+ const deepExtend = (target, source, overwrite) => {
15282
+ for (const prop in source) {
15283
+ if (prop !== '__proto__' && prop !== 'constructor') {
15284
+ if (prop in target) {
15285
+ if (isString(target[prop]) || target[prop] instanceof String || isString(source[prop]) || source[prop] instanceof String) {
15286
+ if (overwrite) target[prop] = source[prop];
15287
+ } else {
15288
+ deepExtend(target[prop], source[prop], overwrite);
15289
+ }
15290
+ } else {
15291
+ target[prop] = source[prop];
15292
+ }
15293
+ }
15294
+ }
15295
+ return target;
15296
+ };
15297
+ const regexEscape = str => str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
15298
+ var _entityMap = {
15299
+ '&': '&amp;',
15300
+ '<': '&lt;',
15301
+ '>': '&gt;',
15302
+ '"': '&quot;',
15303
+ "'": '&#39;',
15304
+ '/': '&#x2F;'
15305
+ };
15306
+ const escape = data => {
15307
+ if (isString(data)) {
15308
+ return data.replace(/[&<>"'\/]/g, s => _entityMap[s]);
15309
+ }
15310
+ return data;
15311
+ };
15312
+ class RegExpCache {
15313
+ constructor(capacity) {
15314
+ this.capacity = capacity;
15315
+ this.regExpMap = new Map();
15316
+ this.regExpQueue = [];
15317
+ }
15318
+ getRegExp(pattern) {
15319
+ const regExpFromCache = this.regExpMap.get(pattern);
15320
+ if (regExpFromCache !== undefined) {
15321
+ return regExpFromCache;
15322
+ }
15323
+ const regExpNew = new RegExp(pattern);
15324
+ if (this.regExpQueue.length === this.capacity) {
15325
+ this.regExpMap.delete(this.regExpQueue.shift());
15326
+ }
15327
+ this.regExpMap.set(pattern, regExpNew);
15328
+ this.regExpQueue.push(pattern);
15329
+ return regExpNew;
15330
+ }
15331
+ }
15332
+ const chars = [' ', ',', '?', '!', ';'];
15333
+ const looksLikeObjectPathRegExpCache = new RegExpCache(20);
15334
+ const looksLikeObjectPath = (key, nsSeparator, keySeparator) => {
15335
+ nsSeparator = nsSeparator || '';
15336
+ keySeparator = keySeparator || '';
15337
+ const possibleChars = chars.filter(c => nsSeparator.indexOf(c) < 0 && keySeparator.indexOf(c) < 0);
15338
+ if (possibleChars.length === 0) return true;
15339
+ const r = looksLikeObjectPathRegExpCache.getRegExp(`(${possibleChars.map(c => c === '?' ? '\\?' : c).join('|')})`);
15340
+ let matched = !r.test(key);
15341
+ if (!matched) {
15342
+ const ki = key.indexOf(keySeparator);
15343
+ if (ki > 0 && !r.test(key.substring(0, ki))) {
15344
+ matched = true;
15345
+ }
15346
+ }
15347
+ return matched;
15348
+ };
15349
+ const deepFind = function (obj, path) {
15350
+ let keySeparator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '.';
15351
+ if (!obj) return undefined;
15352
+ if (obj[path]) return obj[path];
15353
+ const tokens = path.split(keySeparator);
15354
+ let current = obj;
15355
+ for (let i = 0; i < tokens.length;) {
15356
+ if (!current || typeof current !== 'object') {
15357
+ return undefined;
15358
+ }
15359
+ let next;
15360
+ let nextPath = '';
15361
+ for (let j = i; j < tokens.length; ++j) {
15362
+ if (j !== i) {
15363
+ nextPath += keySeparator;
15364
+ }
15365
+ nextPath += tokens[j];
15366
+ next = current[nextPath];
15367
+ if (next !== undefined) {
15368
+ if (['string', 'number', 'boolean'].indexOf(typeof next) > -1 && j < tokens.length - 1) {
15369
+ continue;
15370
+ }
15371
+ i += j - i + 1;
15372
+ break;
15373
+ }
15374
+ }
15375
+ current = next;
15376
+ }
15377
+ return current;
15378
+ };
15379
+ const getCleanedCode = code => code && code.replace('_', '-');
15380
+
15381
+ const consoleLogger = {
15382
+ type: 'logger',
15383
+ log(args) {
15384
+ this.output('log', args);
15385
+ },
15386
+ warn(args) {
15387
+ this.output('warn', args);
15388
+ },
15389
+ error(args) {
15390
+ this.output('error', args);
15391
+ },
15392
+ output(type, args) {
15393
+ if (console && console[type]) console[type].apply(console, args);
15394
+ }
15395
+ };
15396
+ class Logger {
15397
+ constructor(concreteLogger) {
15398
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
15399
+ this.init(concreteLogger, options);
15400
+ }
15401
+ init(concreteLogger) {
15402
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
15403
+ this.prefix = options.prefix || 'i18next:';
15404
+ this.logger = concreteLogger || consoleLogger;
15405
+ this.options = options;
15406
+ this.debug = options.debug;
15407
+ }
15408
+ log() {
15409
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
15410
+ args[_key] = arguments[_key];
15411
+ }
15412
+ return this.forward(args, 'log', '', true);
15413
+ }
15414
+ warn() {
15415
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
15416
+ args[_key2] = arguments[_key2];
15417
+ }
15418
+ return this.forward(args, 'warn', '', true);
15419
+ }
15420
+ error() {
15421
+ for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
15422
+ args[_key3] = arguments[_key3];
15423
+ }
15424
+ return this.forward(args, 'error', '');
15425
+ }
15426
+ deprecate() {
15427
+ for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
15428
+ args[_key4] = arguments[_key4];
15429
+ }
15430
+ return this.forward(args, 'warn', 'WARNING DEPRECATED: ', true);
15431
+ }
15432
+ forward(args, lvl, prefix, debugOnly) {
15433
+ if (debugOnly && !this.debug) return null;
15434
+ if (isString(args[0])) args[0] = `${prefix}${this.prefix} ${args[0]}`;
15435
+ return this.logger[lvl](args);
15436
+ }
15437
+ create(moduleName) {
15438
+ return new Logger(this.logger, {
15439
+ ...{
15440
+ prefix: `${this.prefix}:${moduleName}:`
15441
+ },
15442
+ ...this.options
15443
+ });
15444
+ }
15445
+ clone(options) {
15446
+ options = options || this.options;
15447
+ options.prefix = options.prefix || this.prefix;
15448
+ return new Logger(this.logger, options);
15449
+ }
15450
+ }
15451
+ var baseLogger = new Logger();
15452
+
15453
+ class EventEmitter {
15454
+ constructor() {
15455
+ this.observers = {};
15456
+ }
15457
+ on(events, listener) {
15458
+ events.split(' ').forEach(event => {
15459
+ if (!this.observers[event]) this.observers[event] = new Map();
15460
+ const numListeners = this.observers[event].get(listener) || 0;
15461
+ this.observers[event].set(listener, numListeners + 1);
15462
+ });
15463
+ return this;
15464
+ }
15465
+ off(event, listener) {
15466
+ if (!this.observers[event]) return;
15467
+ if (!listener) {
15468
+ delete this.observers[event];
15469
+ return;
15470
+ }
15471
+ this.observers[event].delete(listener);
15472
+ }
15473
+ emit(event) {
15474
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
15475
+ args[_key - 1] = arguments[_key];
15476
+ }
15477
+ if (this.observers[event]) {
15478
+ const cloned = Array.from(this.observers[event].entries());
15479
+ cloned.forEach(_ref => {
15480
+ let [observer, numTimesAdded] = _ref;
15481
+ for (let i = 0; i < numTimesAdded; i++) {
15482
+ observer(...args);
15483
+ }
15484
+ });
15485
+ }
15486
+ if (this.observers['*']) {
15487
+ const cloned = Array.from(this.observers['*'].entries());
15488
+ cloned.forEach(_ref2 => {
15489
+ let [observer, numTimesAdded] = _ref2;
15490
+ for (let i = 0; i < numTimesAdded; i++) {
15491
+ observer.apply(observer, [event, ...args]);
15492
+ }
15493
+ });
15494
+ }
15495
+ }
15496
+ }
15497
+
15498
+ class ResourceStore extends EventEmitter {
15499
+ constructor(data) {
15500
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
15501
+ ns: ['translation'],
15502
+ defaultNS: 'translation'
15503
+ };
15504
+ super();
15505
+ this.data = data || {};
15506
+ this.options = options;
15507
+ if (this.options.keySeparator === undefined) {
15508
+ this.options.keySeparator = '.';
15509
+ }
15510
+ if (this.options.ignoreJSONStructure === undefined) {
15511
+ this.options.ignoreJSONStructure = true;
15512
+ }
15513
+ }
15514
+ addNamespaces(ns) {
15515
+ if (this.options.ns.indexOf(ns) < 0) {
15516
+ this.options.ns.push(ns);
15517
+ }
15518
+ }
15519
+ removeNamespaces(ns) {
15520
+ const index = this.options.ns.indexOf(ns);
15521
+ if (index > -1) {
15522
+ this.options.ns.splice(index, 1);
15523
+ }
15524
+ }
15525
+ getResource(lng, ns, key) {
15526
+ let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
15527
+ const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
15528
+ const ignoreJSONStructure = options.ignoreJSONStructure !== undefined ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
15529
+ let path;
15530
+ if (lng.indexOf('.') > -1) {
15531
+ path = lng.split('.');
15532
+ } else {
15533
+ path = [lng, ns];
15534
+ if (key) {
15535
+ if (Array.isArray(key)) {
15536
+ path.push(...key);
15537
+ } else if (isString(key) && keySeparator) {
15538
+ path.push(...key.split(keySeparator));
15539
+ } else {
15540
+ path.push(key);
15541
+ }
15542
+ }
15543
+ }
15544
+ const result = getPath(this.data, path);
15545
+ if (!result && !ns && !key && lng.indexOf('.') > -1) {
15546
+ lng = path[0];
15547
+ ns = path[1];
15548
+ key = path.slice(2).join('.');
15549
+ }
15550
+ if (result || !ignoreJSONStructure || !isString(key)) return result;
15551
+ return deepFind(this.data && this.data[lng] && this.data[lng][ns], key, keySeparator);
15552
+ }
15553
+ addResource(lng, ns, key, value) {
15554
+ let options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
15555
+ silent: false
15556
+ };
15557
+ const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
15558
+ let path = [lng, ns];
15559
+ if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
15560
+ if (lng.indexOf('.') > -1) {
15561
+ path = lng.split('.');
15562
+ value = ns;
15563
+ ns = path[1];
15564
+ }
15565
+ this.addNamespaces(ns);
15566
+ setPath(this.data, path, value);
15567
+ if (!options.silent) this.emit('added', lng, ns, key, value);
15568
+ }
15569
+ addResources(lng, ns, resources) {
15570
+ let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
15571
+ silent: false
15572
+ };
15573
+ for (const m in resources) {
15574
+ if (isString(resources[m]) || Array.isArray(resources[m])) this.addResource(lng, ns, m, resources[m], {
15575
+ silent: true
15576
+ });
15577
+ }
15578
+ if (!options.silent) this.emit('added', lng, ns, resources);
15579
+ }
15580
+ addResourceBundle(lng, ns, resources, deep, overwrite) {
15581
+ let options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {
15582
+ silent: false,
15583
+ skipCopy: false
15584
+ };
15585
+ let path = [lng, ns];
15586
+ if (lng.indexOf('.') > -1) {
15587
+ path = lng.split('.');
15588
+ deep = resources;
15589
+ resources = ns;
15590
+ ns = path[1];
15591
+ }
15592
+ this.addNamespaces(ns);
15593
+ let pack = getPath(this.data, path) || {};
15594
+ if (!options.skipCopy) resources = JSON.parse(JSON.stringify(resources));
15595
+ if (deep) {
15596
+ deepExtend(pack, resources, overwrite);
15597
+ } else {
15598
+ pack = {
15599
+ ...pack,
15600
+ ...resources
15601
+ };
15602
+ }
15603
+ setPath(this.data, path, pack);
15604
+ if (!options.silent) this.emit('added', lng, ns, resources);
15605
+ }
15606
+ removeResourceBundle(lng, ns) {
15607
+ if (this.hasResourceBundle(lng, ns)) {
15608
+ delete this.data[lng][ns];
15609
+ }
15610
+ this.removeNamespaces(ns);
15611
+ this.emit('removed', lng, ns);
15612
+ }
15613
+ hasResourceBundle(lng, ns) {
15614
+ return this.getResource(lng, ns) !== undefined;
15615
+ }
15616
+ getResourceBundle(lng, ns) {
15617
+ if (!ns) ns = this.options.defaultNS;
15618
+ if (this.options.compatibilityAPI === 'v1') return {
15619
+ ...{},
15620
+ ...this.getResource(lng, ns)
15621
+ };
15622
+ return this.getResource(lng, ns);
15623
+ }
15624
+ getDataByLanguage(lng) {
15625
+ return this.data[lng];
15626
+ }
15627
+ hasLanguageSomeTranslations(lng) {
15628
+ const data = this.getDataByLanguage(lng);
15629
+ const n = data && Object.keys(data) || [];
15630
+ return !!n.find(v => data[v] && Object.keys(data[v]).length > 0);
15631
+ }
15632
+ toJSON() {
15633
+ return this.data;
15634
+ }
15635
+ }
15636
+
15637
+ var postProcessor = {
15638
+ processors: {},
15639
+ addPostProcessor(module) {
15640
+ this.processors[module.name] = module;
15641
+ },
15642
+ handle(processors, value, key, options, translator) {
15643
+ processors.forEach(processor => {
15644
+ if (this.processors[processor]) value = this.processors[processor].process(value, key, options, translator);
15645
+ });
15646
+ return value;
15647
+ }
15648
+ };
15649
+
15650
+ const checkedLoadedFor = {};
15651
+ class Translator extends EventEmitter {
15652
+ constructor(services) {
15653
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
15654
+ super();
15655
+ copy(['resourceStore', 'languageUtils', 'pluralResolver', 'interpolator', 'backendConnector', 'i18nFormat', 'utils'], services, this);
15656
+ this.options = options;
15657
+ if (this.options.keySeparator === undefined) {
15658
+ this.options.keySeparator = '.';
15659
+ }
15660
+ this.logger = baseLogger.create('translator');
15661
+ }
15662
+ changeLanguage(lng) {
15663
+ if (lng) this.language = lng;
15664
+ }
15665
+ exists(key) {
15666
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
15667
+ interpolation: {}
15668
+ };
15669
+ if (key === undefined || key === null) {
15670
+ return false;
15671
+ }
15672
+ const resolved = this.resolve(key, options);
15673
+ return resolved && resolved.res !== undefined;
15674
+ }
15675
+ extractFromKey(key, options) {
15676
+ let nsSeparator = options.nsSeparator !== undefined ? options.nsSeparator : this.options.nsSeparator;
15677
+ if (nsSeparator === undefined) nsSeparator = ':';
15678
+ const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
15679
+ let namespaces = options.ns || this.options.defaultNS || [];
15680
+ const wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
15681
+ const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !options.keySeparator && !this.options.userDefinedNsSeparator && !options.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
15682
+ if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
15683
+ const m = key.match(this.interpolator.nestingRegexp);
15684
+ if (m && m.length > 0) {
15685
+ return {
15686
+ key,
15687
+ namespaces: isString(namespaces) ? [namespaces] : namespaces
15688
+ };
15689
+ }
15690
+ const parts = key.split(nsSeparator);
15691
+ if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > -1) namespaces = parts.shift();
15692
+ key = parts.join(keySeparator);
15693
+ }
15694
+ return {
15695
+ key,
15696
+ namespaces: isString(namespaces) ? [namespaces] : namespaces
15697
+ };
15698
+ }
15699
+ translate(keys, options, lastKey) {
15700
+ if (typeof options !== 'object' && this.options.overloadTranslationOptionHandler) {
15701
+ options = this.options.overloadTranslationOptionHandler(arguments);
15702
+ }
15703
+ if (typeof options === 'object') options = {
15704
+ ...options
15705
+ };
15706
+ if (!options) options = {};
15707
+ if (keys === undefined || keys === null) return '';
15708
+ if (!Array.isArray(keys)) keys = [String(keys)];
15709
+ const returnDetails = options.returnDetails !== undefined ? options.returnDetails : this.options.returnDetails;
15710
+ const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
15711
+ const {
15712
+ key,
15713
+ namespaces
15714
+ } = this.extractFromKey(keys[keys.length - 1], options);
15715
+ const namespace = namespaces[namespaces.length - 1];
15716
+ const lng = options.lng || this.language;
15717
+ const appendNamespaceToCIMode = options.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
15718
+ if (lng && lng.toLowerCase() === 'cimode') {
15719
+ if (appendNamespaceToCIMode) {
15720
+ const nsSeparator = options.nsSeparator || this.options.nsSeparator;
15721
+ if (returnDetails) {
15722
+ return {
15723
+ res: `${namespace}${nsSeparator}${key}`,
15724
+ usedKey: key,
15725
+ exactUsedKey: key,
15726
+ usedLng: lng,
15727
+ usedNS: namespace,
15728
+ usedParams: this.getUsedParamsDetails(options)
15729
+ };
15730
+ }
15731
+ return `${namespace}${nsSeparator}${key}`;
15732
+ }
15733
+ if (returnDetails) {
15734
+ return {
15735
+ res: key,
15736
+ usedKey: key,
15737
+ exactUsedKey: key,
15738
+ usedLng: lng,
15739
+ usedNS: namespace,
15740
+ usedParams: this.getUsedParamsDetails(options)
15741
+ };
15742
+ }
15743
+ return key;
15744
+ }
15745
+ const resolved = this.resolve(keys, options);
15746
+ let res = resolved && resolved.res;
15747
+ const resUsedKey = resolved && resolved.usedKey || key;
15748
+ const resExactUsedKey = resolved && resolved.exactUsedKey || key;
15749
+ const resType = Object.prototype.toString.apply(res);
15750
+ const noObject = ['[object Number]', '[object Function]', '[object RegExp]'];
15751
+ const joinArrays = options.joinArrays !== undefined ? options.joinArrays : this.options.joinArrays;
15752
+ const handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
15753
+ const handleAsObject = !isString(res) && typeof res !== 'boolean' && typeof res !== 'number';
15754
+ if (handleAsObjectInI18nFormat && res && handleAsObject && noObject.indexOf(resType) < 0 && !(isString(joinArrays) && Array.isArray(res))) {
15755
+ if (!options.returnObjects && !this.options.returnObjects) {
15756
+ if (!this.options.returnedObjectHandler) {
15757
+ this.logger.warn('accessing an object - but returnObjects options is not enabled!');
15758
+ }
15759
+ const r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, res, {
15760
+ ...options,
15761
+ ns: namespaces
15762
+ }) : `key '${key} (${this.language})' returned an object instead of string.`;
15763
+ if (returnDetails) {
15764
+ resolved.res = r;
15765
+ resolved.usedParams = this.getUsedParamsDetails(options);
15766
+ return resolved;
15767
+ }
15768
+ return r;
15769
+ }
15770
+ if (keySeparator) {
15771
+ const resTypeIsArray = Array.isArray(res);
15772
+ const copy = resTypeIsArray ? [] : {};
15773
+ const newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
15774
+ for (const m in res) {
15775
+ if (Object.prototype.hasOwnProperty.call(res, m)) {
15776
+ const deepKey = `${newKeyToUse}${keySeparator}${m}`;
15777
+ copy[m] = this.translate(deepKey, {
15778
+ ...options,
15779
+ ...{
15780
+ joinArrays: false,
15781
+ ns: namespaces
15782
+ }
15783
+ });
15784
+ if (copy[m] === deepKey) copy[m] = res[m];
15785
+ }
15786
+ }
15787
+ res = copy;
15788
+ }
15789
+ } else if (handleAsObjectInI18nFormat && isString(joinArrays) && Array.isArray(res)) {
15790
+ res = res.join(joinArrays);
15791
+ if (res) res = this.extendTranslation(res, keys, options, lastKey);
15792
+ } else {
15793
+ let usedDefault = false;
15794
+ let usedKey = false;
15795
+ const needsPluralHandling = options.count !== undefined && !isString(options.count);
15796
+ const hasDefaultValue = Translator.hasDefaultValue(options);
15797
+ const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, options) : '';
15798
+ const defaultValueSuffixOrdinalFallback = options.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, {
15799
+ ordinal: false
15800
+ }) : '';
15801
+ const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0 && this.pluralResolver.shouldUseIntlApi();
15802
+ const defaultValue = needsZeroSuffixLookup && options[`defaultValue${this.options.pluralSeparator}zero`] || options[`defaultValue${defaultValueSuffix}`] || options[`defaultValue${defaultValueSuffixOrdinalFallback}`] || options.defaultValue;
15803
+ if (!this.isValidLookup(res) && hasDefaultValue) {
15804
+ usedDefault = true;
15805
+ res = defaultValue;
15806
+ }
15807
+ if (!this.isValidLookup(res)) {
15808
+ usedKey = true;
15809
+ res = key;
15810
+ }
15811
+ const missingKeyNoValueFallbackToKey = options.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
15812
+ const resForMissing = missingKeyNoValueFallbackToKey && usedKey ? undefined : res;
15813
+ const updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
15814
+ if (usedKey || usedDefault || updateMissing) {
15815
+ this.logger.log(updateMissing ? 'updateKey' : 'missingKey', lng, namespace, key, updateMissing ? defaultValue : res);
15816
+ if (keySeparator) {
15817
+ const fk = this.resolve(key, {
15818
+ ...options,
15819
+ keySeparator: false
15820
+ });
15821
+ if (fk && fk.res) this.logger.warn('Seems the loaded translations were in flat JSON format instead of nested. Either set keySeparator: false on init or make sure your translations are published in nested format.');
15822
+ }
15823
+ let lngs = [];
15824
+ const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, options.lng || this.language);
15825
+ if (this.options.saveMissingTo === 'fallback' && fallbackLngs && fallbackLngs[0]) {
15826
+ for (let i = 0; i < fallbackLngs.length; i++) {
15827
+ lngs.push(fallbackLngs[i]);
15828
+ }
15829
+ } else if (this.options.saveMissingTo === 'all') {
15830
+ lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language);
15831
+ } else {
15832
+ lngs.push(options.lng || this.language);
15833
+ }
15834
+ const send = (l, k, specificDefaultValue) => {
15835
+ const defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
15836
+ if (this.options.missingKeyHandler) {
15837
+ this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, options);
15838
+ } else if (this.backendConnector && this.backendConnector.saveMissing) {
15839
+ this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, options);
15840
+ }
15841
+ this.emit('missingKey', l, namespace, k, res);
15842
+ };
15843
+ if (this.options.saveMissing) {
15844
+ if (this.options.saveMissingPlurals && needsPluralHandling) {
15845
+ lngs.forEach(language => {
15846
+ const suffixes = this.pluralResolver.getSuffixes(language, options);
15847
+ if (needsZeroSuffixLookup && options[`defaultValue${this.options.pluralSeparator}zero`] && suffixes.indexOf(`${this.options.pluralSeparator}zero`) < 0) {
15848
+ suffixes.push(`${this.options.pluralSeparator}zero`);
15849
+ }
15850
+ suffixes.forEach(suffix => {
15851
+ send([language], key + suffix, options[`defaultValue${suffix}`] || defaultValue);
15852
+ });
15853
+ });
15854
+ } else {
15855
+ send(lngs, key, defaultValue);
15856
+ }
15857
+ }
15858
+ }
15859
+ res = this.extendTranslation(res, keys, options, resolved, lastKey);
15860
+ if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = `${namespace}:${key}`;
15861
+ if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
15862
+ if (this.options.compatibilityAPI !== 'v1') {
15863
+ res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}:${key}` : key, usedDefault ? res : undefined);
15864
+ } else {
15865
+ res = this.options.parseMissingKeyHandler(res);
15866
+ }
15867
+ }
15868
+ }
15869
+ if (returnDetails) {
15870
+ resolved.res = res;
15871
+ resolved.usedParams = this.getUsedParamsDetails(options);
15872
+ return resolved;
15873
+ }
15874
+ return res;
15875
+ }
15876
+ extendTranslation(res, key, options, resolved, lastKey) {
15877
+ var _this = this;
15878
+ if (this.i18nFormat && this.i18nFormat.parse) {
15879
+ res = this.i18nFormat.parse(res, {
15880
+ ...this.options.interpolation.defaultVariables,
15881
+ ...options
15882
+ }, options.lng || this.language || resolved.usedLng, resolved.usedNS, resolved.usedKey, {
15883
+ resolved
15884
+ });
15885
+ } else if (!options.skipInterpolation) {
15886
+ if (options.interpolation) this.interpolator.init({
15887
+ ...options,
15888
+ ...{
15889
+ interpolation: {
15890
+ ...this.options.interpolation,
15891
+ ...options.interpolation
15892
+ }
15893
+ }
15894
+ });
15895
+ const skipOnVariables = isString(res) && (options && options.interpolation && options.interpolation.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
15896
+ let nestBef;
15897
+ if (skipOnVariables) {
15898
+ const nb = res.match(this.interpolator.nestingRegexp);
15899
+ nestBef = nb && nb.length;
15900
+ }
15901
+ let data = options.replace && !isString(options.replace) ? options.replace : options;
15902
+ if (this.options.interpolation.defaultVariables) data = {
15903
+ ...this.options.interpolation.defaultVariables,
15904
+ ...data
15905
+ };
15906
+ res = this.interpolator.interpolate(res, data, options.lng || this.language || resolved.usedLng, options);
15907
+ if (skipOnVariables) {
15908
+ const na = res.match(this.interpolator.nestingRegexp);
15909
+ const nestAft = na && na.length;
15910
+ if (nestBef < nestAft) options.nest = false;
15911
+ }
15912
+ if (!options.lng && this.options.compatibilityAPI !== 'v1' && resolved && resolved.res) options.lng = this.language || resolved.usedLng;
15913
+ if (options.nest !== false) res = this.interpolator.nest(res, function () {
15914
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
15915
+ args[_key] = arguments[_key];
15916
+ }
15917
+ if (lastKey && lastKey[0] === args[0] && !options.context) {
15918
+ _this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
15919
+ return null;
15920
+ }
15921
+ return _this.translate(...args, key);
15922
+ }, options);
15923
+ if (options.interpolation) this.interpolator.reset();
15924
+ }
15925
+ const postProcess = options.postProcess || this.options.postProcess;
15926
+ const postProcessorNames = isString(postProcess) ? [postProcess] : postProcess;
15927
+ if (res !== undefined && res !== null && postProcessorNames && postProcessorNames.length && options.applyPostProcessor !== false) {
15928
+ res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? {
15929
+ i18nResolved: {
15930
+ ...resolved,
15931
+ usedParams: this.getUsedParamsDetails(options)
15932
+ },
15933
+ ...options
15934
+ } : options, this);
15935
+ }
15936
+ return res;
15937
+ }
15938
+ resolve(keys) {
15939
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
15940
+ let found;
15941
+ let usedKey;
15942
+ let exactUsedKey;
15943
+ let usedLng;
15944
+ let usedNS;
15945
+ if (isString(keys)) keys = [keys];
15946
+ keys.forEach(k => {
15947
+ if (this.isValidLookup(found)) return;
15948
+ const extracted = this.extractFromKey(k, options);
15949
+ const key = extracted.key;
15950
+ usedKey = key;
15951
+ let namespaces = extracted.namespaces;
15952
+ if (this.options.fallbackNS) namespaces = namespaces.concat(this.options.fallbackNS);
15953
+ const needsPluralHandling = options.count !== undefined && !isString(options.count);
15954
+ const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0 && this.pluralResolver.shouldUseIntlApi();
15955
+ const needsContextHandling = options.context !== undefined && (isString(options.context) || typeof options.context === 'number') && options.context !== '';
15956
+ const codes = options.lngs ? options.lngs : this.languageUtils.toResolveHierarchy(options.lng || this.language, options.fallbackLng);
15957
+ namespaces.forEach(ns => {
15958
+ if (this.isValidLookup(found)) return;
15959
+ usedNS = ns;
15960
+ if (!checkedLoadedFor[`${codes[0]}-${ns}`] && this.utils && this.utils.hasLoadedNamespace && !this.utils.hasLoadedNamespace(usedNS)) {
15961
+ checkedLoadedFor[`${codes[0]}-${ns}`] = true;
15962
+ this.logger.warn(`key "${usedKey}" for languages "${codes.join(', ')}" won't get resolved as namespace "${usedNS}" was not yet loaded`, 'This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!');
15963
+ }
15964
+ codes.forEach(code => {
15965
+ if (this.isValidLookup(found)) return;
15966
+ usedLng = code;
15967
+ const finalKeys = [key];
15968
+ if (this.i18nFormat && this.i18nFormat.addLookupKeys) {
15969
+ this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, options);
15970
+ } else {
15971
+ let pluralSuffix;
15972
+ if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code, options.count, options);
15973
+ const zeroSuffix = `${this.options.pluralSeparator}zero`;
15974
+ const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
15975
+ if (needsPluralHandling) {
15976
+ finalKeys.push(key + pluralSuffix);
15977
+ if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
15978
+ finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
15979
+ }
15980
+ if (needsZeroSuffixLookup) {
15981
+ finalKeys.push(key + zeroSuffix);
15982
+ }
15983
+ }
15984
+ if (needsContextHandling) {
15985
+ const contextKey = `${key}${this.options.contextSeparator}${options.context}`;
15986
+ finalKeys.push(contextKey);
15987
+ if (needsPluralHandling) {
15988
+ finalKeys.push(contextKey + pluralSuffix);
15989
+ if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
15990
+ finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
15991
+ }
15992
+ if (needsZeroSuffixLookup) {
15993
+ finalKeys.push(contextKey + zeroSuffix);
15994
+ }
15995
+ }
15996
+ }
15997
+ }
15998
+ let possibleKey;
15999
+ while (possibleKey = finalKeys.pop()) {
16000
+ if (!this.isValidLookup(found)) {
16001
+ exactUsedKey = possibleKey;
16002
+ found = this.getResource(code, ns, possibleKey, options);
16003
+ }
16004
+ }
16005
+ });
16006
+ });
16007
+ });
16008
+ return {
16009
+ res: found,
16010
+ usedKey,
16011
+ exactUsedKey,
16012
+ usedLng,
16013
+ usedNS
16014
+ };
16015
+ }
16016
+ isValidLookup(res) {
16017
+ return res !== undefined && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === '');
16018
+ }
16019
+ getResource(code, ns, key) {
16020
+ let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
16021
+ if (this.i18nFormat && this.i18nFormat.getResource) return this.i18nFormat.getResource(code, ns, key, options);
16022
+ return this.resourceStore.getResource(code, ns, key, options);
16023
+ }
16024
+ getUsedParamsDetails() {
16025
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
16026
+ const optionsKeys = ['defaultValue', 'ordinal', 'context', 'replace', 'lng', 'lngs', 'fallbackLng', 'ns', 'keySeparator', 'nsSeparator', 'returnObjects', 'returnDetails', 'joinArrays', 'postProcess', 'interpolation'];
16027
+ const useOptionsReplaceForData = options.replace && !isString(options.replace);
16028
+ let data = useOptionsReplaceForData ? options.replace : options;
16029
+ if (useOptionsReplaceForData && typeof options.count !== 'undefined') {
16030
+ data.count = options.count;
16031
+ }
16032
+ if (this.options.interpolation.defaultVariables) {
16033
+ data = {
16034
+ ...this.options.interpolation.defaultVariables,
16035
+ ...data
16036
+ };
16037
+ }
16038
+ if (!useOptionsReplaceForData) {
16039
+ data = {
16040
+ ...data
16041
+ };
16042
+ for (const key of optionsKeys) {
16043
+ delete data[key];
16044
+ }
16045
+ }
16046
+ return data;
16047
+ }
16048
+ static hasDefaultValue(options) {
16049
+ const prefix = 'defaultValue';
16050
+ for (const option in options) {
16051
+ if (Object.prototype.hasOwnProperty.call(options, option) && prefix === option.substring(0, prefix.length) && undefined !== options[option]) {
16052
+ return true;
16053
+ }
16054
+ }
16055
+ return false;
16056
+ }
16057
+ }
16058
+
16059
+ const capitalize = string => string.charAt(0).toUpperCase() + string.slice(1);
16060
+ class LanguageUtil {
16061
+ constructor(options) {
16062
+ this.options = options;
16063
+ this.supportedLngs = this.options.supportedLngs || false;
16064
+ this.logger = baseLogger.create('languageUtils');
16065
+ }
16066
+ getScriptPartFromCode(code) {
16067
+ code = getCleanedCode(code);
16068
+ if (!code || code.indexOf('-') < 0) return null;
16069
+ const p = code.split('-');
16070
+ if (p.length === 2) return null;
16071
+ p.pop();
16072
+ if (p[p.length - 1].toLowerCase() === 'x') return null;
16073
+ return this.formatLanguageCode(p.join('-'));
16074
+ }
16075
+ getLanguagePartFromCode(code) {
16076
+ code = getCleanedCode(code);
16077
+ if (!code || code.indexOf('-') < 0) return code;
16078
+ const p = code.split('-');
16079
+ return this.formatLanguageCode(p[0]);
16080
+ }
16081
+ formatLanguageCode(code) {
16082
+ if (isString(code) && code.indexOf('-') > -1) {
16083
+ if (typeof Intl !== 'undefined' && typeof Intl.getCanonicalLocales !== 'undefined') {
16084
+ try {
16085
+ let formattedCode = Intl.getCanonicalLocales(code)[0];
16086
+ if (formattedCode && this.options.lowerCaseLng) {
16087
+ formattedCode = formattedCode.toLowerCase();
16088
+ }
16089
+ if (formattedCode) return formattedCode;
16090
+ } catch (e) {}
16091
+ }
16092
+ const specialCases = ['hans', 'hant', 'latn', 'cyrl', 'cans', 'mong', 'arab'];
16093
+ let p = code.split('-');
16094
+ if (this.options.lowerCaseLng) {
16095
+ p = p.map(part => part.toLowerCase());
16096
+ } else if (p.length === 2) {
16097
+ p[0] = p[0].toLowerCase();
16098
+ p[1] = p[1].toUpperCase();
16099
+ if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
16100
+ } else if (p.length === 3) {
16101
+ p[0] = p[0].toLowerCase();
16102
+ if (p[1].length === 2) p[1] = p[1].toUpperCase();
16103
+ if (p[0] !== 'sgn' && p[2].length === 2) p[2] = p[2].toUpperCase();
16104
+ if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
16105
+ if (specialCases.indexOf(p[2].toLowerCase()) > -1) p[2] = capitalize(p[2].toLowerCase());
16106
+ }
16107
+ return p.join('-');
16108
+ }
16109
+ return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
16110
+ }
16111
+ isSupportedCode(code) {
16112
+ if (this.options.load === 'languageOnly' || this.options.nonExplicitSupportedLngs) {
16113
+ code = this.getLanguagePartFromCode(code);
16114
+ }
16115
+ return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.indexOf(code) > -1;
16116
+ }
16117
+ getBestMatchFromCodes(codes) {
16118
+ if (!codes) return null;
16119
+ let found;
16120
+ codes.forEach(code => {
16121
+ if (found) return;
16122
+ const cleanedLng = this.formatLanguageCode(code);
16123
+ if (!this.options.supportedLngs || this.isSupportedCode(cleanedLng)) found = cleanedLng;
16124
+ });
16125
+ if (!found && this.options.supportedLngs) {
16126
+ codes.forEach(code => {
16127
+ if (found) return;
16128
+ const lngOnly = this.getLanguagePartFromCode(code);
16129
+ if (this.isSupportedCode(lngOnly)) return found = lngOnly;
16130
+ found = this.options.supportedLngs.find(supportedLng => {
16131
+ if (supportedLng === lngOnly) return supportedLng;
16132
+ if (supportedLng.indexOf('-') < 0 && lngOnly.indexOf('-') < 0) return;
16133
+ if (supportedLng.indexOf('-') > 0 && lngOnly.indexOf('-') < 0 && supportedLng.substring(0, supportedLng.indexOf('-')) === lngOnly) return supportedLng;
16134
+ if (supportedLng.indexOf(lngOnly) === 0 && lngOnly.length > 1) return supportedLng;
16135
+ });
16136
+ });
16137
+ }
16138
+ if (!found) found = this.getFallbackCodes(this.options.fallbackLng)[0];
16139
+ return found;
16140
+ }
16141
+ getFallbackCodes(fallbacks, code) {
16142
+ if (!fallbacks) return [];
16143
+ if (typeof fallbacks === 'function') fallbacks = fallbacks(code);
16144
+ if (isString(fallbacks)) fallbacks = [fallbacks];
16145
+ if (Array.isArray(fallbacks)) return fallbacks;
16146
+ if (!code) return fallbacks.default || [];
16147
+ let found = fallbacks[code];
16148
+ if (!found) found = fallbacks[this.getScriptPartFromCode(code)];
16149
+ if (!found) found = fallbacks[this.formatLanguageCode(code)];
16150
+ if (!found) found = fallbacks[this.getLanguagePartFromCode(code)];
16151
+ if (!found) found = fallbacks.default;
16152
+ return found || [];
16153
+ }
16154
+ toResolveHierarchy(code, fallbackCode) {
16155
+ const fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [], code);
16156
+ const codes = [];
16157
+ const addCode = c => {
16158
+ if (!c) return;
16159
+ if (this.isSupportedCode(c)) {
16160
+ codes.push(c);
16161
+ } else {
16162
+ this.logger.warn(`rejecting language code not found in supportedLngs: ${c}`);
16163
+ }
16164
+ };
16165
+ if (isString(code) && (code.indexOf('-') > -1 || code.indexOf('_') > -1)) {
16166
+ if (this.options.load !== 'languageOnly') addCode(this.formatLanguageCode(code));
16167
+ if (this.options.load !== 'languageOnly' && this.options.load !== 'currentOnly') addCode(this.getScriptPartFromCode(code));
16168
+ if (this.options.load !== 'currentOnly') addCode(this.getLanguagePartFromCode(code));
16169
+ } else if (isString(code)) {
16170
+ addCode(this.formatLanguageCode(code));
16171
+ }
16172
+ fallbackCodes.forEach(fc => {
16173
+ if (codes.indexOf(fc) < 0) addCode(this.formatLanguageCode(fc));
16174
+ });
16175
+ return codes;
16176
+ }
16177
+ }
16178
+
16179
+ let sets = [{
16180
+ lngs: ['ach', 'ak', 'am', 'arn', 'br', 'fil', 'gun', 'ln', 'mfe', 'mg', 'mi', 'oc', 'pt', 'pt-BR', 'tg', 'tl', 'ti', 'tr', 'uz', 'wa'],
16181
+ nr: [1, 2],
16182
+ fc: 1
16183
+ }, {
16184
+ lngs: ['af', 'an', 'ast', 'az', 'bg', 'bn', 'ca', 'da', 'de', 'dev', 'el', 'en', 'eo', 'es', 'et', 'eu', 'fi', 'fo', 'fur', 'fy', 'gl', 'gu', 'ha', 'hi', 'hu', 'hy', 'ia', 'it', 'kk', 'kn', 'ku', 'lb', 'mai', 'ml', 'mn', 'mr', 'nah', 'nap', 'nb', 'ne', 'nl', 'nn', 'no', 'nso', 'pa', 'pap', 'pms', 'ps', 'pt-PT', 'rm', 'sco', 'se', 'si', 'so', 'son', 'sq', 'sv', 'sw', 'ta', 'te', 'tk', 'ur', 'yo'],
16185
+ nr: [1, 2],
16186
+ fc: 2
16187
+ }, {
16188
+ lngs: ['ay', 'bo', 'cgg', 'fa', 'ht', 'id', 'ja', 'jbo', 'ka', 'km', 'ko', 'ky', 'lo', 'ms', 'sah', 'su', 'th', 'tt', 'ug', 'vi', 'wo', 'zh'],
16189
+ nr: [1],
16190
+ fc: 3
16191
+ }, {
16192
+ lngs: ['be', 'bs', 'cnr', 'dz', 'hr', 'ru', 'sr', 'uk'],
16193
+ nr: [1, 2, 5],
16194
+ fc: 4
16195
+ }, {
16196
+ lngs: ['ar'],
16197
+ nr: [0, 1, 2, 3, 11, 100],
16198
+ fc: 5
16199
+ }, {
16200
+ lngs: ['cs', 'sk'],
16201
+ nr: [1, 2, 5],
16202
+ fc: 6
16203
+ }, {
16204
+ lngs: ['csb', 'pl'],
16205
+ nr: [1, 2, 5],
16206
+ fc: 7
16207
+ }, {
16208
+ lngs: ['cy'],
16209
+ nr: [1, 2, 3, 8],
16210
+ fc: 8
16211
+ }, {
16212
+ lngs: ['fr'],
16213
+ nr: [1, 2],
16214
+ fc: 9
16215
+ }, {
16216
+ lngs: ['ga'],
16217
+ nr: [1, 2, 3, 7, 11],
16218
+ fc: 10
16219
+ }, {
16220
+ lngs: ['gd'],
16221
+ nr: [1, 2, 3, 20],
16222
+ fc: 11
16223
+ }, {
16224
+ lngs: ['is'],
16225
+ nr: [1, 2],
16226
+ fc: 12
16227
+ }, {
16228
+ lngs: ['jv'],
16229
+ nr: [0, 1],
16230
+ fc: 13
16231
+ }, {
16232
+ lngs: ['kw'],
16233
+ nr: [1, 2, 3, 4],
16234
+ fc: 14
16235
+ }, {
16236
+ lngs: ['lt'],
16237
+ nr: [1, 2, 10],
16238
+ fc: 15
16239
+ }, {
16240
+ lngs: ['lv'],
16241
+ nr: [1, 2, 0],
16242
+ fc: 16
16243
+ }, {
16244
+ lngs: ['mk'],
16245
+ nr: [1, 2],
16246
+ fc: 17
16247
+ }, {
16248
+ lngs: ['mnk'],
16249
+ nr: [0, 1, 2],
16250
+ fc: 18
16251
+ }, {
16252
+ lngs: ['mt'],
16253
+ nr: [1, 2, 11, 20],
16254
+ fc: 19
16255
+ }, {
16256
+ lngs: ['or'],
16257
+ nr: [2, 1],
16258
+ fc: 2
16259
+ }, {
16260
+ lngs: ['ro'],
16261
+ nr: [1, 2, 20],
16262
+ fc: 20
16263
+ }, {
16264
+ lngs: ['sl'],
16265
+ nr: [5, 1, 2, 3],
16266
+ fc: 21
16267
+ }, {
16268
+ lngs: ['he', 'iw'],
16269
+ nr: [1, 2, 20, 21],
16270
+ fc: 22
16271
+ }];
16272
+ let _rulesPluralsTypes = {
16273
+ 1: n => Number(n > 1),
16274
+ 2: n => Number(n != 1),
16275
+ 3: n => 0,
16276
+ 4: n => Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2),
16277
+ 5: n => Number(n == 0 ? 0 : n == 1 ? 1 : n == 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5),
16278
+ 6: n => Number(n == 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2),
16279
+ 7: n => Number(n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2),
16280
+ 8: n => Number(n == 1 ? 0 : n == 2 ? 1 : n != 8 && n != 11 ? 2 : 3),
16281
+ 9: n => Number(n >= 2),
16282
+ 10: n => Number(n == 1 ? 0 : n == 2 ? 1 : n < 7 ? 2 : n < 11 ? 3 : 4),
16283
+ 11: n => Number(n == 1 || n == 11 ? 0 : n == 2 || n == 12 ? 1 : n > 2 && n < 20 ? 2 : 3),
16284
+ 12: n => Number(n % 10 != 1 || n % 100 == 11),
16285
+ 13: n => Number(n !== 0),
16286
+ 14: n => Number(n == 1 ? 0 : n == 2 ? 1 : n == 3 ? 2 : 3),
16287
+ 15: n => Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2),
16288
+ 16: n => Number(n % 10 == 1 && n % 100 != 11 ? 0 : n !== 0 ? 1 : 2),
16289
+ 17: n => Number(n == 1 || n % 10 == 1 && n % 100 != 11 ? 0 : 1),
16290
+ 18: n => Number(n == 0 ? 0 : n == 1 ? 1 : 2),
16291
+ 19: n => Number(n == 1 ? 0 : n == 0 || n % 100 > 1 && n % 100 < 11 ? 1 : n % 100 > 10 && n % 100 < 20 ? 2 : 3),
16292
+ 20: n => Number(n == 1 ? 0 : n == 0 || n % 100 > 0 && n % 100 < 20 ? 1 : 2),
16293
+ 21: n => Number(n % 100 == 1 ? 1 : n % 100 == 2 ? 2 : n % 100 == 3 || n % 100 == 4 ? 3 : 0),
16294
+ 22: n => Number(n == 1 ? 0 : n == 2 ? 1 : (n < 0 || n > 10) && n % 10 == 0 ? 2 : 3)
16295
+ };
16296
+ const nonIntlVersions = ['v1', 'v2', 'v3'];
16297
+ const intlVersions = ['v4'];
16298
+ const suffixesOrder = {
16299
+ zero: 0,
16300
+ one: 1,
16301
+ two: 2,
16302
+ few: 3,
16303
+ many: 4,
16304
+ other: 5
16305
+ };
16306
+ const createRules = () => {
16307
+ const rules = {};
16308
+ sets.forEach(set => {
16309
+ set.lngs.forEach(l => {
16310
+ rules[l] = {
16311
+ numbers: set.nr,
16312
+ plurals: _rulesPluralsTypes[set.fc]
16313
+ };
16314
+ });
16315
+ });
16316
+ return rules;
16317
+ };
16318
+ class PluralResolver {
16319
+ constructor(languageUtils) {
16320
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
16321
+ this.languageUtils = languageUtils;
16322
+ this.options = options;
16323
+ this.logger = baseLogger.create('pluralResolver');
16324
+ if ((!this.options.compatibilityJSON || intlVersions.includes(this.options.compatibilityJSON)) && (typeof Intl === 'undefined' || !Intl.PluralRules)) {
16325
+ this.options.compatibilityJSON = 'v3';
16326
+ this.logger.error('Your environment seems not to be Intl API compatible, use an Intl.PluralRules polyfill. Will fallback to the compatibilityJSON v3 format handling.');
16327
+ }
16328
+ this.rules = createRules();
16329
+ this.pluralRulesCache = {};
16330
+ }
16331
+ addRule(lng, obj) {
16332
+ this.rules[lng] = obj;
16333
+ }
16334
+ clearCache() {
16335
+ this.pluralRulesCache = {};
16336
+ }
16337
+ getRule(code) {
16338
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
16339
+ if (this.shouldUseIntlApi()) {
16340
+ const cleanedCode = getCleanedCode(code === 'dev' ? 'en' : code);
16341
+ const type = options.ordinal ? 'ordinal' : 'cardinal';
16342
+ const cacheKey = JSON.stringify({
16343
+ cleanedCode,
16344
+ type
16345
+ });
16346
+ if (cacheKey in this.pluralRulesCache) {
16347
+ return this.pluralRulesCache[cacheKey];
16348
+ }
16349
+ let rule;
16350
+ try {
16351
+ rule = new Intl.PluralRules(cleanedCode, {
16352
+ type
16353
+ });
16354
+ } catch (err) {
16355
+ if (!code.match(/-|_/)) return;
16356
+ const lngPart = this.languageUtils.getLanguagePartFromCode(code);
16357
+ rule = this.getRule(lngPart, options);
16358
+ }
16359
+ this.pluralRulesCache[cacheKey] = rule;
16360
+ return rule;
16361
+ }
16362
+ return this.rules[code] || this.rules[this.languageUtils.getLanguagePartFromCode(code)];
16363
+ }
16364
+ needsPlural(code) {
16365
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
16366
+ const rule = this.getRule(code, options);
16367
+ if (this.shouldUseIntlApi()) {
16368
+ return rule && rule.resolvedOptions().pluralCategories.length > 1;
16369
+ }
16370
+ return rule && rule.numbers.length > 1;
16371
+ }
16372
+ getPluralFormsOfKey(code, key) {
16373
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
16374
+ return this.getSuffixes(code, options).map(suffix => `${key}${suffix}`);
16375
+ }
16376
+ getSuffixes(code) {
16377
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
16378
+ const rule = this.getRule(code, options);
16379
+ if (!rule) {
16380
+ return [];
16381
+ }
16382
+ if (this.shouldUseIntlApi()) {
16383
+ return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map(pluralCategory => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ''}${pluralCategory}`);
16384
+ }
16385
+ return rule.numbers.map(number => this.getSuffix(code, number, options));
16386
+ }
16387
+ getSuffix(code, count) {
16388
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
16389
+ const rule = this.getRule(code, options);
16390
+ if (rule) {
16391
+ if (this.shouldUseIntlApi()) {
16392
+ return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ''}${rule.select(count)}`;
16393
+ }
16394
+ return this.getSuffixRetroCompatible(rule, count);
16395
+ }
16396
+ this.logger.warn(`no plural rule found for: ${code}`);
16397
+ return '';
16398
+ }
16399
+ getSuffixRetroCompatible(rule, count) {
16400
+ const idx = rule.noAbs ? rule.plurals(count) : rule.plurals(Math.abs(count));
16401
+ let suffix = rule.numbers[idx];
16402
+ if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
16403
+ if (suffix === 2) {
16404
+ suffix = 'plural';
16405
+ } else if (suffix === 1) {
16406
+ suffix = '';
16407
+ }
16408
+ }
16409
+ const returnSuffix = () => this.options.prepend && suffix.toString() ? this.options.prepend + suffix.toString() : suffix.toString();
16410
+ if (this.options.compatibilityJSON === 'v1') {
16411
+ if (suffix === 1) return '';
16412
+ if (typeof suffix === 'number') return `_plural_${suffix.toString()}`;
16413
+ return returnSuffix();
16414
+ } else if (this.options.compatibilityJSON === 'v2') {
16415
+ return returnSuffix();
16416
+ } else if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
16417
+ return returnSuffix();
16418
+ }
16419
+ return this.options.prepend && idx.toString() ? this.options.prepend + idx.toString() : idx.toString();
16420
+ }
16421
+ shouldUseIntlApi() {
16422
+ return !nonIntlVersions.includes(this.options.compatibilityJSON);
16423
+ }
16424
+ }
16425
+
16426
+ const deepFindWithDefaults = function (data, defaultData, key) {
16427
+ let keySeparator = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '.';
16428
+ let ignoreJSONStructure = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
16429
+ let path = getPathWithDefaults(data, defaultData, key);
16430
+ if (!path && ignoreJSONStructure && isString(key)) {
16431
+ path = deepFind(data, key, keySeparator);
16432
+ if (path === undefined) path = deepFind(defaultData, key, keySeparator);
16433
+ }
16434
+ return path;
16435
+ };
16436
+ const regexSafe = val => val.replace(/\$/g, '$$$$');
16437
+ class Interpolator {
16438
+ constructor() {
16439
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
16440
+ this.logger = baseLogger.create('interpolator');
16441
+ this.options = options;
16442
+ this.format = options.interpolation && options.interpolation.format || (value => value);
16443
+ this.init(options);
16444
+ }
16445
+ init() {
16446
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
16447
+ if (!options.interpolation) options.interpolation = {
16448
+ escapeValue: true
16449
+ };
16450
+ const {
16451
+ escape: escape$1,
16452
+ escapeValue,
16453
+ useRawValueToEscape,
16454
+ prefix,
16455
+ prefixEscaped,
16456
+ suffix,
16457
+ suffixEscaped,
16458
+ formatSeparator,
16459
+ unescapeSuffix,
16460
+ unescapePrefix,
16461
+ nestingPrefix,
16462
+ nestingPrefixEscaped,
16463
+ nestingSuffix,
16464
+ nestingSuffixEscaped,
16465
+ nestingOptionsSeparator,
16466
+ maxReplaces,
16467
+ alwaysFormat
16468
+ } = options.interpolation;
16469
+ this.escape = escape$1 !== undefined ? escape$1 : escape;
16470
+ this.escapeValue = escapeValue !== undefined ? escapeValue : true;
16471
+ this.useRawValueToEscape = useRawValueToEscape !== undefined ? useRawValueToEscape : false;
16472
+ this.prefix = prefix ? regexEscape(prefix) : prefixEscaped || '{{';
16473
+ this.suffix = suffix ? regexEscape(suffix) : suffixEscaped || '}}';
16474
+ this.formatSeparator = formatSeparator || ',';
16475
+ this.unescapePrefix = unescapeSuffix ? '' : unescapePrefix || '-';
16476
+ this.unescapeSuffix = this.unescapePrefix ? '' : unescapeSuffix || '';
16477
+ this.nestingPrefix = nestingPrefix ? regexEscape(nestingPrefix) : nestingPrefixEscaped || regexEscape('$t(');
16478
+ this.nestingSuffix = nestingSuffix ? regexEscape(nestingSuffix) : nestingSuffixEscaped || regexEscape(')');
16479
+ this.nestingOptionsSeparator = nestingOptionsSeparator || ',';
16480
+ this.maxReplaces = maxReplaces || 1000;
16481
+ this.alwaysFormat = alwaysFormat !== undefined ? alwaysFormat : false;
16482
+ this.resetRegExp();
16483
+ }
16484
+ reset() {
16485
+ if (this.options) this.init(this.options);
16486
+ }
16487
+ resetRegExp() {
16488
+ const getOrResetRegExp = (existingRegExp, pattern) => {
16489
+ if (existingRegExp && existingRegExp.source === pattern) {
16490
+ existingRegExp.lastIndex = 0;
16491
+ return existingRegExp;
16492
+ }
16493
+ return new RegExp(pattern, 'g');
16494
+ };
16495
+ this.regexp = getOrResetRegExp(this.regexp, `${this.prefix}(.+?)${this.suffix}`);
16496
+ this.regexpUnescape = getOrResetRegExp(this.regexpUnescape, `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`);
16497
+ this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, `${this.nestingPrefix}(.+?)${this.nestingSuffix}`);
16498
+ }
16499
+ interpolate(str, data, lng, options) {
16500
+ let match;
16501
+ let value;
16502
+ let replaces;
16503
+ const defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
16504
+ const handleFormat = key => {
16505
+ if (key.indexOf(this.formatSeparator) < 0) {
16506
+ const path = deepFindWithDefaults(data, defaultData, key, this.options.keySeparator, this.options.ignoreJSONStructure);
16507
+ return this.alwaysFormat ? this.format(path, undefined, lng, {
16508
+ ...options,
16509
+ ...data,
16510
+ interpolationkey: key
16511
+ }) : path;
16512
+ }
16513
+ const p = key.split(this.formatSeparator);
16514
+ const k = p.shift().trim();
16515
+ const f = p.join(this.formatSeparator).trim();
16516
+ return this.format(deepFindWithDefaults(data, defaultData, k, this.options.keySeparator, this.options.ignoreJSONStructure), f, lng, {
16517
+ ...options,
16518
+ ...data,
16519
+ interpolationkey: k
16520
+ });
16521
+ };
16522
+ this.resetRegExp();
16523
+ const missingInterpolationHandler = options && options.missingInterpolationHandler || this.options.missingInterpolationHandler;
16524
+ const skipOnVariables = options && options.interpolation && options.interpolation.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
16525
+ const todos = [{
16526
+ regex: this.regexpUnescape,
16527
+ safeValue: val => regexSafe(val)
16528
+ }, {
16529
+ regex: this.regexp,
16530
+ safeValue: val => this.escapeValue ? regexSafe(this.escape(val)) : regexSafe(val)
16531
+ }];
16532
+ todos.forEach(todo => {
16533
+ replaces = 0;
16534
+ while (match = todo.regex.exec(str)) {
16535
+ const matchedVar = match[1].trim();
16536
+ value = handleFormat(matchedVar);
16537
+ if (value === undefined) {
16538
+ if (typeof missingInterpolationHandler === 'function') {
16539
+ const temp = missingInterpolationHandler(str, match, options);
16540
+ value = isString(temp) ? temp : '';
16541
+ } else if (options && Object.prototype.hasOwnProperty.call(options, matchedVar)) {
16542
+ value = '';
16543
+ } else if (skipOnVariables) {
16544
+ value = match[0];
16545
+ continue;
16546
+ } else {
16547
+ this.logger.warn(`missed to pass in variable ${matchedVar} for interpolating ${str}`);
16548
+ value = '';
16549
+ }
16550
+ } else if (!isString(value) && !this.useRawValueToEscape) {
16551
+ value = makeString(value);
16552
+ }
16553
+ const safeValue = todo.safeValue(value);
16554
+ str = str.replace(match[0], safeValue);
16555
+ if (skipOnVariables) {
16556
+ todo.regex.lastIndex += value.length;
16557
+ todo.regex.lastIndex -= match[0].length;
16558
+ } else {
16559
+ todo.regex.lastIndex = 0;
16560
+ }
16561
+ replaces++;
16562
+ if (replaces >= this.maxReplaces) {
16563
+ break;
16564
+ }
16565
+ }
16566
+ });
16567
+ return str;
16568
+ }
16569
+ nest(str, fc) {
16570
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
16571
+ let match;
16572
+ let value;
16573
+ let clonedOptions;
16574
+ const handleHasOptions = (key, inheritedOptions) => {
16575
+ const sep = this.nestingOptionsSeparator;
16576
+ if (key.indexOf(sep) < 0) return key;
16577
+ const c = key.split(new RegExp(`${sep}[ ]*{`));
16578
+ let optionsString = `{${c[1]}`;
16579
+ key = c[0];
16580
+ optionsString = this.interpolate(optionsString, clonedOptions);
16581
+ const matchedSingleQuotes = optionsString.match(/'/g);
16582
+ const matchedDoubleQuotes = optionsString.match(/"/g);
16583
+ if (matchedSingleQuotes && matchedSingleQuotes.length % 2 === 0 && !matchedDoubleQuotes || matchedDoubleQuotes.length % 2 !== 0) {
16584
+ optionsString = optionsString.replace(/'/g, '"');
16585
+ }
16586
+ try {
16587
+ clonedOptions = JSON.parse(optionsString);
16588
+ if (inheritedOptions) clonedOptions = {
16589
+ ...inheritedOptions,
16590
+ ...clonedOptions
16591
+ };
16592
+ } catch (e) {
16593
+ this.logger.warn(`failed parsing options string in nesting for key ${key}`, e);
16594
+ return `${key}${sep}${optionsString}`;
16595
+ }
16596
+ if (clonedOptions.defaultValue && clonedOptions.defaultValue.indexOf(this.prefix) > -1) delete clonedOptions.defaultValue;
16597
+ return key;
16598
+ };
16599
+ while (match = this.nestingRegexp.exec(str)) {
16600
+ let formatters = [];
16601
+ clonedOptions = {
16602
+ ...options
16603
+ };
16604
+ clonedOptions = clonedOptions.replace && !isString(clonedOptions.replace) ? clonedOptions.replace : clonedOptions;
16605
+ clonedOptions.applyPostProcessor = false;
16606
+ delete clonedOptions.defaultValue;
16607
+ let doReduce = false;
16608
+ if (match[0].indexOf(this.formatSeparator) !== -1 && !/{.*}/.test(match[1])) {
16609
+ const r = match[1].split(this.formatSeparator).map(elem => elem.trim());
16610
+ match[1] = r.shift();
16611
+ formatters = r;
16612
+ doReduce = true;
16613
+ }
16614
+ value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
16615
+ if (value && match[0] === str && !isString(value)) return value;
16616
+ if (!isString(value)) value = makeString(value);
16617
+ if (!value) {
16618
+ this.logger.warn(`missed to resolve ${match[1]} for nesting ${str}`);
16619
+ value = '';
16620
+ }
16621
+ if (doReduce) {
16622
+ value = formatters.reduce((v, f) => this.format(v, f, options.lng, {
16623
+ ...options,
16624
+ interpolationkey: match[1].trim()
16625
+ }), value.trim());
16626
+ }
16627
+ str = str.replace(match[0], value);
16628
+ this.regexp.lastIndex = 0;
16629
+ }
16630
+ return str;
16631
+ }
16632
+ }
16633
+
16634
+ const parseFormatStr = formatStr => {
16635
+ let formatName = formatStr.toLowerCase().trim();
16636
+ const formatOptions = {};
16637
+ if (formatStr.indexOf('(') > -1) {
16638
+ const p = formatStr.split('(');
16639
+ formatName = p[0].toLowerCase().trim();
16640
+ const optStr = p[1].substring(0, p[1].length - 1);
16641
+ if (formatName === 'currency' && optStr.indexOf(':') < 0) {
16642
+ if (!formatOptions.currency) formatOptions.currency = optStr.trim();
16643
+ } else if (formatName === 'relativetime' && optStr.indexOf(':') < 0) {
16644
+ if (!formatOptions.range) formatOptions.range = optStr.trim();
16645
+ } else {
16646
+ const opts = optStr.split(';');
16647
+ opts.forEach(opt => {
16648
+ if (opt) {
16649
+ const [key, ...rest] = opt.split(':');
16650
+ const val = rest.join(':').trim().replace(/^'+|'+$/g, '');
16651
+ const trimmedKey = key.trim();
16652
+ if (!formatOptions[trimmedKey]) formatOptions[trimmedKey] = val;
16653
+ if (val === 'false') formatOptions[trimmedKey] = false;
16654
+ if (val === 'true') formatOptions[trimmedKey] = true;
16655
+ if (!isNaN(val)) formatOptions[trimmedKey] = parseInt(val, 10);
16656
+ }
16657
+ });
16658
+ }
16659
+ }
16660
+ return {
16661
+ formatName,
16662
+ formatOptions
16663
+ };
16664
+ };
16665
+ const createCachedFormatter = fn => {
16666
+ const cache = {};
16667
+ return (val, lng, options) => {
16668
+ let optForCache = options;
16669
+ if (options && options.interpolationkey && options.formatParams && options.formatParams[options.interpolationkey] && options[options.interpolationkey]) {
16670
+ optForCache = {
16671
+ ...optForCache,
16672
+ [options.interpolationkey]: undefined
16673
+ };
16674
+ }
16675
+ const key = lng + JSON.stringify(optForCache);
16676
+ let formatter = cache[key];
16677
+ if (!formatter) {
16678
+ formatter = fn(getCleanedCode(lng), options);
16679
+ cache[key] = formatter;
16680
+ }
16681
+ return formatter(val);
16682
+ };
16683
+ };
16684
+ class Formatter {
16685
+ constructor() {
16686
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
16687
+ this.logger = baseLogger.create('formatter');
16688
+ this.options = options;
16689
+ this.formats = {
16690
+ number: createCachedFormatter((lng, opt) => {
16691
+ const formatter = new Intl.NumberFormat(lng, {
16692
+ ...opt
16693
+ });
16694
+ return val => formatter.format(val);
16695
+ }),
16696
+ currency: createCachedFormatter((lng, opt) => {
16697
+ const formatter = new Intl.NumberFormat(lng, {
16698
+ ...opt,
16699
+ style: 'currency'
16700
+ });
16701
+ return val => formatter.format(val);
16702
+ }),
16703
+ datetime: createCachedFormatter((lng, opt) => {
16704
+ const formatter = new Intl.DateTimeFormat(lng, {
16705
+ ...opt
16706
+ });
16707
+ return val => formatter.format(val);
16708
+ }),
16709
+ relativetime: createCachedFormatter((lng, opt) => {
16710
+ const formatter = new Intl.RelativeTimeFormat(lng, {
16711
+ ...opt
16712
+ });
16713
+ return val => formatter.format(val, opt.range || 'day');
16714
+ }),
16715
+ list: createCachedFormatter((lng, opt) => {
16716
+ const formatter = new Intl.ListFormat(lng, {
16717
+ ...opt
16718
+ });
16719
+ return val => formatter.format(val);
16720
+ })
16721
+ };
16722
+ this.init(options);
16723
+ }
16724
+ init(services) {
16725
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
16726
+ interpolation: {}
16727
+ };
16728
+ this.formatSeparator = options.interpolation.formatSeparator || ',';
16729
+ }
16730
+ add(name, fc) {
16731
+ this.formats[name.toLowerCase().trim()] = fc;
16732
+ }
16733
+ addCached(name, fc) {
16734
+ this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
16735
+ }
16736
+ format(value, format, lng) {
16737
+ let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
16738
+ const formats = format.split(this.formatSeparator);
16739
+ if (formats.length > 1 && formats[0].indexOf('(') > 1 && formats[0].indexOf(')') < 0 && formats.find(f => f.indexOf(')') > -1)) {
16740
+ const lastIndex = formats.findIndex(f => f.indexOf(')') > -1);
16741
+ formats[0] = [formats[0], ...formats.splice(1, lastIndex)].join(this.formatSeparator);
16742
+ }
16743
+ const result = formats.reduce((mem, f) => {
16744
+ const {
16745
+ formatName,
16746
+ formatOptions
16747
+ } = parseFormatStr(f);
16748
+ if (this.formats[formatName]) {
16749
+ let formatted = mem;
16750
+ try {
16751
+ const valOptions = options && options.formatParams && options.formatParams[options.interpolationkey] || {};
16752
+ const l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
16753
+ formatted = this.formats[formatName](mem, l, {
16754
+ ...formatOptions,
16755
+ ...options,
16756
+ ...valOptions
16757
+ });
16758
+ } catch (error) {
16759
+ this.logger.warn(error);
16760
+ }
16761
+ return formatted;
16762
+ } else {
16763
+ this.logger.warn(`there was no format function for ${formatName}`);
16764
+ }
16765
+ return mem;
16766
+ }, value);
16767
+ return result;
16768
+ }
16769
+ }
16770
+
16771
+ const removePending = (q, name) => {
16772
+ if (q.pending[name] !== undefined) {
16773
+ delete q.pending[name];
16774
+ q.pendingCount--;
16775
+ }
16776
+ };
16777
+ class Connector extends EventEmitter {
16778
+ constructor(backend, store, services) {
16779
+ let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
16780
+ super();
16781
+ this.backend = backend;
16782
+ this.store = store;
16783
+ this.services = services;
16784
+ this.languageUtils = services.languageUtils;
16785
+ this.options = options;
16786
+ this.logger = baseLogger.create('backendConnector');
16787
+ this.waitingReads = [];
16788
+ this.maxParallelReads = options.maxParallelReads || 10;
16789
+ this.readingCalls = 0;
16790
+ this.maxRetries = options.maxRetries >= 0 ? options.maxRetries : 5;
16791
+ this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
16792
+ this.state = {};
16793
+ this.queue = [];
16794
+ if (this.backend && this.backend.init) {
16795
+ this.backend.init(services, options.backend, options);
16796
+ }
16797
+ }
16798
+ queueLoad(languages, namespaces, options, callback) {
16799
+ const toLoad = {};
16800
+ const pending = {};
16801
+ const toLoadLanguages = {};
16802
+ const toLoadNamespaces = {};
16803
+ languages.forEach(lng => {
16804
+ let hasAllNamespaces = true;
16805
+ namespaces.forEach(ns => {
16806
+ const name = `${lng}|${ns}`;
16807
+ if (!options.reload && this.store.hasResourceBundle(lng, ns)) {
16808
+ this.state[name] = 2;
16809
+ } else if (this.state[name] < 0) ; else if (this.state[name] === 1) {
16810
+ if (pending[name] === undefined) pending[name] = true;
16811
+ } else {
16812
+ this.state[name] = 1;
16813
+ hasAllNamespaces = false;
16814
+ if (pending[name] === undefined) pending[name] = true;
16815
+ if (toLoad[name] === undefined) toLoad[name] = true;
16816
+ if (toLoadNamespaces[ns] === undefined) toLoadNamespaces[ns] = true;
16817
+ }
16818
+ });
16819
+ if (!hasAllNamespaces) toLoadLanguages[lng] = true;
16820
+ });
16821
+ if (Object.keys(toLoad).length || Object.keys(pending).length) {
16822
+ this.queue.push({
16823
+ pending,
16824
+ pendingCount: Object.keys(pending).length,
16825
+ loaded: {},
16826
+ errors: [],
16827
+ callback
16828
+ });
16829
+ }
16830
+ return {
16831
+ toLoad: Object.keys(toLoad),
16832
+ pending: Object.keys(pending),
16833
+ toLoadLanguages: Object.keys(toLoadLanguages),
16834
+ toLoadNamespaces: Object.keys(toLoadNamespaces)
16835
+ };
16836
+ }
16837
+ loaded(name, err, data) {
16838
+ const s = name.split('|');
16839
+ const lng = s[0];
16840
+ const ns = s[1];
16841
+ if (err) this.emit('failedLoading', lng, ns, err);
16842
+ if (!err && data) {
16843
+ this.store.addResourceBundle(lng, ns, data, undefined, undefined, {
16844
+ skipCopy: true
16845
+ });
16846
+ }
16847
+ this.state[name] = err ? -1 : 2;
16848
+ if (err && data) this.state[name] = 0;
16849
+ const loaded = {};
16850
+ this.queue.forEach(q => {
16851
+ pushPath(q.loaded, [lng], ns);
16852
+ removePending(q, name);
16853
+ if (err) q.errors.push(err);
16854
+ if (q.pendingCount === 0 && !q.done) {
16855
+ Object.keys(q.loaded).forEach(l => {
16856
+ if (!loaded[l]) loaded[l] = {};
16857
+ const loadedKeys = q.loaded[l];
16858
+ if (loadedKeys.length) {
16859
+ loadedKeys.forEach(n => {
16860
+ if (loaded[l][n] === undefined) loaded[l][n] = true;
16861
+ });
16862
+ }
16863
+ });
16864
+ q.done = true;
16865
+ if (q.errors.length) {
16866
+ q.callback(q.errors);
16867
+ } else {
16868
+ q.callback();
16869
+ }
16870
+ }
16871
+ });
16872
+ this.emit('loaded', loaded);
16873
+ this.queue = this.queue.filter(q => !q.done);
16874
+ }
16875
+ read(lng, ns, fcName) {
16876
+ let tried = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
16877
+ let wait = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : this.retryTimeout;
16878
+ let callback = arguments.length > 5 ? arguments[5] : undefined;
16879
+ if (!lng.length) return callback(null, {});
16880
+ if (this.readingCalls >= this.maxParallelReads) {
16881
+ this.waitingReads.push({
16882
+ lng,
16883
+ ns,
16884
+ fcName,
16885
+ tried,
16886
+ wait,
16887
+ callback
16888
+ });
16889
+ return;
16890
+ }
16891
+ this.readingCalls++;
16892
+ const resolver = (err, data) => {
16893
+ this.readingCalls--;
16894
+ if (this.waitingReads.length > 0) {
16895
+ const next = this.waitingReads.shift();
16896
+ this.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
16897
+ }
16898
+ if (err && data && tried < this.maxRetries) {
16899
+ setTimeout(() => {
16900
+ this.read.call(this, lng, ns, fcName, tried + 1, wait * 2, callback);
16901
+ }, wait);
16902
+ return;
16903
+ }
16904
+ callback(err, data);
16905
+ };
16906
+ const fc = this.backend[fcName].bind(this.backend);
16907
+ if (fc.length === 2) {
16908
+ try {
16909
+ const r = fc(lng, ns);
16910
+ if (r && typeof r.then === 'function') {
16911
+ r.then(data => resolver(null, data)).catch(resolver);
16912
+ } else {
16913
+ resolver(null, r);
16914
+ }
16915
+ } catch (err) {
16916
+ resolver(err);
16917
+ }
16918
+ return;
16919
+ }
16920
+ return fc(lng, ns, resolver);
16921
+ }
16922
+ prepareLoading(languages, namespaces) {
16923
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
16924
+ let callback = arguments.length > 3 ? arguments[3] : undefined;
16925
+ if (!this.backend) {
16926
+ this.logger.warn('No backend was added via i18next.use. Will not load resources.');
16927
+ return callback && callback();
16928
+ }
16929
+ if (isString(languages)) languages = this.languageUtils.toResolveHierarchy(languages);
16930
+ if (isString(namespaces)) namespaces = [namespaces];
16931
+ const toLoad = this.queueLoad(languages, namespaces, options, callback);
16932
+ if (!toLoad.toLoad.length) {
16933
+ if (!toLoad.pending.length) callback();
16934
+ return null;
16935
+ }
16936
+ toLoad.toLoad.forEach(name => {
16937
+ this.loadOne(name);
16938
+ });
16939
+ }
16940
+ load(languages, namespaces, callback) {
16941
+ this.prepareLoading(languages, namespaces, {}, callback);
16942
+ }
16943
+ reload(languages, namespaces, callback) {
16944
+ this.prepareLoading(languages, namespaces, {
16945
+ reload: true
16946
+ }, callback);
16947
+ }
16948
+ loadOne(name) {
16949
+ let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
16950
+ const s = name.split('|');
16951
+ const lng = s[0];
16952
+ const ns = s[1];
16953
+ this.read(lng, ns, 'read', undefined, undefined, (err, data) => {
16954
+ if (err) this.logger.warn(`${prefix}loading namespace ${ns} for language ${lng} failed`, err);
16955
+ if (!err && data) this.logger.log(`${prefix}loaded namespace ${ns} for language ${lng}`, data);
16956
+ this.loaded(name, err, data);
16957
+ });
16958
+ }
16959
+ saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
16960
+ let options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
16961
+ let clb = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : () => {};
16962
+ if (this.services.utils && this.services.utils.hasLoadedNamespace && !this.services.utils.hasLoadedNamespace(namespace)) {
16963
+ this.logger.warn(`did not save key "${key}" as the namespace "${namespace}" was not yet loaded`, 'This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!');
16964
+ return;
16965
+ }
16966
+ if (key === undefined || key === null || key === '') return;
16967
+ if (this.backend && this.backend.create) {
16968
+ const opts = {
16969
+ ...options,
16970
+ isUpdate
16971
+ };
16972
+ const fc = this.backend.create.bind(this.backend);
16973
+ if (fc.length < 6) {
16974
+ try {
16975
+ let r;
16976
+ if (fc.length === 5) {
16977
+ r = fc(languages, namespace, key, fallbackValue, opts);
16978
+ } else {
16979
+ r = fc(languages, namespace, key, fallbackValue);
16980
+ }
16981
+ if (r && typeof r.then === 'function') {
16982
+ r.then(data => clb(null, data)).catch(clb);
16983
+ } else {
16984
+ clb(null, r);
16985
+ }
16986
+ } catch (err) {
16987
+ clb(err);
16988
+ }
16989
+ } else {
16990
+ fc(languages, namespace, key, fallbackValue, clb, opts);
16991
+ }
16992
+ }
16993
+ if (!languages || !languages[0]) return;
16994
+ this.store.addResource(languages[0], namespace, key, fallbackValue);
16995
+ }
16996
+ }
16997
+
16998
+ const get = () => ({
16999
+ debug: false,
17000
+ initImmediate: true,
17001
+ ns: ['translation'],
17002
+ defaultNS: ['translation'],
17003
+ fallbackLng: ['dev'],
17004
+ fallbackNS: false,
17005
+ supportedLngs: false,
17006
+ nonExplicitSupportedLngs: false,
17007
+ load: 'all',
17008
+ preload: false,
17009
+ simplifyPluralSuffix: true,
17010
+ keySeparator: '.',
17011
+ nsSeparator: ':',
17012
+ pluralSeparator: '_',
17013
+ contextSeparator: '_',
17014
+ partialBundledLanguages: false,
17015
+ saveMissing: false,
17016
+ updateMissing: false,
17017
+ saveMissingTo: 'fallback',
17018
+ saveMissingPlurals: true,
17019
+ missingKeyHandler: false,
17020
+ missingInterpolationHandler: false,
17021
+ postProcess: false,
17022
+ postProcessPassResolved: false,
17023
+ returnNull: false,
17024
+ returnEmptyString: true,
17025
+ returnObjects: false,
17026
+ joinArrays: false,
17027
+ returnedObjectHandler: false,
17028
+ parseMissingKeyHandler: false,
17029
+ appendNamespaceToMissingKey: false,
17030
+ appendNamespaceToCIMode: false,
17031
+ overloadTranslationOptionHandler: args => {
17032
+ let ret = {};
17033
+ if (typeof args[1] === 'object') ret = args[1];
17034
+ if (isString(args[1])) ret.defaultValue = args[1];
17035
+ if (isString(args[2])) ret.tDescription = args[2];
17036
+ if (typeof args[2] === 'object' || typeof args[3] === 'object') {
17037
+ const options = args[3] || args[2];
17038
+ Object.keys(options).forEach(key => {
17039
+ ret[key] = options[key];
17040
+ });
17041
+ }
17042
+ return ret;
17043
+ },
17044
+ interpolation: {
17045
+ escapeValue: true,
17046
+ format: value => value,
17047
+ prefix: '{{',
17048
+ suffix: '}}',
17049
+ formatSeparator: ',',
17050
+ unescapePrefix: '-',
17051
+ nestingPrefix: '$t(',
17052
+ nestingSuffix: ')',
17053
+ nestingOptionsSeparator: ',',
17054
+ maxReplaces: 1000,
17055
+ skipOnVariables: true
17056
+ }
17057
+ });
17058
+ const transformOptions = options => {
17059
+ if (isString(options.ns)) options.ns = [options.ns];
17060
+ if (isString(options.fallbackLng)) options.fallbackLng = [options.fallbackLng];
17061
+ if (isString(options.fallbackNS)) options.fallbackNS = [options.fallbackNS];
17062
+ if (options.supportedLngs && options.supportedLngs.indexOf('cimode') < 0) {
17063
+ options.supportedLngs = options.supportedLngs.concat(['cimode']);
17064
+ }
17065
+ return options;
17066
+ };
17067
+
17068
+ const noop = () => {};
17069
+ const bindMemberFunctions = inst => {
17070
+ const mems = Object.getOwnPropertyNames(Object.getPrototypeOf(inst));
17071
+ mems.forEach(mem => {
17072
+ if (typeof inst[mem] === 'function') {
17073
+ inst[mem] = inst[mem].bind(inst);
17074
+ }
17075
+ });
17076
+ };
17077
+ class I18n extends EventEmitter {
17078
+ constructor() {
17079
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
17080
+ let callback = arguments.length > 1 ? arguments[1] : undefined;
17081
+ super();
17082
+ this.options = transformOptions(options);
17083
+ this.services = {};
17084
+ this.logger = baseLogger;
17085
+ this.modules = {
17086
+ external: []
17087
+ };
17088
+ bindMemberFunctions(this);
17089
+ if (callback && !this.isInitialized && !options.isClone) {
17090
+ if (!this.options.initImmediate) {
17091
+ this.init(options, callback);
17092
+ return this;
17093
+ }
17094
+ setTimeout(() => {
17095
+ this.init(options, callback);
17096
+ }, 0);
17097
+ }
17098
+ }
17099
+ init() {
17100
+ var _this = this;
17101
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
17102
+ let callback = arguments.length > 1 ? arguments[1] : undefined;
17103
+ this.isInitializing = true;
17104
+ if (typeof options === 'function') {
17105
+ callback = options;
17106
+ options = {};
17107
+ }
17108
+ if (!options.defaultNS && options.defaultNS !== false && options.ns) {
17109
+ if (isString(options.ns)) {
17110
+ options.defaultNS = options.ns;
17111
+ } else if (options.ns.indexOf('translation') < 0) {
17112
+ options.defaultNS = options.ns[0];
17113
+ }
17114
+ }
17115
+ const defOpts = get();
17116
+ this.options = {
17117
+ ...defOpts,
17118
+ ...this.options,
17119
+ ...transformOptions(options)
17120
+ };
17121
+ if (this.options.compatibilityAPI !== 'v1') {
17122
+ this.options.interpolation = {
17123
+ ...defOpts.interpolation,
17124
+ ...this.options.interpolation
17125
+ };
17126
+ }
17127
+ if (options.keySeparator !== undefined) {
17128
+ this.options.userDefinedKeySeparator = options.keySeparator;
17129
+ }
17130
+ if (options.nsSeparator !== undefined) {
17131
+ this.options.userDefinedNsSeparator = options.nsSeparator;
17132
+ }
17133
+ const createClassOnDemand = ClassOrObject => {
17134
+ if (!ClassOrObject) return null;
17135
+ if (typeof ClassOrObject === 'function') return new ClassOrObject();
17136
+ return ClassOrObject;
17137
+ };
17138
+ if (!this.options.isClone) {
17139
+ if (this.modules.logger) {
17140
+ baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
17141
+ } else {
17142
+ baseLogger.init(null, this.options);
17143
+ }
17144
+ let formatter;
17145
+ if (this.modules.formatter) {
17146
+ formatter = this.modules.formatter;
17147
+ } else if (typeof Intl !== 'undefined') {
17148
+ formatter = Formatter;
17149
+ }
17150
+ const lu = new LanguageUtil(this.options);
17151
+ this.store = new ResourceStore(this.options.resources, this.options);
17152
+ const s = this.services;
17153
+ s.logger = baseLogger;
17154
+ s.resourceStore = this.store;
17155
+ s.languageUtils = lu;
17156
+ s.pluralResolver = new PluralResolver(lu, {
17157
+ prepend: this.options.pluralSeparator,
17158
+ compatibilityJSON: this.options.compatibilityJSON,
17159
+ simplifyPluralSuffix: this.options.simplifyPluralSuffix
17160
+ });
17161
+ if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
17162
+ s.formatter = createClassOnDemand(formatter);
17163
+ s.formatter.init(s, this.options);
17164
+ this.options.interpolation.format = s.formatter.format.bind(s.formatter);
17165
+ }
17166
+ s.interpolator = new Interpolator(this.options);
17167
+ s.utils = {
17168
+ hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
17169
+ };
17170
+ s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
17171
+ s.backendConnector.on('*', function (event) {
17172
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
17173
+ args[_key - 1] = arguments[_key];
17174
+ }
17175
+ _this.emit(event, ...args);
17176
+ });
17177
+ if (this.modules.languageDetector) {
17178
+ s.languageDetector = createClassOnDemand(this.modules.languageDetector);
17179
+ if (s.languageDetector.init) s.languageDetector.init(s, this.options.detection, this.options);
17180
+ }
17181
+ if (this.modules.i18nFormat) {
17182
+ s.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
17183
+ if (s.i18nFormat.init) s.i18nFormat.init(this);
17184
+ }
17185
+ this.translator = new Translator(this.services, this.options);
17186
+ this.translator.on('*', function (event) {
17187
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
17188
+ args[_key2 - 1] = arguments[_key2];
17189
+ }
17190
+ _this.emit(event, ...args);
17191
+ });
17192
+ this.modules.external.forEach(m => {
17193
+ if (m.init) m.init(this);
17194
+ });
17195
+ }
17196
+ this.format = this.options.interpolation.format;
17197
+ if (!callback) callback = noop;
17198
+ if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
17199
+ const codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
17200
+ if (codes.length > 0 && codes[0] !== 'dev') this.options.lng = codes[0];
17201
+ }
17202
+ if (!this.services.languageDetector && !this.options.lng) {
17203
+ this.logger.warn('init: no languageDetector is used and no lng is defined');
17204
+ }
17205
+ const storeApi = ['getResource', 'hasResourceBundle', 'getResourceBundle', 'getDataByLanguage'];
17206
+ storeApi.forEach(fcName => {
17207
+ this[fcName] = function () {
17208
+ return _this.store[fcName](...arguments);
17209
+ };
17210
+ });
17211
+ const storeApiChained = ['addResource', 'addResources', 'addResourceBundle', 'removeResourceBundle'];
17212
+ storeApiChained.forEach(fcName => {
17213
+ this[fcName] = function () {
17214
+ _this.store[fcName](...arguments);
17215
+ return _this;
17216
+ };
17217
+ });
17218
+ const deferred = defer();
17219
+ const load = () => {
17220
+ const finish = (err, t) => {
17221
+ this.isInitializing = false;
17222
+ if (this.isInitialized && !this.initializedStoreOnce) this.logger.warn('init: i18next is already initialized. You should call init just once!');
17223
+ this.isInitialized = true;
17224
+ if (!this.options.isClone) this.logger.log('initialized', this.options);
17225
+ this.emit('initialized', this.options);
17226
+ deferred.resolve(t);
17227
+ callback(err, t);
17228
+ };
17229
+ if (this.languages && this.options.compatibilityAPI !== 'v1' && !this.isInitialized) return finish(null, this.t.bind(this));
17230
+ this.changeLanguage(this.options.lng, finish);
17231
+ };
17232
+ if (this.options.resources || !this.options.initImmediate) {
17233
+ load();
17234
+ } else {
17235
+ setTimeout(load, 0);
17236
+ }
17237
+ return deferred;
17238
+ }
17239
+ loadResources(language) {
17240
+ let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
17241
+ let usedCallback = callback;
17242
+ const usedLng = isString(language) ? language : this.language;
17243
+ if (typeof language === 'function') usedCallback = language;
17244
+ if (!this.options.resources || this.options.partialBundledLanguages) {
17245
+ if (usedLng && usedLng.toLowerCase() === 'cimode' && (!this.options.preload || this.options.preload.length === 0)) return usedCallback();
17246
+ const toLoad = [];
17247
+ const append = lng => {
17248
+ if (!lng) return;
17249
+ if (lng === 'cimode') return;
17250
+ const lngs = this.services.languageUtils.toResolveHierarchy(lng);
17251
+ lngs.forEach(l => {
17252
+ if (l === 'cimode') return;
17253
+ if (toLoad.indexOf(l) < 0) toLoad.push(l);
17254
+ });
17255
+ };
17256
+ if (!usedLng) {
17257
+ const fallbacks = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
17258
+ fallbacks.forEach(l => append(l));
17259
+ } else {
17260
+ append(usedLng);
17261
+ }
17262
+ if (this.options.preload) {
17263
+ this.options.preload.forEach(l => append(l));
17264
+ }
17265
+ this.services.backendConnector.load(toLoad, this.options.ns, e => {
17266
+ if (!e && !this.resolvedLanguage && this.language) this.setResolvedLanguage(this.language);
17267
+ usedCallback(e);
17268
+ });
17269
+ } else {
17270
+ usedCallback(null);
17271
+ }
17272
+ }
17273
+ reloadResources(lngs, ns, callback) {
17274
+ const deferred = defer();
17275
+ if (typeof lngs === 'function') {
17276
+ callback = lngs;
17277
+ lngs = undefined;
17278
+ }
17279
+ if (typeof ns === 'function') {
17280
+ callback = ns;
17281
+ ns = undefined;
17282
+ }
17283
+ if (!lngs) lngs = this.languages;
17284
+ if (!ns) ns = this.options.ns;
17285
+ if (!callback) callback = noop;
17286
+ this.services.backendConnector.reload(lngs, ns, err => {
17287
+ deferred.resolve();
17288
+ callback(err);
17289
+ });
17290
+ return deferred;
17291
+ }
17292
+ use(module) {
17293
+ if (!module) throw new Error('You are passing an undefined module! Please check the object you are passing to i18next.use()');
17294
+ if (!module.type) throw new Error('You are passing a wrong module! Please check the object you are passing to i18next.use()');
17295
+ if (module.type === 'backend') {
17296
+ this.modules.backend = module;
17297
+ }
17298
+ if (module.type === 'logger' || module.log && module.warn && module.error) {
17299
+ this.modules.logger = module;
17300
+ }
17301
+ if (module.type === 'languageDetector') {
17302
+ this.modules.languageDetector = module;
17303
+ }
17304
+ if (module.type === 'i18nFormat') {
17305
+ this.modules.i18nFormat = module;
17306
+ }
17307
+ if (module.type === 'postProcessor') {
17308
+ postProcessor.addPostProcessor(module);
17309
+ }
17310
+ if (module.type === 'formatter') {
17311
+ this.modules.formatter = module;
17312
+ }
17313
+ if (module.type === '3rdParty') {
17314
+ this.modules.external.push(module);
17315
+ }
17316
+ return this;
17317
+ }
17318
+ setResolvedLanguage(l) {
17319
+ if (!l || !this.languages) return;
17320
+ if (['cimode', 'dev'].indexOf(l) > -1) return;
17321
+ for (let li = 0; li < this.languages.length; li++) {
17322
+ const lngInLngs = this.languages[li];
17323
+ if (['cimode', 'dev'].indexOf(lngInLngs) > -1) continue;
17324
+ if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
17325
+ this.resolvedLanguage = lngInLngs;
17326
+ break;
17327
+ }
17328
+ }
17329
+ }
17330
+ changeLanguage(lng, callback) {
17331
+ var _this2 = this;
17332
+ this.isLanguageChangingTo = lng;
17333
+ const deferred = defer();
17334
+ this.emit('languageChanging', lng);
17335
+ const setLngProps = l => {
17336
+ this.language = l;
17337
+ this.languages = this.services.languageUtils.toResolveHierarchy(l);
17338
+ this.resolvedLanguage = undefined;
17339
+ this.setResolvedLanguage(l);
17340
+ };
17341
+ const done = (err, l) => {
17342
+ if (l) {
17343
+ setLngProps(l);
17344
+ this.translator.changeLanguage(l);
17345
+ this.isLanguageChangingTo = undefined;
17346
+ this.emit('languageChanged', l);
17347
+ this.logger.log('languageChanged', l);
17348
+ } else {
17349
+ this.isLanguageChangingTo = undefined;
17350
+ }
17351
+ deferred.resolve(function () {
17352
+ return _this2.t(...arguments);
17353
+ });
17354
+ if (callback) callback(err, function () {
17355
+ return _this2.t(...arguments);
17356
+ });
17357
+ };
17358
+ const setLng = lngs => {
17359
+ if (!lng && !lngs && this.services.languageDetector) lngs = [];
17360
+ const l = isString(lngs) ? lngs : this.services.languageUtils.getBestMatchFromCodes(lngs);
17361
+ if (l) {
17362
+ if (!this.language) {
17363
+ setLngProps(l);
17364
+ }
17365
+ if (!this.translator.language) this.translator.changeLanguage(l);
17366
+ if (this.services.languageDetector && this.services.languageDetector.cacheUserLanguage) this.services.languageDetector.cacheUserLanguage(l);
17367
+ }
17368
+ this.loadResources(l, err => {
17369
+ done(err, l);
17370
+ });
17371
+ };
17372
+ if (!lng && this.services.languageDetector && !this.services.languageDetector.async) {
17373
+ setLng(this.services.languageDetector.detect());
17374
+ } else if (!lng && this.services.languageDetector && this.services.languageDetector.async) {
17375
+ if (this.services.languageDetector.detect.length === 0) {
17376
+ this.services.languageDetector.detect().then(setLng);
17377
+ } else {
17378
+ this.services.languageDetector.detect(setLng);
17379
+ }
17380
+ } else {
17381
+ setLng(lng);
17382
+ }
17383
+ return deferred;
17384
+ }
17385
+ getFixedT(lng, ns, keyPrefix) {
17386
+ var _this3 = this;
17387
+ const fixedT = function (key, opts) {
17388
+ let options;
17389
+ if (typeof opts !== 'object') {
17390
+ for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
17391
+ rest[_key3 - 2] = arguments[_key3];
17392
+ }
17393
+ options = _this3.options.overloadTranslationOptionHandler([key, opts].concat(rest));
17394
+ } else {
17395
+ options = {
17396
+ ...opts
17397
+ };
17398
+ }
17399
+ options.lng = options.lng || fixedT.lng;
17400
+ options.lngs = options.lngs || fixedT.lngs;
17401
+ options.ns = options.ns || fixedT.ns;
17402
+ if (options.keyPrefix !== '') options.keyPrefix = options.keyPrefix || keyPrefix || fixedT.keyPrefix;
17403
+ const keySeparator = _this3.options.keySeparator || '.';
17404
+ let resultKey;
17405
+ if (options.keyPrefix && Array.isArray(key)) {
17406
+ resultKey = key.map(k => `${options.keyPrefix}${keySeparator}${k}`);
17407
+ } else {
17408
+ resultKey = options.keyPrefix ? `${options.keyPrefix}${keySeparator}${key}` : key;
17409
+ }
17410
+ return _this3.t(resultKey, options);
17411
+ };
17412
+ if (isString(lng)) {
17413
+ fixedT.lng = lng;
17414
+ } else {
17415
+ fixedT.lngs = lng;
17416
+ }
17417
+ fixedT.ns = ns;
17418
+ fixedT.keyPrefix = keyPrefix;
17419
+ return fixedT;
17420
+ }
17421
+ t() {
17422
+ return this.translator && this.translator.translate(...arguments);
17423
+ }
17424
+ exists() {
17425
+ return this.translator && this.translator.exists(...arguments);
17426
+ }
17427
+ setDefaultNamespace(ns) {
17428
+ this.options.defaultNS = ns;
17429
+ }
17430
+ hasLoadedNamespace(ns) {
17431
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
17432
+ if (!this.isInitialized) {
17433
+ this.logger.warn('hasLoadedNamespace: i18next was not initialized', this.languages);
17434
+ return false;
17435
+ }
17436
+ if (!this.languages || !this.languages.length) {
17437
+ this.logger.warn('hasLoadedNamespace: i18n.languages were undefined or empty', this.languages);
17438
+ return false;
17439
+ }
17440
+ const lng = options.lng || this.resolvedLanguage || this.languages[0];
17441
+ const fallbackLng = this.options ? this.options.fallbackLng : false;
17442
+ const lastLng = this.languages[this.languages.length - 1];
17443
+ if (lng.toLowerCase() === 'cimode') return true;
17444
+ const loadNotPending = (l, n) => {
17445
+ const loadState = this.services.backendConnector.state[`${l}|${n}`];
17446
+ return loadState === -1 || loadState === 0 || loadState === 2;
17447
+ };
17448
+ if (options.precheck) {
17449
+ const preResult = options.precheck(this, loadNotPending);
17450
+ if (preResult !== undefined) return preResult;
17451
+ }
17452
+ if (this.hasResourceBundle(lng, ns)) return true;
17453
+ if (!this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages) return true;
17454
+ if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
17455
+ return false;
17456
+ }
17457
+ loadNamespaces(ns, callback) {
17458
+ const deferred = defer();
17459
+ if (!this.options.ns) {
17460
+ if (callback) callback();
17461
+ return Promise.resolve();
17462
+ }
17463
+ if (isString(ns)) ns = [ns];
17464
+ ns.forEach(n => {
17465
+ if (this.options.ns.indexOf(n) < 0) this.options.ns.push(n);
17466
+ });
17467
+ this.loadResources(err => {
17468
+ deferred.resolve();
17469
+ if (callback) callback(err);
17470
+ });
17471
+ return deferred;
17472
+ }
17473
+ loadLanguages(lngs, callback) {
17474
+ const deferred = defer();
17475
+ if (isString(lngs)) lngs = [lngs];
17476
+ const preloaded = this.options.preload || [];
17477
+ const newLngs = lngs.filter(lng => preloaded.indexOf(lng) < 0 && this.services.languageUtils.isSupportedCode(lng));
17478
+ if (!newLngs.length) {
17479
+ if (callback) callback();
17480
+ return Promise.resolve();
17481
+ }
17482
+ this.options.preload = preloaded.concat(newLngs);
17483
+ this.loadResources(err => {
17484
+ deferred.resolve();
17485
+ if (callback) callback(err);
17486
+ });
17487
+ return deferred;
17488
+ }
17489
+ dir(lng) {
17490
+ if (!lng) lng = this.resolvedLanguage || (this.languages && this.languages.length > 0 ? this.languages[0] : this.language);
17491
+ if (!lng) return 'rtl';
17492
+ const rtlLngs = ['ar', 'shu', 'sqr', 'ssh', 'xaa', 'yhd', 'yud', 'aao', 'abh', 'abv', 'acm', 'acq', 'acw', 'acx', 'acy', 'adf', 'ads', 'aeb', 'aec', 'afb', 'ajp', 'apc', 'apd', 'arb', 'arq', 'ars', 'ary', 'arz', 'auz', 'avl', 'ayh', 'ayl', 'ayn', 'ayp', 'bbz', 'pga', 'he', 'iw', 'ps', 'pbt', 'pbu', 'pst', 'prp', 'prd', 'ug', 'ur', 'ydd', 'yds', 'yih', 'ji', 'yi', 'hbo', 'men', 'xmn', 'fa', 'jpr', 'peo', 'pes', 'prs', 'dv', 'sam', 'ckb'];
17493
+ const languageUtils = this.services && this.services.languageUtils || new LanguageUtil(get());
17494
+ return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf('-arab') > 1 ? 'rtl' : 'ltr';
17495
+ }
17496
+ static createInstance() {
17497
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
17498
+ let callback = arguments.length > 1 ? arguments[1] : undefined;
17499
+ return new I18n(options, callback);
17500
+ }
17501
+ cloneInstance() {
17502
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
17503
+ let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
17504
+ const forkResourceStore = options.forkResourceStore;
17505
+ if (forkResourceStore) delete options.forkResourceStore;
17506
+ const mergedOptions = {
17507
+ ...this.options,
17508
+ ...options,
17509
+ ...{
17510
+ isClone: true
17511
+ }
17512
+ };
17513
+ const clone = new I18n(mergedOptions);
17514
+ if (options.debug !== undefined || options.prefix !== undefined) {
17515
+ clone.logger = clone.logger.clone(options);
17516
+ }
17517
+ const membersToCopy = ['store', 'services', 'language'];
17518
+ membersToCopy.forEach(m => {
17519
+ clone[m] = this[m];
17520
+ });
17521
+ clone.services = {
17522
+ ...this.services
17523
+ };
17524
+ clone.services.utils = {
17525
+ hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
17526
+ };
17527
+ if (forkResourceStore) {
17528
+ clone.store = new ResourceStore(this.store.data, mergedOptions);
17529
+ clone.services.resourceStore = clone.store;
17530
+ }
17531
+ clone.translator = new Translator(clone.services, mergedOptions);
17532
+ clone.translator.on('*', function (event) {
17533
+ for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
17534
+ args[_key4 - 1] = arguments[_key4];
17535
+ }
17536
+ clone.emit(event, ...args);
17537
+ });
17538
+ clone.init(mergedOptions, callback);
17539
+ clone.translator.options = mergedOptions;
17540
+ clone.translator.backendConnector.services.utils = {
17541
+ hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
17542
+ };
17543
+ return clone;
17544
+ }
17545
+ toJSON() {
17546
+ return {
17547
+ options: this.options,
17548
+ store: this.store,
17549
+ language: this.language,
17550
+ languages: this.languages,
17551
+ resolvedLanguage: this.resolvedLanguage
17552
+ };
17553
+ }
17554
+ }
17555
+ const instance = I18n.createInstance();
17556
+ instance.createInstance = I18n.createInstance;
17557
+
17558
+ instance.createInstance;
17559
+ instance.dir;
17560
+ instance.init;
17561
+ instance.loadResources;
17562
+ instance.reloadResources;
17563
+ instance.use;
17564
+ instance.changeLanguage;
17565
+ instance.getFixedT;
17566
+ instance.t;
17567
+ instance.exists;
17568
+ instance.setDefaultNamespace;
17569
+ instance.hasLoadedNamespace;
17570
+ instance.loadNamespaces;
17571
+ instance.loadLanguages;
17572
+
17573
+ const enTranslations = {
17574
+ components: {
17575
+ contactInfoPopup: {
17576
+ businessSection: {
17577
+ title: 'Business Information',
17578
+ description: 'Details about the business',
17579
+ },
17580
+ contactMethod: {
17581
+ email: 'Email',
17582
+ phone: 'Phone',
17583
+ website: 'Website',
17584
+ },
17585
+ labelsSection: {
17586
+ title: 'Labels',
17587
+ },
17588
+ membersSection: {
17589
+ title: 'Members',
17590
+ noMembers: 'No members found',
17591
+ },
17592
+ global: {
17593
+ properties: 'Properties',
17594
+ business: 'Business',
17595
+ businessMembers: 'Business Members',
17596
+ labels: 'Labels',
17597
+ },
17598
+ },
17599
+ textBox: {
17600
+ placeholder: 'Enter text...',
17601
+ },
17602
+ },
17603
+ };
17604
+
17605
+ const esTranslations = {
17606
+ components: {
17607
+ contactInfoPopup: {
17608
+ businessSection: {
17609
+ title: 'Información del Negocio',
17610
+ description: 'Detalles sobre el negocio',
17611
+ },
17612
+ contactMethod: {
17613
+ email: 'Correo electrónico',
17614
+ phone: 'Teléfono',
17615
+ website: 'Sitio web',
17616
+ },
17617
+ labelsSection: {
17618
+ title: 'Etiquetas',
17619
+ },
17620
+ membersSection: {
17621
+ title: 'Miembros',
17622
+ noMembers: 'No se encontraron miembros',
17623
+ },
17624
+ global: {
17625
+ properties: 'Propiedades',
17626
+ business: 'Empresa',
17627
+ businessMembers: 'Miembros de la empresa',
17628
+ labels: 'Etiquetas',
17629
+ },
17630
+ },
17631
+ textBox: {
17632
+ placeholder: 'Ingrese texto...',
17633
+ },
17634
+ },
17635
+ };
17636
+
17637
+ instance.use(initReactI18next).init({
17638
+ resources: {
17639
+ en: {
17640
+ translation: enTranslations,
17641
+ },
17642
+ es: {
17643
+ translation: esTranslations,
17644
+ },
17645
+ },
17646
+ lng: 'en',
17647
+ fallbackLng: 'en',
17648
+ interpolation: {
17649
+ escapeValue: false,
17650
+ },
17651
+ });
17652
+
17653
+ const LanguageContext = React.createContext(undefined);
17654
+ const LanguageProvider = ({ children, }) => {
17655
+ const [language, setLanguage] = React.useState(instance.language);
17656
+ const changeLanguage = (lang) => {
17657
+ instance.changeLanguage(lang);
17658
+ setLanguage(lang);
17659
+ };
17660
+ return (jsxRuntimeExports.jsx(LanguageContext.Provider, { value: { language, setLanguage: changeLanguage }, children: children }));
17661
+ };
17662
+ const useLanguage = () => {
17663
+ const context = React.useContext(LanguageContext);
17664
+ if (context === undefined) {
17665
+ throw new Error('useLanguage must be used within a LanguageProvider');
17666
+ }
17667
+ return context;
17668
+ };
17669
+
17670
+ const LanguageSelector = () => {
17671
+ const { language, setLanguage } = useLanguage();
17672
+ return (jsxRuntimeExports.jsxs(material.FormControl, { fullWidth: true, children: [jsxRuntimeExports.jsx(material.InputLabel, { id: "language-select-label", children: "Language" }), jsxRuntimeExports.jsxs(material.Select, { labelId: "language-select-label", value: language, label: "Language", onChange: (e) => setLanguage(e.target.value), children: [jsxRuntimeExports.jsx(material.MenuItem, { value: "en", children: "English" }), jsxRuntimeExports.jsx(material.MenuItem, { value: "es", children: "Espa\u00F1ol" })] })] }));
17673
+ };
17674
+
17675
+ const useTriiTranslation = (namespace) => {
17676
+ const { t, i18n } = useTranslation(namespace);
17677
+ const translate = (key, options) => {
17678
+ return t(key, options);
17679
+ };
17680
+ return {
17681
+ t: translate,
17682
+ i18n,
17683
+ };
14921
17684
  };
14922
17685
 
14923
17686
  exports.ContactInfoPopup = ContactInfoPopup;
17687
+ exports.LanguageProvider = LanguageProvider;
17688
+ exports.LanguageSelector = LanguageSelector;
14924
17689
  exports.TestBox = TestBox;
17690
+ exports.enTranslations = enTranslations;
17691
+ exports.esTranslations = esTranslations;
17692
+ exports.useLanguage = useLanguage;
17693
+ exports.useTriiTranslation = useTriiTranslation;
14925
17694
  //# sourceMappingURL=index.js.map