@trackunit/i18n-library-translation 2.4.30 → 2.4.32
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/index.cjs.js +11 -3
- package/index.esm.js +11 -3
- package/package.json +3 -3
package/index.cjs.js
CHANGED
|
@@ -24,8 +24,9 @@ function NamespaceTrans(props) {
|
|
|
24
24
|
const LANG_STORAGE_KEY = "i18nextLng";
|
|
25
25
|
/** Holds all available TranslationResource by namespace */
|
|
26
26
|
const availableTranslations = {};
|
|
27
|
-
/** Holds all available TranslationResource by namespace */
|
|
28
27
|
let hasBeenInitialized = false;
|
|
28
|
+
let initializedNamespacesKey = "";
|
|
29
|
+
const namespacesKey = () => Object.keys(availableTranslations).toSorted().join("\0");
|
|
29
30
|
/**
|
|
30
31
|
* Use this function to register your translations before the i18next is initialized.
|
|
31
32
|
*
|
|
@@ -53,6 +54,10 @@ const registerTranslations = (resource) => {
|
|
|
53
54
|
* Pass the apps/extensions TranslationResource to this function for them to be available as well.
|
|
54
55
|
*/
|
|
55
56
|
const initializeTranslationsForApp = () => {
|
|
57
|
+
const nextNamespacesKey = namespacesKey();
|
|
58
|
+
if (hasBeenInitialized && nextNamespacesKey === initializedNamespacesKey) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
56
61
|
// Get selected language from url or fallback to english
|
|
57
62
|
const queryString = window.location.search;
|
|
58
63
|
const urlParams = new URLSearchParams(queryString);
|
|
@@ -84,6 +89,7 @@ const initializeTranslationsForApp = () => {
|
|
|
84
89
|
transKeepBasicHtmlNodesFor: ["br", "strong", "i"],
|
|
85
90
|
},
|
|
86
91
|
compatibilityJSON: "v4",
|
|
92
|
+
initImmediate: false,
|
|
87
93
|
};
|
|
88
94
|
if (!hasBeenInitialized) {
|
|
89
95
|
void i18next
|
|
@@ -113,6 +119,7 @@ const initializeTranslationsForApp = () => {
|
|
|
113
119
|
void i18next.init(init);
|
|
114
120
|
}
|
|
115
121
|
hasBeenInitialized = true;
|
|
122
|
+
initializedNamespacesKey = nextNamespacesKey;
|
|
116
123
|
};
|
|
117
124
|
|
|
118
125
|
/**
|
|
@@ -125,8 +132,9 @@ const initializeTranslationsForApp = () => {
|
|
|
125
132
|
*/
|
|
126
133
|
const useNamespaceTranslation = (namespace, options) => {
|
|
127
134
|
const errorhandler = reactCoreHooks.useErrorHandlerOrNull();
|
|
128
|
-
const
|
|
129
|
-
const
|
|
135
|
+
const translationOptions = { ...options, i18n: options?.i18n ?? i18next };
|
|
136
|
+
const customUseTranslation = reactI18next.useTranslation(namespace, translationOptions);
|
|
137
|
+
const [t, i18NextInstance] = reactI18next.useTranslation(namespace, translationOptions);
|
|
130
138
|
const { ready } = customUseTranslation;
|
|
131
139
|
const customT = react.useCallback(function (key, arg2, arg3) {
|
|
132
140
|
if (ready && key && !i18NextInstance.exists(key, { lng: "en", ns: namespace })) {
|
package/index.esm.js
CHANGED
|
@@ -22,8 +22,9 @@ function NamespaceTrans(props) {
|
|
|
22
22
|
const LANG_STORAGE_KEY = "i18nextLng";
|
|
23
23
|
/** Holds all available TranslationResource by namespace */
|
|
24
24
|
const availableTranslations = {};
|
|
25
|
-
/** Holds all available TranslationResource by namespace */
|
|
26
25
|
let hasBeenInitialized = false;
|
|
26
|
+
let initializedNamespacesKey = "";
|
|
27
|
+
const namespacesKey = () => Object.keys(availableTranslations).toSorted().join("\0");
|
|
27
28
|
/**
|
|
28
29
|
* Use this function to register your translations before the i18next is initialized.
|
|
29
30
|
*
|
|
@@ -51,6 +52,10 @@ const registerTranslations = (resource) => {
|
|
|
51
52
|
* Pass the apps/extensions TranslationResource to this function for them to be available as well.
|
|
52
53
|
*/
|
|
53
54
|
const initializeTranslationsForApp = () => {
|
|
55
|
+
const nextNamespacesKey = namespacesKey();
|
|
56
|
+
if (hasBeenInitialized && nextNamespacesKey === initializedNamespacesKey) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
54
59
|
// Get selected language from url or fallback to english
|
|
55
60
|
const queryString = window.location.search;
|
|
56
61
|
const urlParams = new URLSearchParams(queryString);
|
|
@@ -82,6 +87,7 @@ const initializeTranslationsForApp = () => {
|
|
|
82
87
|
transKeepBasicHtmlNodesFor: ["br", "strong", "i"],
|
|
83
88
|
},
|
|
84
89
|
compatibilityJSON: "v4",
|
|
90
|
+
initImmediate: false,
|
|
85
91
|
};
|
|
86
92
|
if (!hasBeenInitialized) {
|
|
87
93
|
void i18next
|
|
@@ -111,6 +117,7 @@ const initializeTranslationsForApp = () => {
|
|
|
111
117
|
void i18next.init(init);
|
|
112
118
|
}
|
|
113
119
|
hasBeenInitialized = true;
|
|
120
|
+
initializedNamespacesKey = nextNamespacesKey;
|
|
114
121
|
};
|
|
115
122
|
|
|
116
123
|
/**
|
|
@@ -123,8 +130,9 @@ const initializeTranslationsForApp = () => {
|
|
|
123
130
|
*/
|
|
124
131
|
const useNamespaceTranslation = (namespace, options) => {
|
|
125
132
|
const errorhandler = useErrorHandlerOrNull();
|
|
126
|
-
const
|
|
127
|
-
const
|
|
133
|
+
const translationOptions = { ...options, i18n: options?.i18n ?? i18next };
|
|
134
|
+
const customUseTranslation = useTranslation(namespace, translationOptions);
|
|
135
|
+
const [t, i18NextInstance] = useTranslation(namespace, translationOptions);
|
|
128
136
|
const { ready } = customUseTranslation;
|
|
129
137
|
const customT = useCallback(function (key, arg2, arg3) {
|
|
130
138
|
if (ready && key && !i18NextInstance.exists(key, { lng: "en", ns: namespace })) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/i18n-library-translation",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.32",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"i18next": "25.1.2",
|
|
12
12
|
"i18next-browser-languagedetector": "8.1.0",
|
|
13
13
|
"i18next-resources-to-backend": "^1.2.1",
|
|
14
|
-
"@trackunit/iris-app-api": "2.4.
|
|
15
|
-
"@trackunit/react-core-hooks": "1.21.
|
|
14
|
+
"@trackunit/iris-app-api": "2.4.24",
|
|
15
|
+
"@trackunit/react-core-hooks": "1.21.32"
|
|
16
16
|
},
|
|
17
17
|
"peerDependencies": {
|
|
18
18
|
"react": "^19.0.0"
|