react-i18next 15.5.1 → 15.5.3
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.
- package/CHANGELOG.md +8 -0
- package/dist/amd/react-i18next.js +79 -92
- package/dist/amd/react-i18next.min.js +1 -1
- package/dist/commonjs/I18nextProvider.js +5 -6
- package/dist/commonjs/Trans.js +16 -17
- package/dist/commonjs/TransWithoutContext.js +17 -18
- package/dist/commonjs/Translation.js +5 -6
- package/dist/commonjs/defaults.js +1 -2
- package/dist/commonjs/useSSR.js +1 -2
- package/dist/commonjs/useTranslation.js +1 -2
- package/dist/commonjs/utils.js +1 -2
- package/dist/commonjs/withSSR.js +5 -6
- package/dist/commonjs/withTranslation.js +27 -31
- package/dist/es/TransWithoutContext.js +1 -1
- package/dist/es/package.json +1 -1
- package/dist/umd/react-i18next.js +79 -92
- package/dist/umd/react-i18next.min.js +1 -1
- package/package.json +13 -12
- package/react-i18next.js +79 -92
- package/react-i18next.min.js +1 -1
- package/src/TransWithoutContext.js +1 -1
|
@@ -163,8 +163,7 @@
|
|
|
163
163
|
});
|
|
164
164
|
i18n.loadLanguages(lng, loadedClb(i18n, cb));
|
|
165
165
|
};
|
|
166
|
-
const hasLoadedNamespace =
|
|
167
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
166
|
+
const hasLoadedNamespace = (ns, i18n, options = {}) => {
|
|
168
167
|
if (!i18n.languages || !i18n.languages.length) {
|
|
169
168
|
warnOnce(i18n, 'NO_LANGUAGES', 'i18n.languages were undefined or empty', {
|
|
170
169
|
languages: i18n.languages
|
|
@@ -218,8 +217,7 @@
|
|
|
218
217
|
useSuspense: true,
|
|
219
218
|
unescape
|
|
220
219
|
};
|
|
221
|
-
const setDefaults =
|
|
222
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
220
|
+
const setDefaults = (options = {}) => {
|
|
223
221
|
defaultOptions = {
|
|
224
222
|
...defaultOptions,
|
|
225
223
|
...options
|
|
@@ -356,7 +354,7 @@
|
|
|
356
354
|
return react.createElement(c.type, {
|
|
357
355
|
...props,
|
|
358
356
|
key: i,
|
|
359
|
-
ref: c.ref
|
|
357
|
+
ref: c.props.ref ?? c.ref
|
|
360
358
|
}, isVoid ? null : inner);
|
|
361
359
|
}));
|
|
362
360
|
}
|
|
@@ -471,23 +469,22 @@
|
|
|
471
469
|
});
|
|
472
470
|
return null;
|
|
473
471
|
};
|
|
474
|
-
function Trans$1(
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
} = _ref;
|
|
472
|
+
function Trans$1({
|
|
473
|
+
children,
|
|
474
|
+
count,
|
|
475
|
+
parent,
|
|
476
|
+
i18nKey,
|
|
477
|
+
context,
|
|
478
|
+
tOptions = {},
|
|
479
|
+
values,
|
|
480
|
+
defaults,
|
|
481
|
+
components,
|
|
482
|
+
ns,
|
|
483
|
+
i18n: i18nFromProps,
|
|
484
|
+
t: tFromProps,
|
|
485
|
+
shouldUnescape,
|
|
486
|
+
...additionalProps
|
|
487
|
+
}) {
|
|
491
488
|
const i18n = i18nFromProps || getI18n();
|
|
492
489
|
if (!i18n) {
|
|
493
490
|
warnOnce(i18n, 'NO_I18NEXT_INSTANCE', `Trans: You need to pass in an i18next instance using i18nextReactModule`, {
|
|
@@ -585,23 +582,22 @@
|
|
|
585
582
|
return ret;
|
|
586
583
|
};
|
|
587
584
|
|
|
588
|
-
function Trans(
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
} = _ref;
|
|
585
|
+
function Trans({
|
|
586
|
+
children,
|
|
587
|
+
count,
|
|
588
|
+
parent,
|
|
589
|
+
i18nKey,
|
|
590
|
+
context,
|
|
591
|
+
tOptions = {},
|
|
592
|
+
values,
|
|
593
|
+
defaults,
|
|
594
|
+
components,
|
|
595
|
+
ns,
|
|
596
|
+
i18n: i18nFromProps,
|
|
597
|
+
t: tFromProps,
|
|
598
|
+
shouldUnescape,
|
|
599
|
+
...additionalProps
|
|
600
|
+
}) {
|
|
605
601
|
const {
|
|
606
602
|
i18n: i18nFromContext,
|
|
607
603
|
defaultNS: defaultNSFromContext
|
|
@@ -635,8 +631,7 @@
|
|
|
635
631
|
};
|
|
636
632
|
const alwaysNewT = (i18n, language, namespace, keyPrefix) => i18n.getFixedT(language, namespace, keyPrefix);
|
|
637
633
|
const useMemoizedT = (i18n, language, namespace, keyPrefix) => react.useCallback(alwaysNewT(i18n, language, namespace, keyPrefix), [i18n, language, namespace, keyPrefix]);
|
|
638
|
-
const useTranslation =
|
|
639
|
-
let props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
634
|
+
const useTranslation = (ns, props = {}) => {
|
|
640
635
|
const {
|
|
641
636
|
i18n: i18nFromProps
|
|
642
637
|
} = props;
|
|
@@ -732,46 +727,41 @@
|
|
|
732
727
|
});
|
|
733
728
|
};
|
|
734
729
|
|
|
735
|
-
const withTranslation = function (
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
passDownProps.ref = forwardedRef;
|
|
755
|
-
} else if (!options.withRef && forwardedRef) {
|
|
756
|
-
passDownProps.forwardedRef = forwardedRef;
|
|
757
|
-
}
|
|
758
|
-
return react.createElement(WrappedComponent, passDownProps);
|
|
730
|
+
const withTranslation = (ns, options = {}) => function Extend(WrappedComponent) {
|
|
731
|
+
function I18nextWithTranslation({
|
|
732
|
+
forwardedRef,
|
|
733
|
+
...rest
|
|
734
|
+
}) {
|
|
735
|
+
const [t, i18n, ready] = useTranslation(ns, {
|
|
736
|
+
...rest,
|
|
737
|
+
keyPrefix: options.keyPrefix
|
|
738
|
+
});
|
|
739
|
+
const passDownProps = {
|
|
740
|
+
...rest,
|
|
741
|
+
t,
|
|
742
|
+
i18n,
|
|
743
|
+
tReady: ready
|
|
744
|
+
};
|
|
745
|
+
if (options.withRef && forwardedRef) {
|
|
746
|
+
passDownProps.ref = forwardedRef;
|
|
747
|
+
} else if (!options.withRef && forwardedRef) {
|
|
748
|
+
passDownProps.forwardedRef = forwardedRef;
|
|
759
749
|
}
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
};
|
|
750
|
+
return react.createElement(WrappedComponent, passDownProps);
|
|
751
|
+
}
|
|
752
|
+
I18nextWithTranslation.displayName = `withI18nextTranslation(${getDisplayName(WrappedComponent)})`;
|
|
753
|
+
I18nextWithTranslation.WrappedComponent = WrappedComponent;
|
|
754
|
+
const forwardRef = (props, ref) => react.createElement(I18nextWithTranslation, Object.assign({}, props, {
|
|
755
|
+
forwardedRef: ref
|
|
756
|
+
}));
|
|
757
|
+
return options.withRef ? react.forwardRef(forwardRef) : I18nextWithTranslation;
|
|
767
758
|
};
|
|
768
759
|
|
|
769
|
-
const Translation =
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
} = _ref;
|
|
760
|
+
const Translation = ({
|
|
761
|
+
ns,
|
|
762
|
+
children,
|
|
763
|
+
...options
|
|
764
|
+
}) => {
|
|
775
765
|
const [t, i18n, ready] = useTranslation(ns, options);
|
|
776
766
|
return children(t, {
|
|
777
767
|
i18n,
|
|
@@ -779,12 +769,11 @@
|
|
|
779
769
|
}, ready);
|
|
780
770
|
};
|
|
781
771
|
|
|
782
|
-
function I18nextProvider(
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
} = _ref;
|
|
772
|
+
function I18nextProvider({
|
|
773
|
+
i18n,
|
|
774
|
+
defaultNS,
|
|
775
|
+
children
|
|
776
|
+
}) {
|
|
788
777
|
const value = react.useMemo(() => ({
|
|
789
778
|
i18n,
|
|
790
779
|
defaultNS
|
|
@@ -794,8 +783,7 @@
|
|
|
794
783
|
}, children);
|
|
795
784
|
}
|
|
796
785
|
|
|
797
|
-
const useSSR =
|
|
798
|
-
let props = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
786
|
+
const useSSR = (initialI18nStore, initialLanguage, props = {}) => {
|
|
799
787
|
const {
|
|
800
788
|
i18n: i18nFromProps
|
|
801
789
|
} = props;
|
|
@@ -822,12 +810,11 @@
|
|
|
822
810
|
};
|
|
823
811
|
|
|
824
812
|
const withSSR = () => function Extend(WrappedComponent) {
|
|
825
|
-
function I18nextWithSSR(
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
} = _ref;
|
|
813
|
+
function I18nextWithSSR({
|
|
814
|
+
initialI18nStore,
|
|
815
|
+
initialLanguage,
|
|
816
|
+
...rest
|
|
817
|
+
}) {
|
|
831
818
|
useSSR(initialI18nStore, initialLanguage);
|
|
832
819
|
return react.createElement(WrappedComponent, {
|
|
833
820
|
...rest
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).ReactI18next={},e.React)}(this,(function(e,n){"use strict";function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s=t({area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0}),r=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function i(e){var n={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},t=e.match(/<\/?([^\s]+?)[/\s>]/);if(t&&(n.name=t[1],(s[t[1]]||"/"===e.charAt(e.length-2))&&(n.voidElement=!0),n.name.startsWith("!--"))){var i=e.indexOf("--\x3e");return{type:"comment",comment:-1!==i?e.slice(4,i):""}}for(var a=new RegExp(r),o=null;null!==(o=a.exec(e));)if(o[0].trim())if(o[1]){var l=o[1].trim(),c=[l,""];l.indexOf("=")>-1&&(c=l.split("=")),n.attrs[c[0]]=c[1],a.lastIndex--}else o[2]&&(n.attrs[o[2]]=o[3].trim().substring(1,o[3].length-1));return n}var a=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,o=/^\s*$/,l=Object.create(null);var c=function(e,n){n||(n={}),n.components||(n.components=l);var t,s=[],r=[],c=-1,u=!1;if(0!==e.indexOf("<")){var p=e.indexOf("<");s.push({type:"text",content:-1===p?e:e.substring(0,p)})}return e.replace(a,(function(a,l){if(u){if(a!=="</"+t.name+">")return;u=!1}var p,d="/"!==a.charAt(1),f=a.startsWith("\x3c!--"),g=l+a.length,m=e.charAt(g);if(f){var h=i(a);return c<0?(s.push(h),s):((p=r[c]).children.push(h),s)}if(d&&(c++,"tag"===(t=i(a)).type&&n.components[t.name]&&(t.type="component",u=!0),t.voidElement||u||!m||"<"===m||t.children.push({type:"text",content:e.slice(g,e.indexOf("<",g))}),0===c&&s.push(t),(p=r[c-1])&&p.children.push(t),r[c]=t),(!d||t.voidElement)&&(c>-1&&(t.voidElement||t.name===a.slice(2,-1))&&(c--,t=-1===c?s:r[c]),!u&&"<"!==m&&m)){p=-1===c?s:r[c].children;var y=e.indexOf("<",g),x=e.slice(g,-1===y?void 0:y);o.test(x)&&(x=" "),(y>-1&&c+p.length>=0||" "!==x)&&p.push({type:"text",content:x})}})),s};const u=(e,n,t,s)=>{const r=[t,{code:n,...s||{}}];if(e?.services?.logger?.forward)return e.services.logger.forward(r,"warn","react-i18next::",!0);y(r[0])&&(r[0]=`react-i18next:: ${r[0]}`),e?.services?.logger?.warn?e.services.logger.warn(...r):console?.warn&&console.warn(...r)},p={},d=(e,n,t,s)=>{y(t)&&p[t]||(y(t)&&(p[t]=new Date),u(e,n,t,s))},f=(e,n)=>()=>{if(e.isInitialized)n();else{const t=()=>{setTimeout((()=>{e.off("initialized",t)}),0),n()};e.on("initialized",t)}},g=(e,n,t)=>{e.loadNamespaces(n,f(e,t))},m=(e,n,t,s)=>{if(y(t)&&(t=[t]),e.options.preload&&e.options.preload.indexOf(n)>-1)return g(e,t,s);t.forEach((n=>{e.options.ns.indexOf(n)<0&&e.options.ns.push(n)})),e.loadLanguages(n,f(e,s))},h=e=>e.displayName||e.name||(y(e)&&e.length>0?e:"Unknown"),y=e=>"string"==typeof e,x=e=>"object"==typeof e&&null!==e,v=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,N={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'," ":" "," ":" ","©":"©","©":"©","®":"®","®":"®","…":"…","…":"…","/":"/","/":"/"},b=e=>N[e];let E={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:e=>e.replace(v,b)};const O=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};E={...E,...e}},I=()=>E;let S;const w=e=>{S=e},$=()=>S,T=(e,n)=>{if(!e)return!1;const t=e.props?.children??e.children;return n?t.length>0:!!t},k=e=>{if(!e)return[];const n=e.props?.children??e.children;return e.props?.i18nIsDynamicList?R(n):n},R=e=>Array.isArray(e)?e:[e],A=(e,t,s,r)=>{if(!e)return"";let i="";const a=R(e),o=t?.transSupportBasicHtmlNodes?t.transKeepBasicHtmlNodesFor??[]:[];return a.forEach(((e,a)=>{if(y(e))i+=`${e}`;else if(n.isValidElement(e)){const{props:n,type:l}=e,c=Object.keys(n).length,u=o.indexOf(l)>-1,p=n.children;if(!p&&u&&!c)return void(i+=`<${l}/>`);if(!p&&(!u||c)||n.i18nIsDynamicList)return void(i+=`<${a}></${a}>`);if(u&&1===c&&y(p))return void(i+=`<${l}>${p}</${l}>`);const d=A(p,t,s,r);i+=`<${a}>${d}</${a}>`}else if(null!==e)if(x(e)){const{format:n,...t}=e,a=Object.keys(t);if(1===a.length){const e=n?`${a[0]}, ${n}`:a[0];return void(i+=`{{${e}}}`)}u(s,"TRANS_INVALID_OBJ","Invalid child - Object should only have keys {{ value, format }} (format is optional).",{i18nKey:r,child:e})}else u(s,"TRANS_INVALID_VAR","Passed in a variable like {number} - pass variables for interpolation as full objects like {{number}}.",{i18nKey:r,child:e});else u(s,"TRANS_NULL_VALUE","Passed in a null value as child",{i18nKey:r})})),i},j=(e,t,s,r,i,a)=>{if(""===t)return[];const o=r.transKeepBasicHtmlNodesFor||[],l=t&&new RegExp(o.map((e=>`<${e}`)).join("|")).test(t);if(!e&&!l&&!a)return[t];const u={},p=e=>{R(e).forEach((e=>{y(e)||(T(e)?p(k(e)):x(e)&&!n.isValidElement(e)&&Object.assign(u,e))}))};p(e);const d=c(`<0>${t}</0>`),f={...u,...i},g=(e,t,s)=>{const r=k(e),i=h(r,t.children,s);return(e=>Array.isArray(e)&&e.every(n.isValidElement))(r)&&0===i.length||e.props?.i18nIsDynamicList?r:i},m=(e,t,s,r,i)=>{e.dummy?(e.children=t,s.push(n.cloneElement(e,{key:r},i?void 0:t))):s.push(...n.Children.map([e],(e=>{const s={...e.props};return delete s.i18nIsDynamicList,n.createElement(e.type,{...s,key:r,ref:e.ref},i?null:t)})))},h=(t,i,c)=>{const u=R(t);return R(i).reduce(((t,i,p)=>{const d=i.children?.[0]?.content&&s.services.interpolator.interpolate(i.children[0].content,f,s.language);if("tag"===i.type){let a=u[parseInt(i.name,10)];1!==c.length||a||(a=c[0][i.name]),a||(a={});const v=0!==Object.keys(i.attrs).length?((e,n)=>{const t={...n};return t.props=Object.assign(e.props,n.props),t})({props:i.attrs},a):a,N=n.isValidElement(v),b=N&&T(i,!0)&&!i.voidElement,E=l&&x(v)&&v.dummy&&!N,O=x(e)&&Object.hasOwnProperty.call(e,i.name);if(y(v)){const e=s.services.interpolator.interpolate(v,f,s.language);t.push(e)}else if(T(v)||b){const e=g(v,i,c);m(v,e,t,p)}else if(E){const e=h(u,i.children,c);m(v,e,t,p)}else if(Number.isNaN(parseFloat(i.name)))if(O){const e=g(v,i,c);m(v,e,t,p,i.voidElement)}else if(r.transSupportBasicHtmlNodes&&o.indexOf(i.name)>-1)if(i.voidElement)t.push(n.createElement(i.name,{key:`${i.name}-${p}`}));else{const e=h(u,i.children,c);t.push(n.createElement(i.name,{key:`${i.name}-${p}`},e))}else if(i.voidElement)t.push(`<${i.name} />`);else{const e=h(u,i.children,c);t.push(`<${i.name}>${e}</${i.name}>`)}else if(x(v)&&!N){const e=i.children[0]?d:null;e&&t.push(e)}else m(v,d,t,p,1!==i.children.length||!d)}else if("text"===i.type){const e=r.transWrapTextNodes,o=a?r.unescape(s.services.interpolator.interpolate(i.content,f,s.language)):s.services.interpolator.interpolate(i.content,f,s.language);e?t.push(n.createElement(e,{key:`${i.name}-${p}`},o)):t.push(o)}return t}),[])},v=h([{dummy:!0,children:e||[]}],d,R(e||[]));return k(v[0])},C=(e,t,s)=>{const r=e.key||t,i=n.cloneElement(e,{key:r});if(!i.props||!i.props.children||s.indexOf(`${t}/>`)<0&&s.indexOf(`${t} />`)<0)return i;return n.createElement((function(){return n.createElement(n.Fragment,null,i)}),{key:r})},L=(e,n,t,s)=>e?Array.isArray(e)?((e,n)=>e.map(((e,t)=>C(e,t,n))))(e,n):x(e)?((e,n)=>{const t={};return Object.keys(e).forEach((s=>{Object.assign(t,{[s]:C(e[s],s,n)})})),t})(e,n):(d(t,"TRANS_INVALID_COMPONENTS",'<Trans /> "components" prop expects an object or array',{i18nKey:s}),null):null;function P(e){let{children:t,count:s,parent:r,i18nKey:i,context:a,tOptions:o={},values:l,defaults:c,components:u,ns:p,i18n:f,t:g,shouldUnescape:m,...h}=e;const x=f||$();if(!x)return d(x,"NO_I18NEXT_INSTANCE","Trans: You need to pass in an i18next instance using i18nextReactModule",{i18nKey:i}),t;const v=g||x.t.bind(x)||(e=>e),N={...I(),...x.options?.react};let b=p||v.ns||x.options?.defaultNS;b=y(b)?[b]:b||["translation"];const E=A(t,N,x,i),O=c||E||N.transEmptyNodeValue||i,{hashTransKey:S}=N,w=i||(S?S(E||O):E||O);x.options?.interpolation?.defaultVariables&&(l=l&&Object.keys(l).length>0?{...l,...x.options.interpolation.defaultVariables}:{...x.options.interpolation.defaultVariables});const T=l||void 0!==s&&!x.options?.interpolation?.alwaysFormat||!t?o.interpolation:{interpolation:{...o.interpolation,prefix:"#$?",suffix:"?$#"}},k={...o,context:a||o.context,count:s,...l,...T,defaultValue:O,ns:b},R=w?v(w,k):O,C=L(u,R,x,i),P=j(C||t,R,x,N,k,m),V=r??N.defaultTransParent;return V?n.createElement(V,h,P):P}const V={type:"3rdParty",init(e){O(e.options.react),w(e)}},_=n.createContext();class D{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach((e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)}))}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}const K=e=>async n=>({...await(e.getInitialProps?.(n))??{},...z()}),z=()=>{const e=$(),n=e.reportNamespaces?.getUsedNamespaces()??[],t={},s={};return e.languages.forEach((t=>{s[t]={},n.forEach((n=>{s[t][n]=e.getResourceBundle(t,n)||{}}))})),t.initialI18nStore=s,t.initialLanguage=e.language,t};const U=(e,n,t,s)=>e.getFixedT(n,t,s),F=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{i18n:s}=t,{i18n:r,defaultNS:i}=n.useContext(_)||{},a=s||r||$();if(a&&!a.reportNamespaces&&(a.reportNamespaces=new D),!a){d(a,"NO_I18NEXT_INSTANCE","useTranslation: You will need to pass in an i18next instance by using initReactI18next");const e=(e,n)=>y(n)?n:x(n)&&y(n.defaultValue)?n.defaultValue:Array.isArray(e)?e[e.length-1]:e,n=[e,{},!1];return n.t=e,n.i18n={},n.ready=!1,n}a.options.react?.wait&&d(a,"DEPRECATED_OPTION","useTranslation: It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const o={...I(),...a.options.react,...t},{useSuspense:l,keyPrefix:c}=o;let u=e||i||a.options?.defaultNS;u=y(u)?[u]:u||["translation"],a.reportNamespaces.addUsedNamespaces?.(u);const p=(a.isInitialized||a.initializedStoreOnce)&&u.every((e=>function(e,n){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return n.languages&&n.languages.length?n.hasLoadedNamespace(e,{lng:t.lng,precheck:(n,s)=>{if(t.bindI18n?.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!s(n.isLanguageChangingTo,e))return!1}}):(d(n,"NO_LANGUAGES","i18n.languages were undefined or empty",{languages:n.languages}),!0)}(e,a,o))),f=((e,t,s,r)=>n.useCallback(U(e,t,s,r),[e,t,s,r]))(a,t.lng||null,"fallback"===o.nsMode?u:u[0],c),h=()=>f,v=()=>U(a,t.lng||null,"fallback"===o.nsMode?u:u[0],c),[N,b]=n.useState(h);let E=u.join();t.lng&&(E=`${t.lng}${E}`);const O=((e,t)=>{const s=n.useRef();return n.useEffect((()=>{s.current=e}),[e,t]),s.current})(E),S=n.useRef(!0);n.useEffect((()=>{const{bindI18n:e,bindI18nStore:n}=o;S.current=!0,p||l||(t.lng?m(a,t.lng,u,(()=>{S.current&&b(v)})):g(a,u,(()=>{S.current&&b(v)}))),p&&O&&O!==E&&S.current&&b(v);const s=()=>{S.current&&b(v)};return e&&a?.on(e,s),n&&a?.store.on(n,s),()=>{S.current=!1,a&&e?.split(" ").forEach((e=>a.off(e,s))),n&&a&&n.split(" ").forEach((e=>a.store.off(e,s)))}}),[a,E]),n.useEffect((()=>{S.current&&p&&b(h)}),[a,c,p]);const w=[N,a,p];if(w.t=N,w.i18n=a,w.ready=p,p)return w;if(!p&&!l)return w;throw new Promise((e=>{t.lng?m(a,t.lng,u,(()=>e())):g(a,u,(()=>e()))}))};const B=function(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const{i18n:r}=s,{i18n:i}=n.useContext(_)||{},a=r||i||$();a.options?.isClone||(e&&!a.initializedStoreOnce&&(a.services.resourceStore.data=e,a.options.ns=Object.values(e).reduce(((e,n)=>(Object.keys(n).forEach((n=>{e.indexOf(n)<0&&e.push(n)})),e)),a.options.ns),a.initializedStoreOnce=!0,a.isInitialized=!0),t&&!a.initializedLanguageOnce&&(a.changeLanguage(t),a.initializedLanguageOnce=!0))};e.I18nContext=_,e.I18nextProvider=function(e){let{i18n:t,defaultNS:s,children:r}=e;const i=n.useMemo((()=>({i18n:t,defaultNS:s})),[t,s]);return n.createElement(_.Provider,{value:i},r)},e.Trans=function(e){let{children:t,count:s,parent:r,i18nKey:i,context:a,tOptions:o={},values:l,defaults:c,components:u,ns:p,i18n:d,t:f,shouldUnescape:g,...m}=e;const{i18n:h,defaultNS:y}=n.useContext(_)||{},x=d||h||$(),v=f||x?.t.bind(x);return P({children:t,count:s,parent:r,i18nKey:i,context:a,tOptions:o,values:l,defaults:c,components:u,ns:p||v?.ns||y||x?.options?.defaultNS,i18n:x,t:f,shouldUnescape:g,...m})},e.TransWithoutContext=P,e.Translation=e=>{let{ns:n,children:t,...s}=e;const[r,i,a]=F(n,s);return t(r,{i18n:i,lng:i.language},a)},e.composeInitialProps=K,e.date=()=>"",e.getDefaults=I,e.getI18n=$,e.getInitialProps=z,e.initReactI18next=V,e.number=()=>"",e.plural=()=>"",e.select=()=>"",e.selectOrdinal=()=>"",e.setDefaults=O,e.setI18n=w,e.time=()=>"",e.useSSR=B,e.useTranslation=F,e.withSSR=()=>function(e){function t(t){let{initialI18nStore:s,initialLanguage:r,...i}=t;return B(s,r),n.createElement(e,{...i})}return t.getInitialProps=K(e),t.displayName=`withI18nextSSR(${h(e)})`,t.WrappedComponent=e,t},e.withTranslation=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(s){function r(r){let{forwardedRef:i,...a}=r;const[o,l,c]=F(e,{...a,keyPrefix:t.keyPrefix}),u={...a,t:o,i18n:l,tReady:c};return t.withRef&&i?u.ref=i:!t.withRef&&i&&(u.forwardedRef=i),n.createElement(s,u)}r.displayName=`withI18nextTranslation(${h(s)})`,r.WrappedComponent=s;return t.withRef?n.forwardRef(((e,t)=>n.createElement(r,Object.assign({},e,{forwardedRef:t})))):r}}}));
|
|
1
|
+
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).ReactI18next={},e.React)}(this,(function(e,n){"use strict";function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s=t({area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0}),r=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function a(e){var n={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},t=e.match(/<\/?([^\s]+?)[/\s>]/);if(t&&(n.name=t[1],(s[t[1]]||"/"===e.charAt(e.length-2))&&(n.voidElement=!0),n.name.startsWith("!--"))){var a=e.indexOf("--\x3e");return{type:"comment",comment:-1!==a?e.slice(4,a):""}}for(var i=new RegExp(r),o=null;null!==(o=i.exec(e));)if(o[0].trim())if(o[1]){var l=o[1].trim(),c=[l,""];l.indexOf("=")>-1&&(c=l.split("=")),n.attrs[c[0]]=c[1],i.lastIndex--}else o[2]&&(n.attrs[o[2]]=o[3].trim().substring(1,o[3].length-1));return n}var i=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,o=/^\s*$/,l=Object.create(null);var c=function(e,n){n||(n={}),n.components||(n.components=l);var t,s=[],r=[],c=-1,u=!1;if(0!==e.indexOf("<")){var p=e.indexOf("<");s.push({type:"text",content:-1===p?e:e.substring(0,p)})}return e.replace(i,(function(i,l){if(u){if(i!=="</"+t.name+">")return;u=!1}var p,d="/"!==i.charAt(1),f=i.startsWith("\x3c!--"),m=l+i.length,g=e.charAt(m);if(f){var h=a(i);return c<0?(s.push(h),s):((p=r[c]).children.push(h),s)}if(d&&(c++,"tag"===(t=a(i)).type&&n.components[t.name]&&(t.type="component",u=!0),t.voidElement||u||!g||"<"===g||t.children.push({type:"text",content:e.slice(m,e.indexOf("<",m))}),0===c&&s.push(t),(p=r[c-1])&&p.children.push(t),r[c]=t),(!d||t.voidElement)&&(c>-1&&(t.voidElement||t.name===i.slice(2,-1))&&(c--,t=-1===c?s:r[c]),!u&&"<"!==g&&g)){p=-1===c?s:r[c].children;var y=e.indexOf("<",m),x=e.slice(m,-1===y?void 0:y);o.test(x)&&(x=" "),(y>-1&&c+p.length>=0||" "!==x)&&p.push({type:"text",content:x})}})),s};const u=(e,n,t,s)=>{const r=[t,{code:n,...s||{}}];if(e?.services?.logger?.forward)return e.services.logger.forward(r,"warn","react-i18next::",!0);y(r[0])&&(r[0]=`react-i18next:: ${r[0]}`),e?.services?.logger?.warn?e.services.logger.warn(...r):console?.warn&&console.warn(...r)},p={},d=(e,n,t,s)=>{y(t)&&p[t]||(y(t)&&(p[t]=new Date),u(e,n,t,s))},f=(e,n)=>()=>{if(e.isInitialized)n();else{const t=()=>{setTimeout((()=>{e.off("initialized",t)}),0),n()};e.on("initialized",t)}},m=(e,n,t)=>{e.loadNamespaces(n,f(e,t))},g=(e,n,t,s)=>{if(y(t)&&(t=[t]),e.options.preload&&e.options.preload.indexOf(n)>-1)return m(e,t,s);t.forEach((n=>{e.options.ns.indexOf(n)<0&&e.options.ns.push(n)})),e.loadLanguages(n,f(e,s))},h=e=>e.displayName||e.name||(y(e)&&e.length>0?e:"Unknown"),y=e=>"string"==typeof e,x=e=>"object"==typeof e&&null!==e,N=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,b={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'," ":" "," ":" ","©":"©","©":"©","®":"®","®":"®","…":"…","…":"…","/":"/","/":"/"},v=e=>b[e];let E={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:e=>e.replace(N,v)};const O=(e={})=>{E={...E,...e}},I=()=>E;let S;const w=e=>{S=e},$=()=>S,T=(e,n)=>{if(!e)return!1;const t=e.props?.children??e.children;return n?t.length>0:!!t},k=e=>{if(!e)return[];const n=e.props?.children??e.children;return e.props?.i18nIsDynamicList?R(n):n},R=e=>Array.isArray(e)?e:[e],A=(e,t,s,r)=>{if(!e)return"";let a="";const i=R(e),o=t?.transSupportBasicHtmlNodes?t.transKeepBasicHtmlNodesFor??[]:[];return i.forEach(((e,i)=>{if(y(e))a+=`${e}`;else if(n.isValidElement(e)){const{props:n,type:l}=e,c=Object.keys(n).length,u=o.indexOf(l)>-1,p=n.children;if(!p&&u&&!c)return void(a+=`<${l}/>`);if(!p&&(!u||c)||n.i18nIsDynamicList)return void(a+=`<${i}></${i}>`);if(u&&1===c&&y(p))return void(a+=`<${l}>${p}</${l}>`);const d=A(p,t,s,r);a+=`<${i}>${d}</${i}>`}else if(null!==e)if(x(e)){const{format:n,...t}=e,i=Object.keys(t);if(1===i.length){const e=n?`${i[0]}, ${n}`:i[0];return void(a+=`{{${e}}}`)}u(s,"TRANS_INVALID_OBJ","Invalid child - Object should only have keys {{ value, format }} (format is optional).",{i18nKey:r,child:e})}else u(s,"TRANS_INVALID_VAR","Passed in a variable like {number} - pass variables for interpolation as full objects like {{number}}.",{i18nKey:r,child:e});else u(s,"TRANS_NULL_VALUE","Passed in a null value as child",{i18nKey:r})})),a},j=(e,t,s,r,a,i)=>{if(""===t)return[];const o=r.transKeepBasicHtmlNodesFor||[],l=t&&new RegExp(o.map((e=>`<${e}`)).join("|")).test(t);if(!e&&!l&&!i)return[t];const u={},p=e=>{R(e).forEach((e=>{y(e)||(T(e)?p(k(e)):x(e)&&!n.isValidElement(e)&&Object.assign(u,e))}))};p(e);const d=c(`<0>${t}</0>`),f={...u,...a},m=(e,t,s)=>{const r=k(e),a=h(r,t.children,s);return(e=>Array.isArray(e)&&e.every(n.isValidElement))(r)&&0===a.length||e.props?.i18nIsDynamicList?r:a},g=(e,t,s,r,a)=>{e.dummy?(e.children=t,s.push(n.cloneElement(e,{key:r},a?void 0:t))):s.push(...n.Children.map([e],(e=>{const s={...e.props};return delete s.i18nIsDynamicList,n.createElement(e.type,{...s,key:r,ref:e.props.ref??e.ref},a?null:t)})))},h=(t,a,c)=>{const u=R(t);return R(a).reduce(((t,a,p)=>{const d=a.children?.[0]?.content&&s.services.interpolator.interpolate(a.children[0].content,f,s.language);if("tag"===a.type){let i=u[parseInt(a.name,10)];1!==c.length||i||(i=c[0][a.name]),i||(i={});const N=0!==Object.keys(a.attrs).length?((e,n)=>{const t={...n};return t.props=Object.assign(e.props,n.props),t})({props:a.attrs},i):i,b=n.isValidElement(N),v=b&&T(a,!0)&&!a.voidElement,E=l&&x(N)&&N.dummy&&!b,O=x(e)&&Object.hasOwnProperty.call(e,a.name);if(y(N)){const e=s.services.interpolator.interpolate(N,f,s.language);t.push(e)}else if(T(N)||v){const e=m(N,a,c);g(N,e,t,p)}else if(E){const e=h(u,a.children,c);g(N,e,t,p)}else if(Number.isNaN(parseFloat(a.name)))if(O){const e=m(N,a,c);g(N,e,t,p,a.voidElement)}else if(r.transSupportBasicHtmlNodes&&o.indexOf(a.name)>-1)if(a.voidElement)t.push(n.createElement(a.name,{key:`${a.name}-${p}`}));else{const e=h(u,a.children,c);t.push(n.createElement(a.name,{key:`${a.name}-${p}`},e))}else if(a.voidElement)t.push(`<${a.name} />`);else{const e=h(u,a.children,c);t.push(`<${a.name}>${e}</${a.name}>`)}else if(x(N)&&!b){const e=a.children[0]?d:null;e&&t.push(e)}else g(N,d,t,p,1!==a.children.length||!d)}else if("text"===a.type){const e=r.transWrapTextNodes,o=i?r.unescape(s.services.interpolator.interpolate(a.content,f,s.language)):s.services.interpolator.interpolate(a.content,f,s.language);e?t.push(n.createElement(e,{key:`${a.name}-${p}`},o)):t.push(o)}return t}),[])},N=h([{dummy:!0,children:e||[]}],d,R(e||[]));return k(N[0])},C=(e,t,s)=>{const r=e.key||t,a=n.cloneElement(e,{key:r});if(!a.props||!a.props.children||s.indexOf(`${t}/>`)<0&&s.indexOf(`${t} />`)<0)return a;return n.createElement((function(){return n.createElement(n.Fragment,null,a)}),{key:r})},L=(e,n,t,s)=>e?Array.isArray(e)?((e,n)=>e.map(((e,t)=>C(e,t,n))))(e,n):x(e)?((e,n)=>{const t={};return Object.keys(e).forEach((s=>{Object.assign(t,{[s]:C(e[s],s,n)})})),t})(e,n):(d(t,"TRANS_INVALID_COMPONENTS",'<Trans /> "components" prop expects an object or array',{i18nKey:s}),null):null;function P({children:e,count:t,parent:s,i18nKey:r,context:a,tOptions:i={},values:o,defaults:l,components:c,ns:u,i18n:p,t:f,shouldUnescape:m,...g}){const h=p||$();if(!h)return d(h,"NO_I18NEXT_INSTANCE","Trans: You need to pass in an i18next instance using i18nextReactModule",{i18nKey:r}),e;const x=f||h.t.bind(h)||(e=>e),N={...I(),...h.options?.react};let b=u||x.ns||h.options?.defaultNS;b=y(b)?[b]:b||["translation"];const v=A(e,N,h,r),E=l||v||N.transEmptyNodeValue||r,{hashTransKey:O}=N,S=r||(O?O(v||E):v||E);h.options?.interpolation?.defaultVariables&&(o=o&&Object.keys(o).length>0?{...o,...h.options.interpolation.defaultVariables}:{...h.options.interpolation.defaultVariables});const w=o||void 0!==t&&!h.options?.interpolation?.alwaysFormat||!e?i.interpolation:{interpolation:{...i.interpolation,prefix:"#$?",suffix:"?$#"}},T={...i,context:a||i.context,count:t,...o,...w,defaultValue:E,ns:b},k=S?x(S,T):E,R=L(c,k,h,r),C=j(R||e,k,h,N,T,m),P=s??N.defaultTransParent;return P?n.createElement(P,g,C):C}const V={type:"3rdParty",init(e){O(e.options.react),w(e)}},_=n.createContext();class D{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach((e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)}))}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}const K=e=>async n=>({...await(e.getInitialProps?.(n))??{},...z()}),z=()=>{const e=$(),n=e.reportNamespaces?.getUsedNamespaces()??[],t={},s={};return e.languages.forEach((t=>{s[t]={},n.forEach((n=>{s[t][n]=e.getResourceBundle(t,n)||{}}))})),t.initialI18nStore=s,t.initialLanguage=e.language,t};const U=(e,n,t,s)=>e.getFixedT(n,t,s),F=(e,t={})=>{const{i18n:s}=t,{i18n:r,defaultNS:a}=n.useContext(_)||{},i=s||r||$();if(i&&!i.reportNamespaces&&(i.reportNamespaces=new D),!i){d(i,"NO_I18NEXT_INSTANCE","useTranslation: You will need to pass in an i18next instance by using initReactI18next");const e=(e,n)=>y(n)?n:x(n)&&y(n.defaultValue)?n.defaultValue:Array.isArray(e)?e[e.length-1]:e,n=[e,{},!1];return n.t=e,n.i18n={},n.ready=!1,n}i.options.react?.wait&&d(i,"DEPRECATED_OPTION","useTranslation: It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const o={...I(),...i.options.react,...t},{useSuspense:l,keyPrefix:c}=o;let u=e||a||i.options?.defaultNS;u=y(u)?[u]:u||["translation"],i.reportNamespaces.addUsedNamespaces?.(u);const p=(i.isInitialized||i.initializedStoreOnce)&&u.every((e=>((e,n,t={})=>n.languages&&n.languages.length?n.hasLoadedNamespace(e,{lng:t.lng,precheck:(n,s)=>{if(t.bindI18n?.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!s(n.isLanguageChangingTo,e))return!1}}):(d(n,"NO_LANGUAGES","i18n.languages were undefined or empty",{languages:n.languages}),!0))(e,i,o))),f=((e,t,s,r)=>n.useCallback(U(e,t,s,r),[e,t,s,r]))(i,t.lng||null,"fallback"===o.nsMode?u:u[0],c),h=()=>f,N=()=>U(i,t.lng||null,"fallback"===o.nsMode?u:u[0],c),[b,v]=n.useState(h);let E=u.join();t.lng&&(E=`${t.lng}${E}`);const O=((e,t)=>{const s=n.useRef();return n.useEffect((()=>{s.current=e}),[e,t]),s.current})(E),S=n.useRef(!0);n.useEffect((()=>{const{bindI18n:e,bindI18nStore:n}=o;S.current=!0,p||l||(t.lng?g(i,t.lng,u,(()=>{S.current&&v(N)})):m(i,u,(()=>{S.current&&v(N)}))),p&&O&&O!==E&&S.current&&v(N);const s=()=>{S.current&&v(N)};return e&&i?.on(e,s),n&&i?.store.on(n,s),()=>{S.current=!1,i&&e?.split(" ").forEach((e=>i.off(e,s))),n&&i&&n.split(" ").forEach((e=>i.store.off(e,s)))}}),[i,E]),n.useEffect((()=>{S.current&&p&&v(h)}),[i,c,p]);const w=[b,i,p];if(w.t=b,w.i18n=i,w.ready=p,p)return w;if(!p&&!l)return w;throw new Promise((e=>{t.lng?g(i,t.lng,u,(()=>e())):m(i,u,(()=>e()))}))};const B=(e,t,s={})=>{const{i18n:r}=s,{i18n:a}=n.useContext(_)||{},i=r||a||$();i.options?.isClone||(e&&!i.initializedStoreOnce&&(i.services.resourceStore.data=e,i.options.ns=Object.values(e).reduce(((e,n)=>(Object.keys(n).forEach((n=>{e.indexOf(n)<0&&e.push(n)})),e)),i.options.ns),i.initializedStoreOnce=!0,i.isInitialized=!0),t&&!i.initializedLanguageOnce&&(i.changeLanguage(t),i.initializedLanguageOnce=!0))};e.I18nContext=_,e.I18nextProvider=function({i18n:e,defaultNS:t,children:s}){const r=n.useMemo((()=>({i18n:e,defaultNS:t})),[e,t]);return n.createElement(_.Provider,{value:r},s)},e.Trans=function({children:e,count:t,parent:s,i18nKey:r,context:a,tOptions:i={},values:o,defaults:l,components:c,ns:u,i18n:p,t:d,shouldUnescape:f,...m}){const{i18n:g,defaultNS:h}=n.useContext(_)||{},y=p||g||$(),x=d||y?.t.bind(y);return P({children:e,count:t,parent:s,i18nKey:r,context:a,tOptions:i,values:o,defaults:l,components:c,ns:u||x?.ns||h||y?.options?.defaultNS,i18n:y,t:d,shouldUnescape:f,...m})},e.TransWithoutContext=P,e.Translation=({ns:e,children:n,...t})=>{const[s,r,a]=F(e,t);return n(s,{i18n:r,lng:r.language},a)},e.composeInitialProps=K,e.date=()=>"",e.getDefaults=I,e.getI18n=$,e.getInitialProps=z,e.initReactI18next=V,e.number=()=>"",e.plural=()=>"",e.select=()=>"",e.selectOrdinal=()=>"",e.setDefaults=O,e.setI18n=w,e.time=()=>"",e.useSSR=B,e.useTranslation=F,e.withSSR=()=>function(e){function t({initialI18nStore:t,initialLanguage:s,...r}){return B(t,s),n.createElement(e,{...r})}return t.getInitialProps=K(e),t.displayName=`withI18nextSSR(${h(e)})`,t.WrappedComponent=e,t},e.withTranslation=(e,t={})=>function(s){function r({forwardedRef:r,...a}){const[i,o,l]=F(e,{...a,keyPrefix:t.keyPrefix}),c={...a,t:i,i18n:o,tReady:l};return t.withRef&&r?c.ref=r:!t.withRef&&r&&(c.forwardedRef=r),n.createElement(s,c)}r.displayName=`withI18nextTranslation(${h(s)})`,r.WrappedComponent=s;return t.withRef?n.forwardRef(((e,t)=>n.createElement(r,Object.assign({},e,{forwardedRef:t})))):r}}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-i18next",
|
|
3
|
-
"version": "15.5.
|
|
3
|
+
"version": "15.5.3",
|
|
4
4
|
"description": "Internationalization for react done right. Using the i18next i18n ecosystem.",
|
|
5
5
|
"main": "dist/commonjs/index.js",
|
|
6
6
|
"types": "./index.d.mts",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"url": "https://github.com/i18next/react-i18next.git"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@babel/runtime": "^7.
|
|
67
|
+
"@babel/runtime": "^7.27.6",
|
|
68
68
|
"html-parse-stringify": "^3.0.1"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
@@ -84,17 +84,17 @@
|
|
|
84
84
|
}
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
|
-
"@babel/cli": "^7.
|
|
88
|
-
"@babel/core": "^7.
|
|
89
|
-
"@babel/eslint-parser": "^7.
|
|
87
|
+
"@babel/cli": "^7.27.2",
|
|
88
|
+
"@babel/core": "^7.27.4",
|
|
89
|
+
"@babel/eslint-parser": "^7.27.5",
|
|
90
90
|
"@babel/plugin-proposal-async-generator-functions": "^7.20.7",
|
|
91
91
|
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
|
|
92
|
-
"@babel/plugin-transform-modules-commonjs": "^7.
|
|
93
|
-
"@babel/plugin-transform-runtime": "^7.
|
|
92
|
+
"@babel/plugin-transform-modules-commonjs": "^7.27.1",
|
|
93
|
+
"@babel/plugin-transform-runtime": "^7.27.4",
|
|
94
94
|
"@babel/polyfill": "^7.12.1",
|
|
95
|
-
"@babel/preset-env": "^7.
|
|
96
|
-
"@babel/preset-react": "^7.
|
|
97
|
-
"@babel/register": "^7.
|
|
95
|
+
"@babel/preset-env": "^7.27.2",
|
|
96
|
+
"@babel/preset-react": "^7.27.1",
|
|
97
|
+
"@babel/register": "^7.27.1",
|
|
98
98
|
"@rollup/plugin-babel": "^6.0.4",
|
|
99
99
|
"@rollup/plugin-commonjs": "^26.0.1",
|
|
100
100
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
"eslint-plugin-testing-library": "^6.3.0",
|
|
124
124
|
"happy-dom": "^14.12.3",
|
|
125
125
|
"husky": "^9.1.4",
|
|
126
|
-
"i18next": "^
|
|
126
|
+
"i18next": "^25.2.1",
|
|
127
127
|
"lint-staged": "^15.2.9",
|
|
128
128
|
"mkdirp": "^3.0.1",
|
|
129
129
|
"prettier": "^3.3.3",
|
|
@@ -162,5 +162,6 @@
|
|
|
162
162
|
"author": "Jan Mühlemann <jan.muehlemann@gmail.com> (https://github.com/jamuhl)",
|
|
163
163
|
"license": "MIT",
|
|
164
164
|
"lock": false,
|
|
165
|
-
"sideEffects": false
|
|
165
|
+
"sideEffects": false,
|
|
166
|
+
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
|
166
167
|
}
|
package/react-i18next.js
CHANGED
|
@@ -163,8 +163,7 @@
|
|
|
163
163
|
});
|
|
164
164
|
i18n.loadLanguages(lng, loadedClb(i18n, cb));
|
|
165
165
|
};
|
|
166
|
-
const hasLoadedNamespace =
|
|
167
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
166
|
+
const hasLoadedNamespace = (ns, i18n, options = {}) => {
|
|
168
167
|
if (!i18n.languages || !i18n.languages.length) {
|
|
169
168
|
warnOnce(i18n, 'NO_LANGUAGES', 'i18n.languages were undefined or empty', {
|
|
170
169
|
languages: i18n.languages
|
|
@@ -218,8 +217,7 @@
|
|
|
218
217
|
useSuspense: true,
|
|
219
218
|
unescape
|
|
220
219
|
};
|
|
221
|
-
const setDefaults =
|
|
222
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
220
|
+
const setDefaults = (options = {}) => {
|
|
223
221
|
defaultOptions = {
|
|
224
222
|
...defaultOptions,
|
|
225
223
|
...options
|
|
@@ -356,7 +354,7 @@
|
|
|
356
354
|
return react.createElement(c.type, {
|
|
357
355
|
...props,
|
|
358
356
|
key: i,
|
|
359
|
-
ref: c.ref
|
|
357
|
+
ref: c.props.ref ?? c.ref
|
|
360
358
|
}, isVoid ? null : inner);
|
|
361
359
|
}));
|
|
362
360
|
}
|
|
@@ -471,23 +469,22 @@
|
|
|
471
469
|
});
|
|
472
470
|
return null;
|
|
473
471
|
};
|
|
474
|
-
function Trans$1(
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
} = _ref;
|
|
472
|
+
function Trans$1({
|
|
473
|
+
children,
|
|
474
|
+
count,
|
|
475
|
+
parent,
|
|
476
|
+
i18nKey,
|
|
477
|
+
context,
|
|
478
|
+
tOptions = {},
|
|
479
|
+
values,
|
|
480
|
+
defaults,
|
|
481
|
+
components,
|
|
482
|
+
ns,
|
|
483
|
+
i18n: i18nFromProps,
|
|
484
|
+
t: tFromProps,
|
|
485
|
+
shouldUnescape,
|
|
486
|
+
...additionalProps
|
|
487
|
+
}) {
|
|
491
488
|
const i18n = i18nFromProps || getI18n();
|
|
492
489
|
if (!i18n) {
|
|
493
490
|
warnOnce(i18n, 'NO_I18NEXT_INSTANCE', `Trans: You need to pass in an i18next instance using i18nextReactModule`, {
|
|
@@ -585,23 +582,22 @@
|
|
|
585
582
|
return ret;
|
|
586
583
|
};
|
|
587
584
|
|
|
588
|
-
function Trans(
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
} = _ref;
|
|
585
|
+
function Trans({
|
|
586
|
+
children,
|
|
587
|
+
count,
|
|
588
|
+
parent,
|
|
589
|
+
i18nKey,
|
|
590
|
+
context,
|
|
591
|
+
tOptions = {},
|
|
592
|
+
values,
|
|
593
|
+
defaults,
|
|
594
|
+
components,
|
|
595
|
+
ns,
|
|
596
|
+
i18n: i18nFromProps,
|
|
597
|
+
t: tFromProps,
|
|
598
|
+
shouldUnescape,
|
|
599
|
+
...additionalProps
|
|
600
|
+
}) {
|
|
605
601
|
const {
|
|
606
602
|
i18n: i18nFromContext,
|
|
607
603
|
defaultNS: defaultNSFromContext
|
|
@@ -635,8 +631,7 @@
|
|
|
635
631
|
};
|
|
636
632
|
const alwaysNewT = (i18n, language, namespace, keyPrefix) => i18n.getFixedT(language, namespace, keyPrefix);
|
|
637
633
|
const useMemoizedT = (i18n, language, namespace, keyPrefix) => react.useCallback(alwaysNewT(i18n, language, namespace, keyPrefix), [i18n, language, namespace, keyPrefix]);
|
|
638
|
-
const useTranslation =
|
|
639
|
-
let props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
634
|
+
const useTranslation = (ns, props = {}) => {
|
|
640
635
|
const {
|
|
641
636
|
i18n: i18nFromProps
|
|
642
637
|
} = props;
|
|
@@ -732,46 +727,41 @@
|
|
|
732
727
|
});
|
|
733
728
|
};
|
|
734
729
|
|
|
735
|
-
const withTranslation = function (
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
passDownProps.ref = forwardedRef;
|
|
755
|
-
} else if (!options.withRef && forwardedRef) {
|
|
756
|
-
passDownProps.forwardedRef = forwardedRef;
|
|
757
|
-
}
|
|
758
|
-
return react.createElement(WrappedComponent, passDownProps);
|
|
730
|
+
const withTranslation = (ns, options = {}) => function Extend(WrappedComponent) {
|
|
731
|
+
function I18nextWithTranslation({
|
|
732
|
+
forwardedRef,
|
|
733
|
+
...rest
|
|
734
|
+
}) {
|
|
735
|
+
const [t, i18n, ready] = useTranslation(ns, {
|
|
736
|
+
...rest,
|
|
737
|
+
keyPrefix: options.keyPrefix
|
|
738
|
+
});
|
|
739
|
+
const passDownProps = {
|
|
740
|
+
...rest,
|
|
741
|
+
t,
|
|
742
|
+
i18n,
|
|
743
|
+
tReady: ready
|
|
744
|
+
};
|
|
745
|
+
if (options.withRef && forwardedRef) {
|
|
746
|
+
passDownProps.ref = forwardedRef;
|
|
747
|
+
} else if (!options.withRef && forwardedRef) {
|
|
748
|
+
passDownProps.forwardedRef = forwardedRef;
|
|
759
749
|
}
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
};
|
|
750
|
+
return react.createElement(WrappedComponent, passDownProps);
|
|
751
|
+
}
|
|
752
|
+
I18nextWithTranslation.displayName = `withI18nextTranslation(${getDisplayName(WrappedComponent)})`;
|
|
753
|
+
I18nextWithTranslation.WrappedComponent = WrappedComponent;
|
|
754
|
+
const forwardRef = (props, ref) => react.createElement(I18nextWithTranslation, Object.assign({}, props, {
|
|
755
|
+
forwardedRef: ref
|
|
756
|
+
}));
|
|
757
|
+
return options.withRef ? react.forwardRef(forwardRef) : I18nextWithTranslation;
|
|
767
758
|
};
|
|
768
759
|
|
|
769
|
-
const Translation =
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
} = _ref;
|
|
760
|
+
const Translation = ({
|
|
761
|
+
ns,
|
|
762
|
+
children,
|
|
763
|
+
...options
|
|
764
|
+
}) => {
|
|
775
765
|
const [t, i18n, ready] = useTranslation(ns, options);
|
|
776
766
|
return children(t, {
|
|
777
767
|
i18n,
|
|
@@ -779,12 +769,11 @@
|
|
|
779
769
|
}, ready);
|
|
780
770
|
};
|
|
781
771
|
|
|
782
|
-
function I18nextProvider(
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
} = _ref;
|
|
772
|
+
function I18nextProvider({
|
|
773
|
+
i18n,
|
|
774
|
+
defaultNS,
|
|
775
|
+
children
|
|
776
|
+
}) {
|
|
788
777
|
const value = react.useMemo(() => ({
|
|
789
778
|
i18n,
|
|
790
779
|
defaultNS
|
|
@@ -794,8 +783,7 @@
|
|
|
794
783
|
}, children);
|
|
795
784
|
}
|
|
796
785
|
|
|
797
|
-
const useSSR =
|
|
798
|
-
let props = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
786
|
+
const useSSR = (initialI18nStore, initialLanguage, props = {}) => {
|
|
799
787
|
const {
|
|
800
788
|
i18n: i18nFromProps
|
|
801
789
|
} = props;
|
|
@@ -822,12 +810,11 @@
|
|
|
822
810
|
};
|
|
823
811
|
|
|
824
812
|
const withSSR = () => function Extend(WrappedComponent) {
|
|
825
|
-
function I18nextWithSSR(
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
} = _ref;
|
|
813
|
+
function I18nextWithSSR({
|
|
814
|
+
initialI18nStore,
|
|
815
|
+
initialLanguage,
|
|
816
|
+
...rest
|
|
817
|
+
}) {
|
|
831
818
|
useSSR(initialI18nStore, initialLanguage);
|
|
832
819
|
return react.createElement(WrappedComponent, {
|
|
833
820
|
...rest
|