@nimpl/i18n 2.0.1-canary.0 → 3.0.0
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/ClientTranslation.d.ts +1 -1
- package/README.md +1 -1
- package/ServerTranslation.d.ts +1 -1
- package/dist/lib/Translation.js +2 -1
- package/dist/lib/loadI18nData.js +1 -8
- package/dist/useTranslation.js +1 -1
- package/package.json +6 -6
package/ClientTranslation.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { type I18nOptions } from "./types";
|
|
|
3
3
|
type ClientTranslationProps = {
|
|
4
4
|
term: string;
|
|
5
5
|
components?: {
|
|
6
|
-
[key: string]:
|
|
6
|
+
[key: string]: React.ReactElement;
|
|
7
7
|
};
|
|
8
8
|
query?: I18nOptions["query"];
|
|
9
9
|
removeUnusedQueries?: I18nOptions["removeUnusedQueries"];
|
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
i18n library designed primarily with server components in mind and maximum optimization (due to the transfer of logic to the assembly stage and/or server side).
|
|
6
6
|
|
|
7
|
-
Visit https://nimpl.
|
|
7
|
+
Visit https://nimpl.dev/docs/i18n to view the full documentation.
|
|
8
8
|
|
|
9
9
|
## Why one more library?
|
|
10
10
|
|
package/ServerTranslation.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { type I18nOptions } from "./types";
|
|
|
3
3
|
type ServerTranslationProps = {
|
|
4
4
|
term: string;
|
|
5
5
|
components?: {
|
|
6
|
-
[key: string]:
|
|
6
|
+
[key: string]: React.ReactElement;
|
|
7
7
|
};
|
|
8
8
|
query?: I18nOptions["query"];
|
|
9
9
|
removeUnusedQueries?: I18nOptions["removeUnusedQueries"];
|
package/dist/lib/Translation.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
3
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
5
|
};
|
|
@@ -35,7 +36,7 @@ const Translation = ({ term, text, components }) => {
|
|
|
35
36
|
if (component) {
|
|
36
37
|
const children = parts
|
|
37
38
|
.slice(targetTag.position + 1, tagIndex + 1)
|
|
38
|
-
.filter((c) => Boolean(c.props.children));
|
|
39
|
+
.filter((c) => Boolean(c && typeof c === "object" && "props" in c && c.props.children));
|
|
39
40
|
parts.splice(targetTag.position + 1, // parts на 1 больше
|
|
40
41
|
tagIndex - targetTag.position, react_1.default.cloneElement(component, { key: `${tagIndex}-${targetIndex}` }, children.length ? children : component.props.children));
|
|
41
42
|
}
|
package/dist/lib/loadI18nData.js
CHANGED
|
@@ -8,14 +8,7 @@ const get_pathname_1 = require("@nimpl/getters/get-pathname");
|
|
|
8
8
|
const get_params_1 = require("@nimpl/getters/get-params");
|
|
9
9
|
const loadI18nData = async () => {
|
|
10
10
|
const config = await (0, getConfig_1.default)();
|
|
11
|
-
const language = await config.getLanguage({
|
|
12
|
-
get pathname() {
|
|
13
|
-
return (0, get_pathname_1.getPathname)();
|
|
14
|
-
},
|
|
15
|
-
get params() {
|
|
16
|
-
return (0, get_params_1.getParams)();
|
|
17
|
-
},
|
|
18
|
-
});
|
|
11
|
+
const language = await config.getLanguage({ pathname: (0, get_pathname_1.getPathname)(), params: (0, get_params_1.getParams)() });
|
|
19
12
|
if (!language || !config.languages.includes(language)) {
|
|
20
13
|
throw new Error(`Can\' load data for language "${language}", valid languages are: ${config.languages.join(", ")}`);
|
|
21
14
|
}
|
package/dist/useTranslation.js
CHANGED
|
@@ -9,7 +9,7 @@ const injectQuery_1 = __importDefault(require("./lib/injectQuery"));
|
|
|
9
9
|
const useTranslation = ({ namespace } = {}) => {
|
|
10
10
|
const context = (0, react_1.useContext)(ClientI18nContext_1.ClientI18nContext);
|
|
11
11
|
if (!context) {
|
|
12
|
-
throw new Error("Please, Init I18nTransmitter for client components - https://nimpl.
|
|
12
|
+
throw new Error("Please, Init I18nTransmitter for client components - https://nimpl.dev/docs/i18n/usage#client-components");
|
|
13
13
|
}
|
|
14
14
|
const { language, translates } = context;
|
|
15
15
|
const t = (term, opts) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nimpl/i18n",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "i18n library for working with translations in server and client components",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./ClientTranslation": {
|
|
@@ -59,17 +59,17 @@
|
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@types/node": "16.11.12",
|
|
61
61
|
"@types/object-path": "0.11.4",
|
|
62
|
-
"@types/react": "
|
|
62
|
+
"@types/react": "19.1.1",
|
|
63
63
|
"@types/webpack": "5.28.5",
|
|
64
|
-
"react": "
|
|
64
|
+
"react": "19.1.0",
|
|
65
65
|
"typescript": "5.3.2"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
|
-
"react": ">=
|
|
68
|
+
"react": ">= 19.1.0"
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"@nimpl/getters": "1.
|
|
71
|
+
"@nimpl/getters": "2.1.1",
|
|
72
72
|
"html-entities": "2.4.0",
|
|
73
73
|
"object-path": "0.11.8"
|
|
74
74
|
}
|
|
75
|
-
}
|
|
75
|
+
}
|