inline-i18n-multi-react 0.3.0 → 0.5.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.
- package/dist/index.d.mts +66 -3
- package/dist/index.d.ts +66 -3
- package/dist/index.js +94 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +72 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { ReactNode } from 'react';
|
|
2
|
+
import React, { ReactNode } from 'react';
|
|
3
3
|
import { Locale, TranslationVars, Translations } from 'inline-i18n-multi';
|
|
4
|
-
export { Dictionaries, Dictionary, Locale, PluralRules, TranslationVars, Translations, clearDictionaries, en_de, en_es, en_fr, en_ja, en_zh, getDictionary, getLoadedLocales, getLocale, hasTranslation, it, it_de, it_es, it_fr, it_ja, it_zh, ja_es, ja_zh, loadDictionaries, loadDictionary, setLocale, t, zh_es } from 'inline-i18n-multi';
|
|
4
|
+
export { Dictionaries, Dictionary, Locale, PluralRules, RichTextSegment, TranslationVars, Translations, clearDictionaries, en_de, en_es, en_fr, en_ja, en_zh, getDictionary, getLoadedLocales, getLocale, hasTranslation, isLoaded, it, it_de, it_es, it_fr, it_ja, it_zh, ja_es, ja_zh, loadAsync, loadDictionaries, loadDictionary, parseRichText, setLocale, t, zh_es } from 'inline-i18n-multi';
|
|
5
5
|
|
|
6
6
|
interface LocaleProviderProps {
|
|
7
7
|
/**
|
|
@@ -33,6 +33,22 @@ declare function useLocale(): [Locale, (locale: Locale) => void];
|
|
|
33
33
|
* t('items.count', { count: 5 })
|
|
34
34
|
*/
|
|
35
35
|
declare function useT(): (key: string, vars?: TranslationVars) => string;
|
|
36
|
+
/**
|
|
37
|
+
* Hook for lazy loading dictionaries
|
|
38
|
+
* Automatically loads dictionaries when locale or namespace changes
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* function Dashboard() {
|
|
42
|
+
* const { isLoading, error } = useLoadDictionaries('ko', 'dashboard')
|
|
43
|
+
* if (isLoading) return <Spinner />
|
|
44
|
+
* if (error) return <Error message={error.message} />
|
|
45
|
+
* return <Content />
|
|
46
|
+
* }
|
|
47
|
+
*/
|
|
48
|
+
declare function useLoadDictionaries(locale: Locale, namespace?: string): {
|
|
49
|
+
isLoading: boolean;
|
|
50
|
+
error: Error | null;
|
|
51
|
+
};
|
|
36
52
|
|
|
37
53
|
interface TPropsShorthand {
|
|
38
54
|
/**
|
|
@@ -62,4 +78,51 @@ type TProps = (TPropsShorthand | TPropsObject) & TranslationVars;
|
|
|
62
78
|
*/
|
|
63
79
|
declare function T(props: TProps): react_jsx_runtime.JSX.Element;
|
|
64
80
|
|
|
65
|
-
|
|
81
|
+
type ComponentRenderer = (text: string) => ReactNode;
|
|
82
|
+
interface RichTextProps {
|
|
83
|
+
/**
|
|
84
|
+
* Translation map with locale keys
|
|
85
|
+
* Tags like <link>text</link> will be matched to component renderers
|
|
86
|
+
*/
|
|
87
|
+
translations: Translations;
|
|
88
|
+
/**
|
|
89
|
+
* Component renderers for each tag name
|
|
90
|
+
* @example { link: (text) => <a href="/terms">{text}</a> }
|
|
91
|
+
*/
|
|
92
|
+
components: Record<string, ComponentRenderer>;
|
|
93
|
+
/**
|
|
94
|
+
* Variables for interpolation (applied before rich text parsing)
|
|
95
|
+
*/
|
|
96
|
+
vars?: TranslationVars;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Rich text translation component
|
|
100
|
+
* Supports embedding React components within translations
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* <RichText
|
|
104
|
+
* translations={{
|
|
105
|
+
* en: 'Read <link>terms</link> and <bold>agree</bold>',
|
|
106
|
+
* ko: '<link>약관</link>을 읽고 <bold>동의</bold>해주세요'
|
|
107
|
+
* }}
|
|
108
|
+
* components={{
|
|
109
|
+
* link: (text) => <a href="/terms">{text}</a>,
|
|
110
|
+
* bold: (text) => <strong>{text}</strong>
|
|
111
|
+
* }}
|
|
112
|
+
* />
|
|
113
|
+
*/
|
|
114
|
+
declare function RichText({ translations, components, vars }: RichTextProps): React.JSX.Element;
|
|
115
|
+
/**
|
|
116
|
+
* Hook for rich text translations
|
|
117
|
+
* Returns a function that resolves translations with component interpolation
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* const richT = useRichText({
|
|
121
|
+
* link: (text) => <a href="/terms">{text}</a>,
|
|
122
|
+
* bold: (text) => <strong>{text}</strong>,
|
|
123
|
+
* })
|
|
124
|
+
* return richT({ en: 'Click <link>here</link>', ko: '<link>여기</link> 클릭' })
|
|
125
|
+
*/
|
|
126
|
+
declare function useRichText(components: Record<string, ComponentRenderer>): (translations: Translations, vars?: TranslationVars) => ReactNode;
|
|
127
|
+
|
|
128
|
+
export { LocaleProvider, RichText, T, useLoadDictionaries, useLocale, useRichText, useT };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { ReactNode } from 'react';
|
|
2
|
+
import React, { ReactNode } from 'react';
|
|
3
3
|
import { Locale, TranslationVars, Translations } from 'inline-i18n-multi';
|
|
4
|
-
export { Dictionaries, Dictionary, Locale, PluralRules, TranslationVars, Translations, clearDictionaries, en_de, en_es, en_fr, en_ja, en_zh, getDictionary, getLoadedLocales, getLocale, hasTranslation, it, it_de, it_es, it_fr, it_ja, it_zh, ja_es, ja_zh, loadDictionaries, loadDictionary, setLocale, t, zh_es } from 'inline-i18n-multi';
|
|
4
|
+
export { Dictionaries, Dictionary, Locale, PluralRules, RichTextSegment, TranslationVars, Translations, clearDictionaries, en_de, en_es, en_fr, en_ja, en_zh, getDictionary, getLoadedLocales, getLocale, hasTranslation, isLoaded, it, it_de, it_es, it_fr, it_ja, it_zh, ja_es, ja_zh, loadAsync, loadDictionaries, loadDictionary, parseRichText, setLocale, t, zh_es } from 'inline-i18n-multi';
|
|
5
5
|
|
|
6
6
|
interface LocaleProviderProps {
|
|
7
7
|
/**
|
|
@@ -33,6 +33,22 @@ declare function useLocale(): [Locale, (locale: Locale) => void];
|
|
|
33
33
|
* t('items.count', { count: 5 })
|
|
34
34
|
*/
|
|
35
35
|
declare function useT(): (key: string, vars?: TranslationVars) => string;
|
|
36
|
+
/**
|
|
37
|
+
* Hook for lazy loading dictionaries
|
|
38
|
+
* Automatically loads dictionaries when locale or namespace changes
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* function Dashboard() {
|
|
42
|
+
* const { isLoading, error } = useLoadDictionaries('ko', 'dashboard')
|
|
43
|
+
* if (isLoading) return <Spinner />
|
|
44
|
+
* if (error) return <Error message={error.message} />
|
|
45
|
+
* return <Content />
|
|
46
|
+
* }
|
|
47
|
+
*/
|
|
48
|
+
declare function useLoadDictionaries(locale: Locale, namespace?: string): {
|
|
49
|
+
isLoading: boolean;
|
|
50
|
+
error: Error | null;
|
|
51
|
+
};
|
|
36
52
|
|
|
37
53
|
interface TPropsShorthand {
|
|
38
54
|
/**
|
|
@@ -62,4 +78,51 @@ type TProps = (TPropsShorthand | TPropsObject) & TranslationVars;
|
|
|
62
78
|
*/
|
|
63
79
|
declare function T(props: TProps): react_jsx_runtime.JSX.Element;
|
|
64
80
|
|
|
65
|
-
|
|
81
|
+
type ComponentRenderer = (text: string) => ReactNode;
|
|
82
|
+
interface RichTextProps {
|
|
83
|
+
/**
|
|
84
|
+
* Translation map with locale keys
|
|
85
|
+
* Tags like <link>text</link> will be matched to component renderers
|
|
86
|
+
*/
|
|
87
|
+
translations: Translations;
|
|
88
|
+
/**
|
|
89
|
+
* Component renderers for each tag name
|
|
90
|
+
* @example { link: (text) => <a href="/terms">{text}</a> }
|
|
91
|
+
*/
|
|
92
|
+
components: Record<string, ComponentRenderer>;
|
|
93
|
+
/**
|
|
94
|
+
* Variables for interpolation (applied before rich text parsing)
|
|
95
|
+
*/
|
|
96
|
+
vars?: TranslationVars;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Rich text translation component
|
|
100
|
+
* Supports embedding React components within translations
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* <RichText
|
|
104
|
+
* translations={{
|
|
105
|
+
* en: 'Read <link>terms</link> and <bold>agree</bold>',
|
|
106
|
+
* ko: '<link>약관</link>을 읽고 <bold>동의</bold>해주세요'
|
|
107
|
+
* }}
|
|
108
|
+
* components={{
|
|
109
|
+
* link: (text) => <a href="/terms">{text}</a>,
|
|
110
|
+
* bold: (text) => <strong>{text}</strong>
|
|
111
|
+
* }}
|
|
112
|
+
* />
|
|
113
|
+
*/
|
|
114
|
+
declare function RichText({ translations, components, vars }: RichTextProps): React.JSX.Element;
|
|
115
|
+
/**
|
|
116
|
+
* Hook for rich text translations
|
|
117
|
+
* Returns a function that resolves translations with component interpolation
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* const richT = useRichText({
|
|
121
|
+
* link: (text) => <a href="/terms">{text}</a>,
|
|
122
|
+
* bold: (text) => <strong>{text}</strong>,
|
|
123
|
+
* })
|
|
124
|
+
* return richT({ en: 'Click <link>here</link>', ko: '<link>여기</link> 클릭' })
|
|
125
|
+
*/
|
|
126
|
+
declare function useRichText(components: Record<string, ComponentRenderer>): (translations: Translations, vars?: TranslationVars) => ReactNode;
|
|
127
|
+
|
|
128
|
+
export { LocaleProvider, RichText, T, useLoadDictionaries, useLocale, useRichText, useT };
|
package/dist/index.js
CHANGED
|
@@ -22,32 +22,38 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
22
22
|
var index_exports = {};
|
|
23
23
|
__export(index_exports, {
|
|
24
24
|
LocaleProvider: () => LocaleProvider,
|
|
25
|
+
RichText: () => RichText,
|
|
25
26
|
T: () => T,
|
|
26
|
-
clearDictionaries: () =>
|
|
27
|
-
en_de: () =>
|
|
28
|
-
en_es: () =>
|
|
29
|
-
en_fr: () =>
|
|
30
|
-
en_ja: () =>
|
|
31
|
-
en_zh: () =>
|
|
32
|
-
getDictionary: () =>
|
|
33
|
-
getLoadedLocales: () =>
|
|
34
|
-
getLocale: () =>
|
|
35
|
-
hasTranslation: () =>
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
27
|
+
clearDictionaries: () => import_inline_i18n_multi5.clearDictionaries,
|
|
28
|
+
en_de: () => import_inline_i18n_multi5.en_de,
|
|
29
|
+
en_es: () => import_inline_i18n_multi5.en_es,
|
|
30
|
+
en_fr: () => import_inline_i18n_multi5.en_fr,
|
|
31
|
+
en_ja: () => import_inline_i18n_multi5.en_ja,
|
|
32
|
+
en_zh: () => import_inline_i18n_multi5.en_zh,
|
|
33
|
+
getDictionary: () => import_inline_i18n_multi5.getDictionary,
|
|
34
|
+
getLoadedLocales: () => import_inline_i18n_multi5.getLoadedLocales,
|
|
35
|
+
getLocale: () => import_inline_i18n_multi5.getLocale,
|
|
36
|
+
hasTranslation: () => import_inline_i18n_multi5.hasTranslation,
|
|
37
|
+
isLoaded: () => import_inline_i18n_multi5.isLoaded,
|
|
38
|
+
it: () => import_inline_i18n_multi5.it,
|
|
39
|
+
it_de: () => import_inline_i18n_multi5.it_de,
|
|
40
|
+
it_es: () => import_inline_i18n_multi5.it_es,
|
|
41
|
+
it_fr: () => import_inline_i18n_multi5.it_fr,
|
|
42
|
+
it_ja: () => import_inline_i18n_multi5.it_ja,
|
|
43
|
+
it_zh: () => import_inline_i18n_multi5.it_zh,
|
|
44
|
+
ja_es: () => import_inline_i18n_multi5.ja_es,
|
|
45
|
+
ja_zh: () => import_inline_i18n_multi5.ja_zh,
|
|
46
|
+
loadAsync: () => import_inline_i18n_multi5.loadAsync,
|
|
47
|
+
loadDictionaries: () => import_inline_i18n_multi5.loadDictionaries,
|
|
48
|
+
loadDictionary: () => import_inline_i18n_multi5.loadDictionary,
|
|
49
|
+
parseRichText: () => import_inline_i18n_multi5.parseRichText,
|
|
50
|
+
setLocale: () => import_inline_i18n_multi5.setLocale,
|
|
51
|
+
t: () => import_inline_i18n_multi5.t,
|
|
52
|
+
useLoadDictionaries: () => useLoadDictionaries,
|
|
48
53
|
useLocale: () => useLocale,
|
|
54
|
+
useRichText: () => useRichText,
|
|
49
55
|
useT: () => useT,
|
|
50
|
-
zh_es: () =>
|
|
56
|
+
zh_es: () => import_inline_i18n_multi5.zh_es
|
|
51
57
|
});
|
|
52
58
|
module.exports = __toCommonJS(index_exports);
|
|
53
59
|
|
|
@@ -112,6 +118,24 @@ function useT() {
|
|
|
112
118
|
[locale]
|
|
113
119
|
);
|
|
114
120
|
}
|
|
121
|
+
function useLoadDictionaries(locale, namespace) {
|
|
122
|
+
const [isLoading, setIsLoading] = (0, import_react3.useState)(() => !(0, import_inline_i18n_multi2.isLoaded)(locale, namespace));
|
|
123
|
+
const [error, setError] = (0, import_react3.useState)(null);
|
|
124
|
+
(0, import_react3.useEffect)(() => {
|
|
125
|
+
if ((0, import_inline_i18n_multi2.isLoaded)(locale, namespace)) {
|
|
126
|
+
setIsLoading(false);
|
|
127
|
+
setError(null);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
setIsLoading(true);
|
|
131
|
+
setError(null);
|
|
132
|
+
(0, import_inline_i18n_multi2.loadAsync)(locale, namespace).then(() => setIsLoading(false)).catch((err) => {
|
|
133
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
134
|
+
setIsLoading(false);
|
|
135
|
+
});
|
|
136
|
+
}, [locale, namespace]);
|
|
137
|
+
return { isLoading, error };
|
|
138
|
+
}
|
|
115
139
|
|
|
116
140
|
// src/component.tsx
|
|
117
141
|
var import_inline_i18n_multi3 = require("inline-i18n-multi");
|
|
@@ -127,11 +151,52 @@ function T(props) {
|
|
|
127
151
|
throw new Error('T component requires either "translations" or both "ko" and "en" props');
|
|
128
152
|
}
|
|
129
153
|
|
|
130
|
-
// src/
|
|
154
|
+
// src/richtext.tsx
|
|
155
|
+
var import_react4 = require("react");
|
|
131
156
|
var import_inline_i18n_multi4 = require("inline-i18n-multi");
|
|
157
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
158
|
+
function RichText({ translations, components, vars }) {
|
|
159
|
+
const componentNames = (0, import_react4.useMemo)(() => Object.keys(components), [components]);
|
|
160
|
+
const resolved = (0, import_inline_i18n_multi4.it)(translations, vars);
|
|
161
|
+
const segments = (0, import_inline_i18n_multi4.parseRichText)(resolved, componentNames);
|
|
162
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, { children: segments.map((segment, index) => {
|
|
163
|
+
if (segment.type === "text") {
|
|
164
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react4.Fragment, { children: segment.content }, index);
|
|
165
|
+
}
|
|
166
|
+
const renderer = components[segment.componentName];
|
|
167
|
+
if (!renderer) {
|
|
168
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react4.Fragment, { children: segment.content }, index);
|
|
169
|
+
}
|
|
170
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react4.Fragment, { children: renderer(segment.content) }, index);
|
|
171
|
+
}) });
|
|
172
|
+
}
|
|
173
|
+
function useRichText(components) {
|
|
174
|
+
const componentNames = (0, import_react4.useMemo)(() => Object.keys(components), [components]);
|
|
175
|
+
return (0, import_react4.useCallback)(
|
|
176
|
+
(translations, vars) => {
|
|
177
|
+
const resolved = (0, import_inline_i18n_multi4.it)(translations, vars);
|
|
178
|
+
const segments = (0, import_inline_i18n_multi4.parseRichText)(resolved, componentNames);
|
|
179
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, { children: segments.map((segment, index) => {
|
|
180
|
+
if (segment.type === "text") {
|
|
181
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react4.Fragment, { children: segment.content }, index);
|
|
182
|
+
}
|
|
183
|
+
const renderer = components[segment.componentName];
|
|
184
|
+
if (!renderer) {
|
|
185
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react4.Fragment, { children: segment.content }, index);
|
|
186
|
+
}
|
|
187
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react4.Fragment, { children: renderer(segment.content) }, index);
|
|
188
|
+
}) });
|
|
189
|
+
},
|
|
190
|
+
[components, componentNames]
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// src/index.ts
|
|
195
|
+
var import_inline_i18n_multi5 = require("inline-i18n-multi");
|
|
132
196
|
// Annotate the CommonJS export names for ESM import in node:
|
|
133
197
|
0 && (module.exports = {
|
|
134
198
|
LocaleProvider,
|
|
199
|
+
RichText,
|
|
135
200
|
T,
|
|
136
201
|
clearDictionaries,
|
|
137
202
|
en_de,
|
|
@@ -143,6 +208,7 @@ var import_inline_i18n_multi4 = require("inline-i18n-multi");
|
|
|
143
208
|
getLoadedLocales,
|
|
144
209
|
getLocale,
|
|
145
210
|
hasTranslation,
|
|
211
|
+
isLoaded,
|
|
146
212
|
it,
|
|
147
213
|
it_de,
|
|
148
214
|
it_es,
|
|
@@ -151,11 +217,15 @@ var import_inline_i18n_multi4 = require("inline-i18n-multi");
|
|
|
151
217
|
it_zh,
|
|
152
218
|
ja_es,
|
|
153
219
|
ja_zh,
|
|
220
|
+
loadAsync,
|
|
154
221
|
loadDictionaries,
|
|
155
222
|
loadDictionary,
|
|
223
|
+
parseRichText,
|
|
156
224
|
setLocale,
|
|
157
225
|
t,
|
|
226
|
+
useLoadDictionaries,
|
|
158
227
|
useLocale,
|
|
228
|
+
useRichText,
|
|
159
229
|
useT,
|
|
160
230
|
zh_es
|
|
161
231
|
});
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/provider.tsx","../src/context.tsx","../src/hooks.ts","../src/component.tsx"],"sourcesContent":["export { LocaleProvider } from './provider'\nexport { useLocale, useT } from './hooks'\nexport { T } from './component'\n\n// re-export from core for convenience\nexport {\n // inline translations\n it,\n it_ja,\n it_zh,\n it_es,\n it_fr,\n it_de,\n en_ja,\n en_zh,\n en_es,\n en_fr,\n en_de,\n ja_zh,\n ja_es,\n zh_es,\n getLocale,\n setLocale,\n // key-based translations (i18n compatible)\n t,\n loadDictionaries,\n loadDictionary,\n clearDictionaries,\n hasTranslation,\n getLoadedLocales,\n getDictionary,\n // types\n type Locale,\n type Translations,\n type TranslationVars,\n type Dictionary,\n type Dictionaries,\n type PluralRules,\n} from 'inline-i18n-multi'\n","import { useState, useCallback, useMemo, useEffect, type ReactNode } from 'react'\nimport { setLocale as setCoreLocale, type Locale } from 'inline-i18n-multi'\nimport { LocaleContext } from './context'\n\ninterface LocaleProviderProps {\n /**\n * Initial locale value\n */\n locale: Locale\n /**\n * Cookie name for persisting locale (default: NEXT_LOCALE)\n * Set to false to disable cookie sync\n */\n cookieName?: string | false\n /**\n * Callback when locale changes\n */\n onLocaleChange?: (locale: Locale) => void\n children: ReactNode\n}\n\nfunction setCookie(name: string, value: string, days = 365): void {\n if (typeof document === 'undefined') return\n const expires = new Date(Date.now() + days * 864e5).toUTCString()\n document.cookie = `${name}=${value}; expires=${expires}; path=/; SameSite=Lax`\n}\n\nexport function LocaleProvider({\n locale: initialLocale,\n cookieName = 'NEXT_LOCALE',\n onLocaleChange,\n children,\n}: LocaleProviderProps) {\n const [locale, setLocaleState] = useState<Locale>(initialLocale)\n\n // sync with core package on mount and locale change\n useEffect(() => {\n setCoreLocale(locale)\n }, [locale])\n\n const setLocale = useCallback(\n (newLocale: Locale) => {\n setLocaleState(newLocale)\n setCoreLocale(newLocale)\n\n // sync cookie for Next.js middleware\n if (cookieName) {\n setCookie(cookieName, newLocale)\n }\n\n // callback for custom handling\n onLocaleChange?.(newLocale)\n },\n [cookieName, onLocaleChange]\n )\n\n const value = useMemo(() => ({ locale, setLocale }), [locale, setLocale])\n\n return <LocaleContext.Provider value={value}>{children}</LocaleContext.Provider>\n}\n","import { createContext, useContext } from 'react'\nimport type { Locale } from 'inline-i18n-multi'\n\ninterface LocaleContextValue {\n locale: Locale\n setLocale: (locale: Locale) => void\n}\n\nexport const LocaleContext = createContext<LocaleContextValue | null>(null)\n\nexport function useLocaleContext(): LocaleContextValue {\n const context = useContext(LocaleContext)\n\n if (!context) {\n throw new Error('useLocaleContext must be used within a LocaleProvider')\n }\n\n return context\n}\n","import { useCallback } from 'react'\nimport { useLocaleContext } from './context'\nimport { t as coreT } from 'inline-i18n-multi'\nimport type { Locale, TranslationVars } from 'inline-i18n-multi'\n\n/**\n * Get current locale and setter\n */\nexport function useLocale(): [Locale, (locale: Locale) => void] {\n const { locale, setLocale } = useLocaleContext()\n return [locale, setLocale]\n}\n\n/**\n * Get translation function bound to current locale\n * @example\n * const t = useT()\n * t('greeting.hello') // uses context locale\n * t('items.count', { count: 5 })\n */\nexport function useT(): (key: string, vars?: TranslationVars) => string {\n const { locale } = useLocaleContext()\n\n return useCallback(\n (key: string, vars?: TranslationVars) => coreT(key, vars, locale),\n [locale]\n )\n}\n","import { it, type Translations, type TranslationVars } from 'inline-i18n-multi'\n\ninterface TPropsShorthand {\n /**\n * Korean text\n */\n ko: string\n /**\n * English text\n */\n en: string\n translations?: never\n}\n\ninterface TPropsObject {\n ko?: never\n en?: never\n /**\n * Translation map with locale keys\n */\n translations: Translations\n}\n\ntype TProps = (TPropsShorthand | TPropsObject) & TranslationVars\n\n/**\n * Translation component for JSX\n * @example <T ko=\"안녕\" en=\"Hello\" />\n * @example <T translations={{ ko: '안녕', en: 'Hello', ja: 'こんにちは' }} />\n * @example <T ko=\"안녕 {name}\" en=\"Hello {name}\" name=\"철수\" />\n */\nexport function T(props: TProps) {\n const { ko, en, translations, ...vars } = props\n\n if (translations) {\n return <>{it(translations, vars)}</>\n }\n\n if (ko !== undefined && en !== undefined) {\n return <>{it(ko, en, vars)}</>\n }\n\n throw new Error('T component requires either \"translations\" or both \"ko\" and \"en\" props')\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,gBAA0E;AAC1E,+BAAwD;;;ACDxD,mBAA0C;AAQnC,IAAM,oBAAgB,4BAAyC,IAAI;AAEnE,SAAS,mBAAuC;AACrD,QAAM,cAAU,yBAAW,aAAa;AAExC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AAEA,SAAO;AACT;;;ADwCS;AArCT,SAAS,UAAU,MAAc,OAAe,OAAO,KAAW;AAChE,MAAI,OAAO,aAAa,YAAa;AACrC,QAAM,UAAU,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,EAAE,YAAY;AAChE,WAAS,SAAS,GAAG,IAAI,IAAI,KAAK,aAAa,OAAO;AACxD;AAEO,SAAS,eAAe;AAAA,EAC7B,QAAQ;AAAA,EACR,aAAa;AAAA,EACb;AAAA,EACA;AACF,GAAwB;AACtB,QAAM,CAAC,QAAQ,cAAc,QAAI,wBAAiB,aAAa;AAG/D,+BAAU,MAAM;AACd,iCAAAC,WAAc,MAAM;AAAA,EACtB,GAAG,CAAC,MAAM,CAAC;AAEX,QAAMC,iBAAY;AAAA,IAChB,CAAC,cAAsB;AACrB,qBAAe,SAAS;AACxB,mCAAAD,WAAc,SAAS;AAGvB,UAAI,YAAY;AACd,kBAAU,YAAY,SAAS;AAAA,MACjC;AAGA,uBAAiB,SAAS;AAAA,IAC5B;AAAA,IACA,CAAC,YAAY,cAAc;AAAA,EAC7B;AAEA,QAAM,YAAQ,uBAAQ,OAAO,EAAE,QAAQ,WAAAC,WAAU,IAAI,CAAC,QAAQA,UAAS,CAAC;AAExE,SAAO,4CAAC,cAAc,UAAd,EAAuB,OAAe,UAAS;AACzD;;;AE3DA,IAAAC,gBAA4B;AAE5B,IAAAC,4BAA2B;AAMpB,SAAS,YAAgD;AAC9D,QAAM,EAAE,QAAQ,WAAAC,WAAU,IAAI,iBAAiB;AAC/C,SAAO,CAAC,QAAQA,UAAS;AAC3B;AASO,SAAS,OAAwD;AACtE,QAAM,EAAE,OAAO,IAAI,iBAAiB;AAEpC,aAAO;AAAA,IACL,CAAC,KAAa,aAA2B,0BAAAC,GAAM,KAAK,MAAM,MAAM;AAAA,IAChE,CAAC,MAAM;AAAA,EACT;AACF;;;AC3BA,IAAAC,4BAA4D;AAmCjD,IAAAC,sBAAA;AAJJ,SAAS,EAAE,OAAe;AAC/B,QAAM,EAAE,IAAI,IAAI,cAAc,GAAG,KAAK,IAAI;AAE1C,MAAI,cAAc;AAChB,WAAO,6EAAG,4CAAG,cAAc,IAAI,GAAE;AAAA,EACnC;AAEA,MAAI,OAAO,UAAa,OAAO,QAAW;AACxC,WAAO,6EAAG,4CAAG,IAAI,IAAI,IAAI,GAAE;AAAA,EAC7B;AAEA,QAAM,IAAI,MAAM,wEAAwE;AAC1F;;;AJtCA,IAAAC,4BAiCO;","names":["import_react","setCoreLocale","setLocale","import_react","import_inline_i18n_multi","setLocale","coreT","import_inline_i18n_multi","import_jsx_runtime","import_inline_i18n_multi"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/provider.tsx","../src/context.tsx","../src/hooks.ts","../src/component.tsx","../src/richtext.tsx"],"sourcesContent":["export { LocaleProvider } from './provider'\nexport { useLocale, useT, useLoadDictionaries } from './hooks'\nexport { T } from './component'\nexport { RichText, useRichText } from './richtext'\n\n// re-export from core for convenience\nexport {\n // inline translations\n it,\n it_ja,\n it_zh,\n it_es,\n it_fr,\n it_de,\n en_ja,\n en_zh,\n en_es,\n en_fr,\n en_de,\n ja_zh,\n ja_es,\n zh_es,\n getLocale,\n setLocale,\n // key-based translations (i18n compatible)\n t,\n loadDictionaries,\n loadDictionary,\n clearDictionaries,\n hasTranslation,\n getLoadedLocales,\n getDictionary,\n loadAsync,\n isLoaded,\n // rich text parsing\n parseRichText,\n type RichTextSegment,\n // types\n type Locale,\n type Translations,\n type TranslationVars,\n type Dictionary,\n type Dictionaries,\n type PluralRules,\n} from 'inline-i18n-multi'\n","import { useState, useCallback, useMemo, useEffect, type ReactNode } from 'react'\nimport { setLocale as setCoreLocale, type Locale } from 'inline-i18n-multi'\nimport { LocaleContext } from './context'\n\ninterface LocaleProviderProps {\n /**\n * Initial locale value\n */\n locale: Locale\n /**\n * Cookie name for persisting locale (default: NEXT_LOCALE)\n * Set to false to disable cookie sync\n */\n cookieName?: string | false\n /**\n * Callback when locale changes\n */\n onLocaleChange?: (locale: Locale) => void\n children: ReactNode\n}\n\nfunction setCookie(name: string, value: string, days = 365): void {\n if (typeof document === 'undefined') return\n const expires = new Date(Date.now() + days * 864e5).toUTCString()\n document.cookie = `${name}=${value}; expires=${expires}; path=/; SameSite=Lax`\n}\n\nexport function LocaleProvider({\n locale: initialLocale,\n cookieName = 'NEXT_LOCALE',\n onLocaleChange,\n children,\n}: LocaleProviderProps) {\n const [locale, setLocaleState] = useState<Locale>(initialLocale)\n\n // sync with core package on mount and locale change\n useEffect(() => {\n setCoreLocale(locale)\n }, [locale])\n\n const setLocale = useCallback(\n (newLocale: Locale) => {\n setLocaleState(newLocale)\n setCoreLocale(newLocale)\n\n // sync cookie for Next.js middleware\n if (cookieName) {\n setCookie(cookieName, newLocale)\n }\n\n // callback for custom handling\n onLocaleChange?.(newLocale)\n },\n [cookieName, onLocaleChange]\n )\n\n const value = useMemo(() => ({ locale, setLocale }), [locale, setLocale])\n\n return <LocaleContext.Provider value={value}>{children}</LocaleContext.Provider>\n}\n","import { createContext, useContext } from 'react'\nimport type { Locale } from 'inline-i18n-multi'\n\ninterface LocaleContextValue {\n locale: Locale\n setLocale: (locale: Locale) => void\n}\n\nexport const LocaleContext = createContext<LocaleContextValue | null>(null)\n\nexport function useLocaleContext(): LocaleContextValue {\n const context = useContext(LocaleContext)\n\n if (!context) {\n throw new Error('useLocaleContext must be used within a LocaleProvider')\n }\n\n return context\n}\n","import { useCallback, useState, useEffect } from 'react'\nimport { useLocaleContext } from './context'\nimport { t as coreT, loadAsync, isLoaded } from 'inline-i18n-multi'\nimport type { Locale, TranslationVars } from 'inline-i18n-multi'\n\n/**\n * Get current locale and setter\n */\nexport function useLocale(): [Locale, (locale: Locale) => void] {\n const { locale, setLocale } = useLocaleContext()\n return [locale, setLocale]\n}\n\n/**\n * Get translation function bound to current locale\n * @example\n * const t = useT()\n * t('greeting.hello') // uses context locale\n * t('items.count', { count: 5 })\n */\nexport function useT(): (key: string, vars?: TranslationVars) => string {\n const { locale } = useLocaleContext()\n\n return useCallback(\n (key: string, vars?: TranslationVars) => coreT(key, vars, locale),\n [locale]\n )\n}\n\n/**\n * Hook for lazy loading dictionaries\n * Automatically loads dictionaries when locale or namespace changes\n *\n * @example\n * function Dashboard() {\n * const { isLoading, error } = useLoadDictionaries('ko', 'dashboard')\n * if (isLoading) return <Spinner />\n * if (error) return <Error message={error.message} />\n * return <Content />\n * }\n */\nexport function useLoadDictionaries(\n locale: Locale,\n namespace?: string\n): { isLoading: boolean; error: Error | null } {\n const [isLoading, setIsLoading] = useState(() => !isLoaded(locale, namespace))\n const [error, setError] = useState<Error | null>(null)\n\n useEffect(() => {\n if (isLoaded(locale, namespace)) {\n setIsLoading(false)\n setError(null)\n return\n }\n\n setIsLoading(true)\n setError(null)\n\n loadAsync(locale, namespace)\n .then(() => setIsLoading(false))\n .catch((err) => {\n setError(err instanceof Error ? err : new Error(String(err)))\n setIsLoading(false)\n })\n }, [locale, namespace])\n\n return { isLoading, error }\n}\n","import { it, type Translations, type TranslationVars } from 'inline-i18n-multi'\n\ninterface TPropsShorthand {\n /**\n * Korean text\n */\n ko: string\n /**\n * English text\n */\n en: string\n translations?: never\n}\n\ninterface TPropsObject {\n ko?: never\n en?: never\n /**\n * Translation map with locale keys\n */\n translations: Translations\n}\n\ntype TProps = (TPropsShorthand | TPropsObject) & TranslationVars\n\n/**\n * Translation component for JSX\n * @example <T ko=\"안녕\" en=\"Hello\" />\n * @example <T translations={{ ko: '안녕', en: 'Hello', ja: 'こんにちは' }} />\n * @example <T ko=\"안녕 {name}\" en=\"Hello {name}\" name=\"철수\" />\n */\nexport function T(props: TProps) {\n const { ko, en, translations, ...vars } = props\n\n if (translations) {\n return <>{it(translations, vars)}</>\n }\n\n if (ko !== undefined && en !== undefined) {\n return <>{it(ko, en, vars)}</>\n }\n\n throw new Error('T component requires either \"translations\" or both \"ko\" and \"en\" props')\n}\n","import React, { type ReactNode, useMemo, useCallback, Fragment } from 'react'\nimport { it, parseRichText, type Translations, type TranslationVars } from 'inline-i18n-multi'\n\ntype ComponentRenderer = (text: string) => ReactNode\n\ninterface RichTextProps {\n /**\n * Translation map with locale keys\n * Tags like <link>text</link> will be matched to component renderers\n */\n translations: Translations\n /**\n * Component renderers for each tag name\n * @example { link: (text) => <a href=\"/terms\">{text}</a> }\n */\n components: Record<string, ComponentRenderer>\n /**\n * Variables for interpolation (applied before rich text parsing)\n */\n vars?: TranslationVars\n}\n\n/**\n * Rich text translation component\n * Supports embedding React components within translations\n *\n * @example\n * <RichText\n * translations={{\n * en: 'Read <link>terms</link> and <bold>agree</bold>',\n * ko: '<link>약관</link>을 읽고 <bold>동의</bold>해주세요'\n * }}\n * components={{\n * link: (text) => <a href=\"/terms\">{text}</a>,\n * bold: (text) => <strong>{text}</strong>\n * }}\n * />\n */\nexport function RichText({ translations, components, vars }: RichTextProps): React.JSX.Element {\n const componentNames = useMemo(() => Object.keys(components), [components])\n\n // Resolve locale and interpolate variables ({curly} braces)\n // Rich text tags (<angle> brackets) don't conflict with variable interpolation\n const resolved = it(translations, vars)\n const segments = parseRichText(resolved, componentNames)\n\n return (\n <>\n {segments.map((segment, index) => {\n if (segment.type === 'text') {\n return <Fragment key={index}>{segment.content}</Fragment>\n }\n const renderer = components[segment.componentName!]\n if (!renderer) {\n return <Fragment key={index}>{segment.content}</Fragment>\n }\n return <Fragment key={index}>{renderer(segment.content)}</Fragment>\n })}\n </>\n )\n}\n\n/**\n * Hook for rich text translations\n * Returns a function that resolves translations with component interpolation\n *\n * @example\n * const richT = useRichText({\n * link: (text) => <a href=\"/terms\">{text}</a>,\n * bold: (text) => <strong>{text}</strong>,\n * })\n * return richT({ en: 'Click <link>here</link>', ko: '<link>여기</link> 클릭' })\n */\nexport function useRichText(\n components: Record<string, ComponentRenderer>\n): (translations: Translations, vars?: TranslationVars) => ReactNode {\n const componentNames = useMemo(() => Object.keys(components), [components])\n\n return useCallback(\n (translations: Translations, vars?: TranslationVars): ReactNode => {\n const resolved = it(translations, vars)\n const segments = parseRichText(resolved, componentNames)\n\n return (\n <>\n {segments.map((segment, index) => {\n if (segment.type === 'text') {\n return <Fragment key={index}>{segment.content}</Fragment>\n }\n const renderer = components[segment.componentName!]\n if (!renderer) {\n return <Fragment key={index}>{segment.content}</Fragment>\n }\n return <Fragment key={index}>{renderer(segment.content)}</Fragment>\n })}\n </>\n )\n },\n [components, componentNames]\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,gBAA0E;AAC1E,+BAAwD;;;ACDxD,mBAA0C;AAQnC,IAAM,oBAAgB,4BAAyC,IAAI;AAEnE,SAAS,mBAAuC;AACrD,QAAM,cAAU,yBAAW,aAAa;AAExC,MAAI,CAAC,SAAS;AACZ,UAAM,IAA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S,QAAQ;AAC3B,aAAO,6CAAC,0BAAsB,kBAAQ,WAAhB,KAAwB;AAAA,IAChD;AACA,UAAM,WAAW,WAAW,QAAQ,aAAc;AAClD,QAAI,CAAC,UAAU;AACb,aAAO,6CAAC,0BAAsB,kBAAQ,WAAhB,KAAwB;AAAA,IAChD;AACA,WAAO,6CAAC,0BAAsB,mBAAS,QAAQ,OAAO,KAAhC,KAAkC;AAAA,EAC1D,CAAC,GACH;AAEJ;AAaO,SAAS,YACd,YACmE;AACnE,QAAM,qBAAiB,uBAAQ,MAAM,OAAO,KAAK,UAAU,GAAG,CAAC,UAAU,CAAC;AAE1E,aAAO;AAAA,IACL,CAAC,cAA4B,SAAsC;AACjE,YAAM,eAAW,8BAAG,cAAc,IAAI;AACtC,YAAM,eAAW,yCAAc,UAAU,cAAc;AAEvD,aACE,6EACG,mBAAS,IAAI,CAAC,SAAS,UAAU;AAChC,YAAI,QAAQ,SAAS,QAAQ;AAC3B,iBAAO,6CAAC,0BAAsB,kBAAQ,WAAhB,KAAwB;AAAA,QAChD;AACA,cAAM,WAAW,WAAW,QAAQ,aAAc;AAClD,YAAI,CAAC,UAAU;AACb,iBAAO,6CAAC,0BAAsB,kBAAQ,WAAhB,KAAwB;AAAA,QAChD;AACA,eAAO,6CAAC,0BAAsB,mBAAS,QAAQ,OAAO,KAAhC,KAAkC;AAAA,MAC1D,CAAC,GACH;AAAA,IAEJ;AAAA,IACA,CAAC,YAAY,cAAc;AAAA,EAC7B;AACF;;;AL9FA,IAAAC,4BAsCO;","names":["import_react","setCoreLocale","setLocale","import_react","import_inline_i18n_multi","setLocale","coreT","import_inline_i18n_multi","import_jsx_runtime","import_react","import_inline_i18n_multi","import_jsx_runtime","import_inline_i18n_multi"]}
|
package/dist/index.mjs
CHANGED
|
@@ -48,8 +48,8 @@ function LocaleProvider({
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
// src/hooks.ts
|
|
51
|
-
import { useCallback as useCallback2 } from "react";
|
|
52
|
-
import { t as coreT } from "inline-i18n-multi";
|
|
51
|
+
import { useCallback as useCallback2, useState as useState2, useEffect as useEffect2 } from "react";
|
|
52
|
+
import { t as coreT, loadAsync, isLoaded } from "inline-i18n-multi";
|
|
53
53
|
function useLocale() {
|
|
54
54
|
const { locale, setLocale: setLocale2 } = useLocaleContext();
|
|
55
55
|
return [locale, setLocale2];
|
|
@@ -61,6 +61,24 @@ function useT() {
|
|
|
61
61
|
[locale]
|
|
62
62
|
);
|
|
63
63
|
}
|
|
64
|
+
function useLoadDictionaries(locale, namespace) {
|
|
65
|
+
const [isLoading, setIsLoading] = useState2(() => !isLoaded(locale, namespace));
|
|
66
|
+
const [error, setError] = useState2(null);
|
|
67
|
+
useEffect2(() => {
|
|
68
|
+
if (isLoaded(locale, namespace)) {
|
|
69
|
+
setIsLoading(false);
|
|
70
|
+
setError(null);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
setIsLoading(true);
|
|
74
|
+
setError(null);
|
|
75
|
+
loadAsync(locale, namespace).then(() => setIsLoading(false)).catch((err) => {
|
|
76
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
77
|
+
setIsLoading(false);
|
|
78
|
+
});
|
|
79
|
+
}, [locale, namespace]);
|
|
80
|
+
return { isLoading, error };
|
|
81
|
+
}
|
|
64
82
|
|
|
65
83
|
// src/component.tsx
|
|
66
84
|
import { it } from "inline-i18n-multi";
|
|
@@ -76,9 +94,49 @@ function T(props) {
|
|
|
76
94
|
throw new Error('T component requires either "translations" or both "ko" and "en" props');
|
|
77
95
|
}
|
|
78
96
|
|
|
97
|
+
// src/richtext.tsx
|
|
98
|
+
import { useMemo as useMemo2, useCallback as useCallback3, Fragment as Fragment2 } from "react";
|
|
99
|
+
import { it as it2, parseRichText } from "inline-i18n-multi";
|
|
100
|
+
import { Fragment as Fragment3, jsx as jsx3 } from "react/jsx-runtime";
|
|
101
|
+
function RichText({ translations, components, vars }) {
|
|
102
|
+
const componentNames = useMemo2(() => Object.keys(components), [components]);
|
|
103
|
+
const resolved = it2(translations, vars);
|
|
104
|
+
const segments = parseRichText(resolved, componentNames);
|
|
105
|
+
return /* @__PURE__ */ jsx3(Fragment3, { children: segments.map((segment, index) => {
|
|
106
|
+
if (segment.type === "text") {
|
|
107
|
+
return /* @__PURE__ */ jsx3(Fragment2, { children: segment.content }, index);
|
|
108
|
+
}
|
|
109
|
+
const renderer = components[segment.componentName];
|
|
110
|
+
if (!renderer) {
|
|
111
|
+
return /* @__PURE__ */ jsx3(Fragment2, { children: segment.content }, index);
|
|
112
|
+
}
|
|
113
|
+
return /* @__PURE__ */ jsx3(Fragment2, { children: renderer(segment.content) }, index);
|
|
114
|
+
}) });
|
|
115
|
+
}
|
|
116
|
+
function useRichText(components) {
|
|
117
|
+
const componentNames = useMemo2(() => Object.keys(components), [components]);
|
|
118
|
+
return useCallback3(
|
|
119
|
+
(translations, vars) => {
|
|
120
|
+
const resolved = it2(translations, vars);
|
|
121
|
+
const segments = parseRichText(resolved, componentNames);
|
|
122
|
+
return /* @__PURE__ */ jsx3(Fragment3, { children: segments.map((segment, index) => {
|
|
123
|
+
if (segment.type === "text") {
|
|
124
|
+
return /* @__PURE__ */ jsx3(Fragment2, { children: segment.content }, index);
|
|
125
|
+
}
|
|
126
|
+
const renderer = components[segment.componentName];
|
|
127
|
+
if (!renderer) {
|
|
128
|
+
return /* @__PURE__ */ jsx3(Fragment2, { children: segment.content }, index);
|
|
129
|
+
}
|
|
130
|
+
return /* @__PURE__ */ jsx3(Fragment2, { children: renderer(segment.content) }, index);
|
|
131
|
+
}) });
|
|
132
|
+
},
|
|
133
|
+
[components, componentNames]
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
79
137
|
// src/index.ts
|
|
80
138
|
import {
|
|
81
|
-
it as
|
|
139
|
+
it as it3,
|
|
82
140
|
it_ja,
|
|
83
141
|
it_zh,
|
|
84
142
|
it_es,
|
|
@@ -100,10 +158,14 @@ import {
|
|
|
100
158
|
clearDictionaries,
|
|
101
159
|
hasTranslation,
|
|
102
160
|
getLoadedLocales,
|
|
103
|
-
getDictionary
|
|
161
|
+
getDictionary,
|
|
162
|
+
loadAsync as loadAsync2,
|
|
163
|
+
isLoaded as isLoaded2,
|
|
164
|
+
parseRichText as parseRichText2
|
|
104
165
|
} from "inline-i18n-multi";
|
|
105
166
|
export {
|
|
106
167
|
LocaleProvider,
|
|
168
|
+
RichText,
|
|
107
169
|
T,
|
|
108
170
|
clearDictionaries,
|
|
109
171
|
en_de,
|
|
@@ -115,7 +177,8 @@ export {
|
|
|
115
177
|
getLoadedLocales,
|
|
116
178
|
getLocale,
|
|
117
179
|
hasTranslation,
|
|
118
|
-
|
|
180
|
+
isLoaded2 as isLoaded,
|
|
181
|
+
it3 as it,
|
|
119
182
|
it_de,
|
|
120
183
|
it_es,
|
|
121
184
|
it_fr,
|
|
@@ -123,11 +186,15 @@ export {
|
|
|
123
186
|
it_zh,
|
|
124
187
|
ja_es,
|
|
125
188
|
ja_zh,
|
|
189
|
+
loadAsync2 as loadAsync,
|
|
126
190
|
loadDictionaries,
|
|
127
191
|
loadDictionary,
|
|
192
|
+
parseRichText2 as parseRichText,
|
|
128
193
|
setLocale,
|
|
129
194
|
t,
|
|
195
|
+
useLoadDictionaries,
|
|
130
196
|
useLocale,
|
|
197
|
+
useRichText,
|
|
131
198
|
useT,
|
|
132
199
|
zh_es
|
|
133
200
|
};
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/provider.tsx","../src/context.tsx","../src/hooks.ts","../src/component.tsx","../src/index.ts"],"sourcesContent":["import { useState, useCallback, useMemo, useEffect, type ReactNode } from 'react'\nimport { setLocale as setCoreLocale, type Locale } from 'inline-i18n-multi'\nimport { LocaleContext } from './context'\n\ninterface LocaleProviderProps {\n /**\n * Initial locale value\n */\n locale: Locale\n /**\n * Cookie name for persisting locale (default: NEXT_LOCALE)\n * Set to false to disable cookie sync\n */\n cookieName?: string | false\n /**\n * Callback when locale changes\n */\n onLocaleChange?: (locale: Locale) => void\n children: ReactNode\n}\n\nfunction setCookie(name: string, value: string, days = 365): void {\n if (typeof document === 'undefined') return\n const expires = new Date(Date.now() + days * 864e5).toUTCString()\n document.cookie = `${name}=${value}; expires=${expires}; path=/; SameSite=Lax`\n}\n\nexport function LocaleProvider({\n locale: initialLocale,\n cookieName = 'NEXT_LOCALE',\n onLocaleChange,\n children,\n}: LocaleProviderProps) {\n const [locale, setLocaleState] = useState<Locale>(initialLocale)\n\n // sync with core package on mount and locale change\n useEffect(() => {\n setCoreLocale(locale)\n }, [locale])\n\n const setLocale = useCallback(\n (newLocale: Locale) => {\n setLocaleState(newLocale)\n setCoreLocale(newLocale)\n\n // sync cookie for Next.js middleware\n if (cookieName) {\n setCookie(cookieName, newLocale)\n }\n\n // callback for custom handling\n onLocaleChange?.(newLocale)\n },\n [cookieName, onLocaleChange]\n )\n\n const value = useMemo(() => ({ locale, setLocale }), [locale, setLocale])\n\n return <LocaleContext.Provider value={value}>{children}</LocaleContext.Provider>\n}\n","import { createContext, useContext } from 'react'\nimport type { Locale } from 'inline-i18n-multi'\n\ninterface LocaleContextValue {\n locale: Locale\n setLocale: (locale: Locale) => void\n}\n\nexport const LocaleContext = createContext<LocaleContextValue | null>(null)\n\nexport function useLocaleContext(): LocaleContextValue {\n const context = useContext(LocaleContext)\n\n if (!context) {\n throw new Error('useLocaleContext must be used within a LocaleProvider')\n }\n\n return context\n}\n","import { useCallback } from 'react'\nimport { useLocaleContext } from './context'\nimport { t as coreT } from 'inline-i18n-multi'\nimport type { Locale, TranslationVars } from 'inline-i18n-multi'\n\n/**\n * Get current locale and setter\n */\nexport function useLocale(): [Locale, (locale: Locale) => void] {\n const { locale, setLocale } = useLocaleContext()\n return [locale, setLocale]\n}\n\n/**\n * Get translation function bound to current locale\n * @example\n * const t = useT()\n * t('greeting.hello') // uses context locale\n * t('items.count', { count: 5 })\n */\nexport function useT(): (key: string, vars?: TranslationVars) => string {\n const { locale } = useLocaleContext()\n\n return useCallback(\n (key: string, vars?: TranslationVars) => coreT(key, vars, locale),\n [locale]\n )\n}\n","import { it, type Translations, type TranslationVars } from 'inline-i18n-multi'\n\ninterface TPropsShorthand {\n /**\n * Korean text\n */\n ko: string\n /**\n * English text\n */\n en: string\n translations?: never\n}\n\ninterface TPropsObject {\n ko?: never\n en?: never\n /**\n * Translation map with locale keys\n */\n translations: Translations\n}\n\ntype TProps = (TPropsShorthand | TPropsObject) & TranslationVars\n\n/**\n * Translation component for JSX\n * @example <T ko=\"안녕\" en=\"Hello\" />\n * @example <T translations={{ ko: '안녕', en: 'Hello', ja: 'こんにちは' }} />\n * @example <T ko=\"안녕 {name}\" en=\"Hello {name}\" name=\"철수\" />\n */\nexport function T(props: TProps) {\n const { ko, en, translations, ...vars } = props\n\n if (translations) {\n return <>{it(translations, vars)}</>\n }\n\n if (ko !== undefined && en !== undefined) {\n return <>{it(ko, en, vars)}</>\n }\n\n throw new Error('T component requires either \"translations\" or both \"ko\" and \"en\" props')\n}\n","export { LocaleProvider } from './provider'\nexport { useLocale, useT } from './hooks'\nexport { T } from './component'\n\n// re-export from core for convenience\nexport {\n // inline translations\n it,\n it_ja,\n it_zh,\n it_es,\n it_fr,\n it_de,\n en_ja,\n en_zh,\n en_es,\n en_fr,\n en_de,\n ja_zh,\n ja_es,\n zh_es,\n getLocale,\n setLocale,\n // key-based translations (i18n compatible)\n t,\n loadDictionaries,\n loadDictionary,\n clearDictionaries,\n hasTranslation,\n getLoadedLocales,\n getDictionary,\n // types\n type Locale,\n type Translations,\n type TranslationVars,\n type Dictionary,\n type Dictionaries,\n type PluralRules,\n} from 'inline-i18n-multi'\n"],"mappings":";;;AAAA,SAAS,UAAU,aAAa,SAAS,iBAAiC;AAC1E,SAAS,aAAa,qBAAkC;;;ACDxD,SAAS,eAAe,kBAAkB;AAQnC,IAAM,gBAAgB,cAAyC,IAAI;AAEnE,SAAS,mBAAuC;AACrD,QAAM,UAAU,WAAW,aAA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D;AAmCjD,0BAAAC,YAAA;AAJJ,SAAS,EAAE,OAAe;AAC/B,QAAM,EAAE,IAAI,IAAI,cAAc,GAAG,KAAK,IAAI;AAE1C,MAAI,cAAc;AAChB,WAAO,gBAAAA,KAAA,YAAG,aAAG,cAAc,IAAI,GAAE;AAAA,EACnC;AAEA,MAAI,OAAO,UAAa,OAAO,QAAW;AACxC,WAAO,gBAAAA,KAAA,YAAG,aAAG,IAAI,IAAI,IAAI,GAAE;AAAA,EAC7B;AAEA,QAAM,IAAI,MAAM,wEAAwE;AAC1F;;;ACtCA;AAAA,EAEE,MAAAC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAQK;","names":["setLocale","useCallback","setLocale","useCallback","jsx","it"]}
|
|
1
|
+
{"version":3,"sources":["../src/provider.tsx","../src/context.tsx","../src/hooks.ts","../src/component.tsx","../src/richtext.tsx","../src/index.ts"],"sourcesContent":["import { useState, useCallback, useMemo, useEffect, type ReactNode } from 'react'\nimport { setLocale as setCoreLocale, type Locale } from 'inline-i18n-multi'\nimport { LocaleContext } from './context'\n\ninterface LocaleProviderProps {\n /**\n * Initial locale value\n */\n locale: Locale\n /**\n * Cookie name for persisting locale (default: NEXT_LOCALE)\n * Set to false to disable cookie sync\n */\n cookieName?: string | false\n /**\n * Callback when locale changes\n */\n onLocaleChange?: (locale: Locale) => void\n children: ReactNode\n}\n\nfunction setCookie(name: string, value: string, days = 365): void {\n if (typeof document === 'undefined') return\n const expires = new Date(Date.now() + days * 864e5).toUTCString()\n document.cookie = `${name}=${value}; expires=${expires}; path=/; SameSite=Lax`\n}\n\nexport function LocaleProvider({\n locale: initialLocale,\n cookieName = 'NEXT_LOCALE',\n onLocaleChange,\n children,\n}: LocaleProviderProps) {\n const [locale, setLocaleState] = useState<Locale>(initialLocale)\n\n // sync with core package on mount and locale change\n useEffect(() => {\n setCoreLocale(locale)\n }, [locale])\n\n const setLocale = useCallback(\n (newLocale: Locale) => {\n setLocaleState(newLocale)\n setCoreLocale(newLocale)\n\n // sync cookie for Next.js middleware\n if (cookieName) {\n setCookie(cookieName, newLocale)\n }\n\n // callback for custom handling\n onLocaleChange?.(newLocale)\n },\n [cookieName, onLocaleChange]\n )\n\n const value = useMemo(() => ({ locale, setLocale }), [locale, setLocale])\n\n return <LocaleContext.Provider value={value}>{children}</LocaleContext.Provider>\n}\n","import { createContext, useContext } from 'react'\nimport type { Locale } from 'inline-i18n-multi'\n\ninterface LocaleContextValue {\n locale: Locale\n setLocale: (locale: Locale) => void\n}\n\nexport const LocaleContext = createContext<LocaleContextValue | null>(null)\n\nexport function useLocaleContext(): LocaleContextValue {\n const context = useContext(LocaleContext)\n\n if (!context) {\n throw new Error('useLocaleContext must be used within a LocaleProvider')\n }\n\n return context\n}\n","import { useCallback, useState, useEffect } from 'react'\nimport { useLocaleContext } from './context'\nimport { t as coreT, loadAsync, isLoaded } from 'inline-i18n-multi'\nimport type { Locale, TranslationVars } from 'inline-i18n-multi'\n\n/**\n * Get current locale and setter\n */\nexport function useLocale(): [Locale, (locale: Locale) => void] {\n const { locale, setLocale } = useLocaleContext()\n return [locale, setLocale]\n}\n\n/**\n * Get translation function bound to current locale\n * @example\n * const t = useT()\n * t('greeting.hello') // uses context locale\n * t('items.count', { count: 5 })\n */\nexport function useT(): (key: string, vars?: TranslationVars) => string {\n const { locale } = useLocaleContext()\n\n return useCallback(\n (key: string, vars?: TranslationVars) => coreT(key, vars, locale),\n [locale]\n )\n}\n\n/**\n * Hook for lazy loading dictionaries\n * Automatically loads dictionaries when locale or namespace changes\n *\n * @example\n * function Dashboard() {\n * const { isLoading, error } = useLoadDictionaries('ko', 'dashboard')\n * if (isLoading) return <Spinner />\n * if (error) return <Error message={error.message} />\n * return <Content />\n * }\n */\nexport function useLoadDictionaries(\n locale: Locale,\n namespace?: string\n): { isLoading: boolean; error: Error | null } {\n const [isLoading, setIsLoading] = useState(() => !isLoaded(locale, namespace))\n const [error, setError] = useState<Error | null>(null)\n\n useEffect(() => {\n if (isLoaded(locale, namespace)) {\n setIsLoading(false)\n setError(null)\n return\n }\n\n setIsLoading(true)\n setError(null)\n\n loadAsync(locale, namespace)\n .then(() => setIsLoading(false))\n .catch((err) => {\n setError(err instanceof Error ? err : new Error(String(err)))\n setIsLoading(false)\n })\n }, [locale, namespace])\n\n return { isLoading, error }\n}\n","import { it, type Translations, type TranslationVars } from 'inline-i18n-multi'\n\ninterface TPropsShorthand {\n /**\n * Korean text\n */\n ko: string\n /**\n * English text\n */\n en: string\n translations?: never\n}\n\ninterface TPropsObject {\n ko?: never\n en?: never\n /**\n * Translation map with locale keys\n */\n translations: Translations\n}\n\ntype TProps = (TPropsShorthand | TPropsObject) & TranslationVars\n\n/**\n * Translation component for JSX\n * @example <T ko=\"안녕\" en=\"Hello\" />\n * @example <T translations={{ ko: '안녕', en: 'Hello', ja: 'こんにちは' }} />\n * @example <T ko=\"안녕 {name}\" en=\"Hello {name}\" name=\"철수\" />\n */\nexport function T(props: TProps) {\n const { ko, en, translations, ...vars } = props\n\n if (translations) {\n return <>{it(translations, vars)}</>\n }\n\n if (ko !== undefined && en !== undefined) {\n return <>{it(ko, en, vars)}</>\n }\n\n throw new Error('T component requires either \"translations\" or both \"ko\" and \"en\" props')\n}\n","import React, { type ReactNode, useMemo, useCallback, Fragment } from 'react'\nimport { it, parseRichText, type Translations, type TranslationVars } from 'inline-i18n-multi'\n\ntype ComponentRenderer = (text: string) => ReactNode\n\ninterface RichTextProps {\n /**\n * Translation map with locale keys\n * Tags like <link>text</link> will be matched to component renderers\n */\n translations: Translations\n /**\n * Component renderers for each tag name\n * @example { link: (text) => <a href=\"/terms\">{text}</a> }\n */\n components: Record<string, ComponentRenderer>\n /**\n * Variables for interpolation (applied before rich text parsing)\n */\n vars?: TranslationVars\n}\n\n/**\n * Rich text translation component\n * Supports embedding React components within translations\n *\n * @example\n * <RichText\n * translations={{\n * en: 'Read <link>terms</link> and <bold>agree</bold>',\n * ko: '<link>약관</link>을 읽고 <bold>동의</bold>해주세요'\n * }}\n * components={{\n * link: (text) => <a href=\"/terms\">{text}</a>,\n * bold: (text) => <strong>{text}</strong>\n * }}\n * />\n */\nexport function RichText({ translations, components, vars }: RichTextProps): React.JSX.Element {\n const componentNames = useMemo(() => Object.keys(components), [components])\n\n // Resolve locale and interpolate variables ({curly} braces)\n // Rich text tags (<angle> brackets) don't conflict with variable interpolation\n const resolved = it(translations, vars)\n const segments = parseRichText(resolved, componentNames)\n\n return (\n <>\n {segments.map((segment, index) => {\n if (segment.type === 'text') {\n return <Fragment key={index}>{segment.content}</Fragment>\n }\n const renderer = components[segment.componentName!]\n if (!renderer) {\n return <Fragment key={index}>{segment.content}</Fragment>\n }\n return <Fragment key={index}>{renderer(segment.content)}</Fragment>\n })}\n </>\n )\n}\n\n/**\n * Hook for rich text translations\n * Returns a function that resolves translations with component interpolation\n *\n * @example\n * const richT = useRichText({\n * link: (text) => <a href=\"/terms\">{text}</a>,\n * bold: (text) => <strong>{text}</strong>,\n * })\n * return richT({ en: 'Click <link>here</link>', ko: '<link>여기</link> 클릭' })\n */\nexport function useRichText(\n components: Record<string, ComponentRenderer>\n): (translations: Translations, vars?: TranslationVars) => ReactNode {\n const componentNames = useMemo(() => Object.keys(components), [components])\n\n return useCallback(\n (translations: Translations, vars?: TranslationVars): ReactNode => {\n const resolved = it(translations, vars)\n const segments = parseRichText(resolved, componentNames)\n\n return (\n <>\n {segments.map((segment, index) => {\n if (segment.type === 'text') {\n return <Fragment key={index}>{segment.content}</Fragment>\n }\n const renderer = components[segment.componentName!]\n if (!renderer) {\n return <Fragment key={index}>{segment.content}</Fragment>\n }\n return <Fragment key={index}>{renderer(segment.content)}</Fragment>\n })}\n </>\n )\n },\n [components, componentNames]\n )\n}\n","export { LocaleProvider } from './provider'\nexport { useLocale, useT, useLoadDictionaries } from './hooks'\nexport { T } from './component'\nexport { RichText, useRichText } from './richtext'\n\n// re-export from core for convenience\nexport {\n // inline translations\n it,\n it_ja,\n it_zh,\n it_es,\n it_fr,\n it_de,\n en_ja,\n en_zh,\n en_es,\n en_fr,\n en_de,\n ja_zh,\n ja_es,\n zh_es,\n getLocale,\n setLocale,\n // key-based translations (i18n compatible)\n t,\n loadDictionaries,\n loadDictionary,\n clearDictionaries,\n hasTranslation,\n getLoadedLocales,\n getDictionary,\n loadAsync,\n isLoaded,\n // rich text parsing\n parseRichText,\n type RichTextSegment,\n // types\n type Locale,\n type Translations,\n type TranslationVars,\n type Dictionary,\n type Dictionaries,\n type PluralRules,\n} from 'inline-i18n-multi'\n"],"mappings":";;;AAAA,SAAS,UAAU,aAAa,SAAS,iBAAiC;AAC1E,SAAS,aAAa,qBAAkC;;;ACDxD,SAAS,eAAe,kBAAkB;AAQnC,IAAM,gBAAgB,cAAyC,IAAI;AAEnE,SAAS,mBAAuC;AACrD,QAAM,UAAU,WAAW,aAAa;AAExC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AAEA,SAAO;AACT;;;ADwCS;AArCT,SAAS,UAAU,MAAc,OAAe,OAAO,KAAW;AAChE,MAAI,OAAO,aAAa,YAAa;AACrC,QAAM,UAAU,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,EAAE,YAAY;AAChE,WAAS,SAAS,GAAG,IAAI,IAAI,KAAK,aAAa,OAAO;AACxD;AAEO,SAAS,eAAe;AAAA,EAC7B,QAAQ;AAAA,EACR,aAAa;AAAA,EACb;AAAA,EACA;AACF,GAAwB;AACtB,QAAM,CAAC,QAAQ,cAAc,IAAI,SAAiB,aAAa;AAG/D,YAAU,MAAM;AACd,kBAAc,MAAM;AAAA,EACtB,GAAG,CAAC,MAAM,CAAC;AAEX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,QAAM,iBAAiBF,SAAQ,MAAM,OAAO,KAAK,UAAU,GAAG,CAAC,UAAU,CAAC;AAE1E,SAAOC;AAAA,IACL,CAAC,cAA4B,SAAsC;AACjE,YAAM,WAAWE,IAAG,cAAc,IAAI;AACtC,YAAM,WAAW,cAAc,UAAU,cAAc;AAEvD,aACE,gBAAAC,KAAAF,WAAA,EACG,mBAAS,IAAI,CAAC,SAAS,UAAU;AAChC,YAAI,QAAQ,SAAS,QAAQ;AAC3B,iBAAO,gBAAAE,KAACF,WAAA,EAAsB,kBAAQ,WAAhB,KAAwB;AAAA,QAChD;AACA,cAAM,WAAW,WAAW,QAAQ,aAAc;AAClD,YAAI,CAAC,UAAU;AACb,iBAAO,gBAAAE,KAACF,WAAA,EAAsB,kBAAQ,WAAhB,KAAwB;AAAA,QAChD;AACA,eAAO,gBAAAE,KAACF,WAAA,EAAsB,mBAAS,QAAQ,OAAO,KAAhC,KAAkC;AAAA,MAC1D,CAAC,GACH;AAAA,IAEJ;AAAA,IACA,CAAC,YAAY,cAAc;AAAA,EAC7B;AACF;;;AC9FA;AAAA,EAEE,MAAAG;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,aAAAC;AAAA,EACA,YAAAC;AAAA,EAEA,iBAAAC;AAAA,OASK;","names":["setLocale","useCallback","useState","useEffect","setLocale","useCallback","useState","useEffect","jsx","useMemo","useCallback","Fragment","it","jsx","it","loadAsync","isLoaded","parseRichText"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inline-i18n-multi-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "React integration for inline-i18n-multi",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"react": "^18.0.0 || ^19.0.0"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"inline-i18n-multi": "0.
|
|
37
|
+
"inline-i18n-multi": "0.5.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/react": "^19.0.2",
|