@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.
@@ -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
  };
@@ -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;
@@ -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 component = components[tagName];
53
- if (component) {
54
- parts.splice(tagIndex + 1, 1, react_1.default.cloneElement(component, { key: `c-${tagIndex}` }, component.props.children));
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 component = components[targetTag.tag];
69
- if (component) {
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.cloneElement(component, { key: `${tagIndex}-${targetIndex}` }, children.length ? children : component.props.children));
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nimpl/i18n",
3
- "version": "0.0.0-experimental-3abcca7",
3
+ "version": "0.0.0-experimental-47e75fe",
4
4
  "description": "i18n library for working with translations in server and client components",
5
5
  "exports": {
6
6
  "./ClientTranslation": {