@nimpl/i18n 0.0.0-experimental-504b302 → 0.0.0-experimental-480e42f
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/README.md +2 -2
- package/{ClientTranslation.d.ts → client-translation.d.ts} +1 -1
- package/dist/{ClientTranslation.js → client-translation.js} +4 -4
- package/dist/lib/{ClientI18nContext.js → client-context.js} +2 -2
- package/dist/lib/{ClientI18nProvider.js → client-provider.js} +6 -6
- package/dist/lib/format-translate.js +2 -2
- package/dist/lib/translation-core.js +2 -2
- package/dist/lib/transmitter-core.js +2 -2
- package/dist/{useTranslation.js → use-translation.js} +4 -4
- package/package.json +5 -5
- /package/dist/lib/{injectQuery.js → inject-query.js} +0 -0
- /package/dist/lib/{parseEntities.js → parse-entities.js} +0 -0
- /package/dist/lib/{Translation.js → translation.js} +0 -0
- /package/{useTranslation.d.ts → use-translation.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -199,7 +199,7 @@ Client-side hook. Requires `Transmitter` in a parent Server Component.
|
|
|
199
199
|
```tsx
|
|
200
200
|
"use client";
|
|
201
201
|
|
|
202
|
-
import { useTranslation } from "@nimpl/i18n/
|
|
202
|
+
import { useTranslation } from "@nimpl/i18n/use-translation";
|
|
203
203
|
|
|
204
204
|
export default function Counter() {
|
|
205
205
|
const { t } = useTranslation();
|
|
@@ -221,7 +221,7 @@ Client component for complex translations with embedded JSX.
|
|
|
221
221
|
```tsx
|
|
222
222
|
"use client";
|
|
223
223
|
|
|
224
|
-
import { ClientTranslation } from "@nimpl/i18n/
|
|
224
|
+
import { ClientTranslation } from "@nimpl/i18n/client-translation";
|
|
225
225
|
|
|
226
226
|
// Translation: "Read our <link>documentation</link>"
|
|
227
227
|
export default function Info() {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { type I18nOptions } from "./types";
|
|
3
|
-
import { type TranslationProps } from "./lib/
|
|
3
|
+
import { type TranslationProps } from "./lib/translation";
|
|
4
4
|
type ClientTranslationProps = {
|
|
5
5
|
term: string;
|
|
6
6
|
components?: TranslationProps["components"];
|
|
@@ -6,11 +6,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.ClientTranslation = void 0;
|
|
8
8
|
const react_1 = __importDefault(require("react"));
|
|
9
|
-
const
|
|
10
|
-
const
|
|
9
|
+
const translation_1 = require("./lib/translation");
|
|
10
|
+
const use_translation_1 = require("./use-translation");
|
|
11
11
|
const ClientTranslation = ({ term, components, query, removeUnusedQueries, }) => {
|
|
12
|
-
const { t } = (0,
|
|
12
|
+
const { t } = (0, use_translation_1.useTranslation)();
|
|
13
13
|
const text = t(term, { query, removeUnusedQueries });
|
|
14
|
-
return react_1.default.createElement(
|
|
14
|
+
return react_1.default.createElement(translation_1.Translation, { term: term, text: text, components: components });
|
|
15
15
|
};
|
|
16
16
|
exports.ClientTranslation = ClientTranslation;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
"use client";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
4
|
+
exports.ClientContext = void 0;
|
|
5
5
|
const react_1 = require("react");
|
|
6
|
-
exports.
|
|
6
|
+
exports.ClientContext = (0, react_1.createContext)(null);
|
|
@@ -34,14 +34,14 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
};
|
|
35
35
|
})();
|
|
36
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
-
exports.
|
|
37
|
+
exports.ClientProvider = void 0;
|
|
38
38
|
const react_1 = __importStar(require("react"));
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
const prevTranslates = (0, react_1.useContext)(
|
|
39
|
+
const client_context_1 = require("./client-context");
|
|
40
|
+
const ClientProvider = ({ translates, children, language, cleanThread }) => {
|
|
41
|
+
const prevTranslates = (0, react_1.useContext)(client_context_1.ClientContext);
|
|
42
42
|
if (cleanThread) {
|
|
43
43
|
Object.assign(translates, prevTranslates?.translates);
|
|
44
44
|
}
|
|
45
|
-
return react_1.default.createElement(
|
|
45
|
+
return react_1.default.createElement(client_context_1.ClientContext.Provider, { value: { language, translates } }, children);
|
|
46
46
|
};
|
|
47
|
-
exports.
|
|
47
|
+
exports.ClientProvider = ClientProvider;
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.formatTranslate = void 0;
|
|
4
4
|
const html_entities_1 = require("html-entities");
|
|
5
|
-
const
|
|
5
|
+
const inject_query_1 = require("./inject-query");
|
|
6
6
|
const formatTranslate = ({ term, text, removeUnusedQueries, query, parseEntities }) => {
|
|
7
7
|
let newTranslate = text;
|
|
8
8
|
if (query) {
|
|
9
|
-
newTranslate = (0,
|
|
9
|
+
newTranslate = (0, inject_query_1.injectQuery)({ term, text: newTranslate, query, removeUnusedQueries });
|
|
10
10
|
}
|
|
11
11
|
if (parseEntities === undefined || parseEntities === true) {
|
|
12
12
|
newTranslate = (0, html_entities_1.decode)(newTranslate, { scope: "strict" });
|
|
@@ -5,11 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.TranslationCore = void 0;
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
|
-
const
|
|
8
|
+
const translation_1 = require("./translation");
|
|
9
9
|
const get_translation_core_1 = require("./get-translation-core");
|
|
10
10
|
const TranslationCore = ({ dictionary, namespace, term, components, query, removeUnusedQueries, language, }) => {
|
|
11
11
|
const { t } = (0, get_translation_core_1.getTranslationCore)({ language, namespace, dictionary });
|
|
12
12
|
const text = t(term, { query, removeUnusedQueries });
|
|
13
|
-
return react_1.default.createElement(
|
|
13
|
+
return react_1.default.createElement(translation_1.Translation, { term: term, text: text, components: components });
|
|
14
14
|
};
|
|
15
15
|
exports.TranslationCore = TranslationCore;
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.TransmitterCore = void 0;
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
8
|
const object_path_1 = __importDefault(require("object-path"));
|
|
9
|
-
const
|
|
9
|
+
const client_provider_1 = require("./client-provider");
|
|
10
10
|
const format_translate_1 = require("./format-translate");
|
|
11
11
|
const formatTranslates = (result, targetKey, translates, opts = {}) => {
|
|
12
12
|
if (!translates)
|
|
@@ -33,6 +33,6 @@ const TransmitterCore = async ({ dictionary, language, terms, children, cleanThr
|
|
|
33
33
|
formatTranslates(result, term, translates);
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
|
-
return (react_1.default.createElement(
|
|
36
|
+
return (react_1.default.createElement(client_provider_1.ClientProvider, { language: language, translates: result, cleanThread: cleanThread }, children));
|
|
37
37
|
};
|
|
38
38
|
exports.TransmitterCore = TransmitterCore;
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useTranslation = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const client_context_1 = require("./lib/client-context");
|
|
6
|
+
const inject_query_1 = require("./lib/inject-query");
|
|
7
7
|
const useTranslation = ({ namespace } = {}) => {
|
|
8
|
-
const context = (0, react_1.useContext)(
|
|
8
|
+
const context = (0, react_1.useContext)(client_context_1.ClientContext);
|
|
9
9
|
if (!context) {
|
|
10
10
|
throw new Error("Please, Init I18nTransmitter for client components - https://nimpl.dev/docs/i18n/usage#client-components");
|
|
11
11
|
}
|
|
@@ -22,7 +22,7 @@ const useTranslation = ({ namespace } = {}) => {
|
|
|
22
22
|
if (!translation)
|
|
23
23
|
return termKey;
|
|
24
24
|
if (opts?.query) {
|
|
25
|
-
return (0,
|
|
25
|
+
return (0, inject_query_1.injectQuery)({
|
|
26
26
|
term,
|
|
27
27
|
text: translation,
|
|
28
28
|
query: opts.query,
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nimpl/i18n",
|
|
3
|
-
"version": "0.0.0-experimental-
|
|
3
|
+
"version": "0.0.0-experimental-480e42f",
|
|
4
4
|
"description": "i18n library for working with translations in server and client components",
|
|
5
5
|
"exports": {
|
|
6
|
-
"./
|
|
7
|
-
"default": "./dist/
|
|
6
|
+
"./client-translation": {
|
|
7
|
+
"default": "./dist/client-translation.js"
|
|
8
8
|
},
|
|
9
9
|
"./initialize": {
|
|
10
10
|
"default": "./dist/initialize.js"
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"./types": {
|
|
13
13
|
"default": "./dist/types.js"
|
|
14
14
|
},
|
|
15
|
-
"./
|
|
16
|
-
"default": "./dist/
|
|
15
|
+
"./use-translation": {
|
|
16
|
+
"default": "./dist/use-translation.js"
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
"files": [
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|