i18n-keyless-react 1.7.5 → 1.7.7
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/dist/I18nKeylessText.d.ts +14 -14
- package/dist/package.json +1 -1
- package/dist/store.js +6 -1
- package/package.json +1 -1
|
@@ -2,30 +2,30 @@ import React from "react";
|
|
|
2
2
|
import { TranslationOptions } from "i18n-keyless-core";
|
|
3
3
|
export interface I18nKeylessTextProps {
|
|
4
4
|
/**
|
|
5
|
-
* children must be a string
|
|
6
|
-
*
|
|
5
|
+
* The `children` prop must be a string.
|
|
6
|
+
* It's the text to translate from your primary language.
|
|
7
7
|
*/
|
|
8
8
|
children: string;
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* RegEx is `key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"))` so you can use use your own syntax
|
|
10
|
+
* The keys to replace in the text.
|
|
11
|
+
* It's an object where the key is the placeholder and the value is the replacement.
|
|
12
|
+
* Example: { "{{name}}": "John" } will replace all the {{name}} in the text with "John".
|
|
13
|
+
* RegEx is `key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"))` so you can use use your own syntax.
|
|
14
14
|
*/
|
|
15
15
|
replace?: Record<string, string>;
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
17
|
+
* The context of the translation.
|
|
18
|
+
* It's useful for ambiguous translations, like "8 heures" in French could be "8 AM" or "8 hours".
|
|
19
19
|
*/
|
|
20
|
-
context?:
|
|
20
|
+
context?: TranslationOptions["context"];
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* If true, some helpful logs will be displayed in the console.
|
|
23
23
|
*/
|
|
24
|
-
debug?:
|
|
24
|
+
debug?: TranslationOptions["debug"];
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
26
|
+
* If the proposed translation from AI is not satisfactory,
|
|
27
|
+
* you can use this field to setup your own translation.
|
|
28
|
+
* You can leave it there forever, or remove it once your translation is saved.
|
|
29
29
|
*/
|
|
30
30
|
forceTemporary?: TranslationOptions["forceTemporary"];
|
|
31
31
|
}
|
package/dist/package.json
CHANGED
package/dist/store.js
CHANGED
|
@@ -106,6 +106,10 @@ export const useI18nKeyless = create((set, get) => ({
|
|
|
106
106
|
if (currentLanguage === config.languages.primary) {
|
|
107
107
|
return text;
|
|
108
108
|
}
|
|
109
|
+
const forceTemporary = options?.forceTemporary;
|
|
110
|
+
if (forceTemporary?.[currentLanguage]) {
|
|
111
|
+
get().translateKey(forceTemporary[currentLanguage], options);
|
|
112
|
+
}
|
|
109
113
|
const context = options?.context;
|
|
110
114
|
const translation = context ? get().translations[`${text}__${context}`] : get().translations[text];
|
|
111
115
|
if (!translation) {
|
|
@@ -135,8 +139,9 @@ export const useI18nKeyless = create((set, get) => ({
|
|
|
135
139
|
if (debug) {
|
|
136
140
|
console.log("translateKey", key, context, debug);
|
|
137
141
|
}
|
|
142
|
+
const forceTemporaryLang = options?.forceTemporary?.[get().currentLanguage];
|
|
138
143
|
const translation = context ? get().translations[`${key}__${context}`] : get().translations[key];
|
|
139
|
-
if (translation) {
|
|
144
|
+
if (translation && !forceTemporaryLang) {
|
|
140
145
|
if (debug) {
|
|
141
146
|
console.log("translation exists", `${key}__${context}`);
|
|
142
147
|
}
|