i18n-keyless-react 1.17.3 → 1.18.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.
@@ -5,7 +5,7 @@ export interface I18nKeylessTextProps {
5
5
  * The `children` prop must be a string.
6
6
  * It's the text to translate from your primary language.
7
7
  */
8
- children: string;
8
+ children: string | React.ReactNode;
9
9
  /**
10
10
  * The keys to replace in the text.
11
11
  * It's an object where the key is the placeholder and the value is the replacement.
@@ -7,15 +7,16 @@ const warnAboutWhitespace = (text) => {
7
7
  "This may cause inconsistencies in translations. Consider trimming the text.");
8
8
  }
9
9
  };
10
- export const I18nKeylessText = ({ children, replace, context, debug = false, forceTemporary, }) => {
10
+ export const I18nKeylessText = ({ children, replace, context, debug = false, forceTemporary }) => {
11
11
  const translations = useI18nKeyless((store) => store.translations);
12
12
  const currentLanguage = useI18nKeyless((store) => store.currentLanguage);
13
13
  const config = useI18nKeyless((store) => store.config);
14
14
  // Trim the source text immediately
15
- const sourceText = children.trim();
15
+ const rawText = Array.isArray(children) ? children.join("") : String(children ?? "");
16
+ const sourceText = rawText.trim();
16
17
  useEffect(() => {
17
- warnAboutWhitespace(children);
18
- }, [children]);
18
+ warnAboutWhitespace(rawText);
19
+ }, [rawText]);
19
20
  useEffect(() => {
20
21
  getTranslation(sourceText, { context, debug, forceTemporary });
21
22
  }, [sourceText, currentLanguage, context, debug, forceTemporary]);
@@ -44,7 +45,7 @@ export const I18nKeylessText = ({ children, replace, context, debug = false, for
44
45
  finalText,
45
46
  replace,
46
47
  context,
47
- forceTemporary,
48
+ forceTemporary
48
49
  });
49
50
  }
50
51
  return _jsx(React.Fragment, { children: finalText }, currentLanguage);
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { I18nKeylessText, I18nKeylessText as T } from "./I18nKeylessText";
2
- export { init, setCurrentLanguage, useCurrentLanguage, getTranslation, getSupportedLanguages, useI18nKeyless, } from "./store";
2
+ export { init, setCurrentLanguage, useCurrentLanguage, getTranslation, getSupportedLanguages, useI18nKeyless } from "./store";
3
3
  export { clearI18nKeylessStorage, validateLanguage } from "./utils";
4
4
  export type { I18nKeylessTextProps } from "./I18nKeylessText";
5
5
  export { type I18nConfig, type TranslationStoreState, type TranslationOptions, type TranslationStore } from "./types";
6
- export { type Lang, type PrimaryLang, type Translations, type I18nKeylessRequestBody, type I18nKeylessResponse, getAllTranslationsFromLanguage, queue, } from "i18n-keyless-core";
6
+ export { AVAILABLE_LANGS, type Lang, type PrimaryLang, type Translations, type I18nKeylessRequestBody, type I18nKeylessResponse, getAllTranslationsFromLanguage, queue } from "i18n-keyless-core";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export { I18nKeylessText, I18nKeylessText as T } from "./I18nKeylessText";
2
- export { init, setCurrentLanguage, useCurrentLanguage, getTranslation, getSupportedLanguages, useI18nKeyless, } from "./store";
2
+ export { init, setCurrentLanguage, useCurrentLanguage, getTranslation, getSupportedLanguages, useI18nKeyless } from "./store";
3
3
  export { clearI18nKeylessStorage, validateLanguage } from "./utils";
4
- export { getAllTranslationsFromLanguage, queue, } from "i18n-keyless-core";
4
+ export { AVAILABLE_LANGS, getAllTranslationsFromLanguage, queue } from "i18n-keyless-core";
package/dist/utils.d.ts CHANGED
@@ -44,4 +44,4 @@ export declare function clearI18nKeylessStorage(storage: I18nConfig["storage"]):
44
44
  * @returns The validated language or the fallback language if not supported
45
45
  * @throws Error if config is not initialized
46
46
  */
47
- export declare function validateLanguage(lang: I18nConfig["languages"]["supported"][number], config: I18nConfig): import("i18n-keyless-core").Lang | undefined;
47
+ export declare function validateLanguage(lang: I18nConfig["languages"]["supported"][number], config: I18nConfig): "fr" | "en" | "nl" | "it" | "de" | "es" | "pl" | "pt" | "ro" | "hu" | "sv" | "tr" | "ja" | "cn" | "cz" | "ru" | "ko" | "ar" | undefined;
package/package.json CHANGED
@@ -1,11 +1,18 @@
1
1
  {
2
2
  "name": "i18n-keyless-react",
3
3
  "private": false,
4
- "version": "1.17.3",
4
+ "version": "1.18.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",
8
8
  "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
9
16
  "files": [
10
17
  "dist"
11
18
  ],
@@ -17,7 +24,7 @@
17
24
  "postpublish": "rm -rf ./dist && rm *.tgz"
18
25
  },
19
26
  "dependencies": {
20
- "i18n-keyless-core": "1.17.3",
27
+ "i18n-keyless-core": "1.18.0",
21
28
  "zustand": "^5.0.3"
22
29
  },
23
30
  "peerDependencies": {