@trackunit/i18n-library-translation 1.0.8 → 1.0.13
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 +5 -24
- package/index.esm.js +3 -4
- package/package.json +3 -3
- package/src/NamespaceTrans.d.ts +4 -4
package/index.cjs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
-
var
|
|
4
|
+
var react = require('react');
|
|
5
5
|
var reactI18next = require('react-i18next');
|
|
6
6
|
var irisAppApi = require('@trackunit/iris-app-api');
|
|
7
7
|
var i18next = require('i18next');
|
|
@@ -9,35 +9,16 @@ var browserLanguageDetector = require('i18next-browser-languagedetector');
|
|
|
9
9
|
var resourcesToBackend = require('i18next-resources-to-backend');
|
|
10
10
|
var reactCoreHooks = require('@trackunit/react-core-hooks');
|
|
11
11
|
|
|
12
|
-
function _interopNamespaceDefault(e) {
|
|
13
|
-
var n = Object.create(null);
|
|
14
|
-
if (e) {
|
|
15
|
-
Object.keys(e).forEach(function (k) {
|
|
16
|
-
if (k !== 'default') {
|
|
17
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
18
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: function () { return e[k]; }
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
n.default = e;
|
|
26
|
-
return Object.freeze(n);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
30
|
-
|
|
31
12
|
/**
|
|
32
13
|
* Minimal wrapper of i18ns Trans component - only exposing what is currently needed - while ensuring type safety on translation keys.
|
|
33
14
|
*
|
|
34
15
|
* @param { NamespaceTransProps } props the props for this namespace
|
|
35
|
-
* @returns {
|
|
16
|
+
* @returns { ReactElement } The translated text - with safe interpolation of simple html (<strong><em><b><i> etc.)
|
|
36
17
|
*/
|
|
37
18
|
function NamespaceTrans(props) {
|
|
38
19
|
// The as string | string[] is in order for TS to not choke on the size of the intersection
|
|
39
20
|
// "Expression produces a union type that is too complex to represent.ts(2590)"
|
|
40
|
-
return (jsxRuntime.jsx(reactI18next.Trans, { components: props.components, i18nKey: props.i18nKey, ns: props.namespace, values: props.values, children:
|
|
21
|
+
return (jsxRuntime.jsx(reactI18next.Trans, { components: props.components, i18nKey: props.i18nKey, ns: props.namespace, values: props.values, children: react.Children }));
|
|
41
22
|
}
|
|
42
23
|
|
|
43
24
|
const LANG_STORAGE_KEY = "i18nextLng";
|
|
@@ -142,7 +123,7 @@ const useNamespaceTranslation = (namespace, options) => {
|
|
|
142
123
|
const { captureException } = reactCoreHooks.useErrorHandler();
|
|
143
124
|
const customUseTranslation = reactI18next.useTranslation(namespace, options);
|
|
144
125
|
const [t, i18NextInstance] = reactI18next.useTranslation(namespace, options);
|
|
145
|
-
const customT =
|
|
126
|
+
const customT = react.useCallback(function (key, arg2, arg3) {
|
|
146
127
|
if (key && !i18NextInstance.exists(key, { lng: "en", ns: namespace })) {
|
|
147
128
|
captureException(new Error(JSON.stringify({
|
|
148
129
|
info: "A Translation key could not be found!",
|
|
@@ -159,7 +140,7 @@ const useNamespaceTranslation = (namespace, options) => {
|
|
|
159
140
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
160
141
|
[i18NextInstance, namespace]);
|
|
161
142
|
// Replace t function with customT
|
|
162
|
-
const updatedUseTranslation =
|
|
143
|
+
const updatedUseTranslation = react.useMemo(() => {
|
|
163
144
|
customUseTranslation[0] = customT;
|
|
164
145
|
customUseTranslation.t = customT;
|
|
165
146
|
return customUseTranslation;
|
package/index.esm.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import
|
|
3
|
-
import { useCallback, useMemo } from 'react';
|
|
2
|
+
import { Children, useCallback, useMemo } from 'react';
|
|
4
3
|
import { Trans, initReactI18next, useTranslation } from 'react-i18next';
|
|
5
4
|
import { languageKeys } from '@trackunit/iris-app-api';
|
|
6
5
|
import i18next from 'i18next';
|
|
@@ -12,12 +11,12 @@ import { useErrorHandler } from '@trackunit/react-core-hooks';
|
|
|
12
11
|
* Minimal wrapper of i18ns Trans component - only exposing what is currently needed - while ensuring type safety on translation keys.
|
|
13
12
|
*
|
|
14
13
|
* @param { NamespaceTransProps } props the props for this namespace
|
|
15
|
-
* @returns {
|
|
14
|
+
* @returns { ReactElement } The translated text - with safe interpolation of simple html (<strong><em><b><i> etc.)
|
|
16
15
|
*/
|
|
17
16
|
function NamespaceTrans(props) {
|
|
18
17
|
// The as string | string[] is in order for TS to not choke on the size of the intersection
|
|
19
18
|
// "Expression produces a union type that is too complex to represent.ts(2590)"
|
|
20
|
-
return (jsx(Trans, { components: props.components, i18nKey: props.i18nKey, ns: props.namespace, values: props.values, children:
|
|
19
|
+
return (jsx(Trans, { components: props.components, i18nKey: props.i18nKey, ns: props.namespace, values: props.values, children: Children }));
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
const LANG_STORAGE_KEY = "i18nextLng";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/i18n-library-translation",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"i18next": "21.10.0",
|
|
14
14
|
"i18next-browser-languagedetector": "6.1.8",
|
|
15
15
|
"i18next-resources-to-backend": "^1.1.4",
|
|
16
|
-
"@trackunit/iris-app-api": "
|
|
17
|
-
"@trackunit/react-core-hooks": "
|
|
16
|
+
"@trackunit/iris-app-api": "1.0.8",
|
|
17
|
+
"@trackunit/react-core-hooks": "1.0.9"
|
|
18
18
|
},
|
|
19
19
|
"module": "./index.esm.js",
|
|
20
20
|
"main": "./index.cjs.js",
|
package/src/NamespaceTrans.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ReactElement } from "react";
|
|
2
2
|
export interface NamespaceTransProps<TranslationKeys extends string> {
|
|
3
3
|
namespace?: string;
|
|
4
4
|
i18nKey: TranslationKeys | TranslationKeys[];
|
|
5
5
|
values: object;
|
|
6
6
|
components?: {
|
|
7
|
-
readonly [tagName: string]:
|
|
7
|
+
readonly [tagName: string]: ReactElement;
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
11
|
* Minimal wrapper of i18ns Trans component - only exposing what is currently needed - while ensuring type safety on translation keys.
|
|
12
12
|
*
|
|
13
13
|
* @param { NamespaceTransProps } props the props for this namespace
|
|
14
|
-
* @returns {
|
|
14
|
+
* @returns { ReactElement } The translated text - with safe interpolation of simple html (<strong><em><b><i> etc.)
|
|
15
15
|
*/
|
|
16
|
-
export declare function NamespaceTrans<TranslationKeys extends string>(props: NamespaceTransProps<TranslationKeys>):
|
|
16
|
+
export declare function NamespaceTrans<TranslationKeys extends string>(props: NamespaceTransProps<TranslationKeys>): ReactElement;
|