@nimpl/i18n 0.0.0-experimental-3abcca7 → 0.0.0-experimental-47e75fe
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
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { type I18nOptions } from "./types";
|
|
3
|
+
import { type TranslationProps } from "./lib/Translation";
|
|
3
4
|
type ClientTranslationProps = {
|
|
4
5
|
term: string;
|
|
5
|
-
components?:
|
|
6
|
-
[key: string]: React.ReactElement;
|
|
7
|
-
};
|
|
6
|
+
components?: TranslationProps["components"];
|
|
8
7
|
query?: I18nOptions["query"];
|
|
9
8
|
removeUnusedQueries?: I18nOptions["removeUnusedQueries"];
|
|
10
9
|
};
|
package/ServerTranslation.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { type I18nOptions } from "./types";
|
|
3
|
+
import { type TranslationProps } from "./lib/Translation";
|
|
3
4
|
type ServerTranslationProps = {
|
|
4
5
|
term: string;
|
|
5
|
-
components?:
|
|
6
|
-
[key: string]: React.ReactElement;
|
|
7
|
-
};
|
|
6
|
+
components?: TranslationProps["components"];
|
|
8
7
|
query?: I18nOptions["query"];
|
|
9
8
|
removeUnusedQueries?: I18nOptions["removeUnusedQueries"];
|
|
10
9
|
language?: string;
|
package/dist/lib/Translation.js
CHANGED
|
@@ -49,9 +49,9 @@ const Translation = ({ term, text, components }) => {
|
|
|
49
49
|
tags.forEach((tag, tagIndex) => {
|
|
50
50
|
const { name: tagName, type: tagType } = parseTag(tag);
|
|
51
51
|
if (tagType === "self") {
|
|
52
|
-
const
|
|
53
|
-
if (
|
|
54
|
-
parts.splice(tagIndex + 1, 1, react_1.default.
|
|
52
|
+
const Component = components[tagName];
|
|
53
|
+
if (Component) {
|
|
54
|
+
parts.splice(tagIndex + 1, 1, react_1.default.createElement(Component, { key: `c-${tagIndex}` }));
|
|
55
55
|
}
|
|
56
56
|
else {
|
|
57
57
|
console.warn(`Unknown component for term "${term}" - ${tagName}`);
|
|
@@ -65,15 +65,15 @@ const Translation = ({ term, text, components }) => {
|
|
|
65
65
|
for (let i = openedTagsLength; i > lastOpenedIndex; i--) {
|
|
66
66
|
const targetIndex = i - 1;
|
|
67
67
|
const targetTag = openedTags[targetIndex];
|
|
68
|
-
const
|
|
69
|
-
if (
|
|
68
|
+
const Component = components[targetTag.tag];
|
|
69
|
+
if (Component) {
|
|
70
70
|
const children = parts
|
|
71
71
|
.slice(targetTag.position + 1, tagIndex + 1)
|
|
72
72
|
.filter((child) => Boolean(child &&
|
|
73
73
|
typeof child === "object" &&
|
|
74
74
|
"props" in child &&
|
|
75
75
|
child.props.children));
|
|
76
|
-
parts.splice(targetTag.position + 1, tagIndex - targetTag.position, react_1.default.
|
|
76
|
+
parts.splice(targetTag.position + 1, tagIndex - targetTag.position, react_1.default.createElement(Component, { key: `${tagIndex}-${targetIndex}` }, children));
|
|
77
77
|
}
|
|
78
78
|
else {
|
|
79
79
|
console.warn(`Unknown component for term "${term}" - ${targetTag}`);
|
package/package.json
CHANGED