@sheet-i18n/react-client 1.0.7 → 1.0.9
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 +6 -7
- package/dist/index.d.ts +6 -7
- package/dist/index.js +75 -54
- package/dist/index.mjs +75 -54
- package/package.json +5 -5
package/dist/index.d.mts
CHANGED
|
@@ -2,19 +2,18 @@ import { MessageDescriptor, IntlShape } from 'react-intl';
|
|
|
2
2
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
3
|
import { I18nStore } from '@sheet-i18n/react-core';
|
|
4
4
|
|
|
5
|
-
type UseIntlParams
|
|
6
|
-
type $TParams
|
|
5
|
+
type UseIntlParams<D = MessageDescriptor> = Parameters<IntlShape['$t']> extends [D, ...infer R] ? [...R, Omit<D, 'id'>] : never;
|
|
6
|
+
type $TParams = Partial<UseIntlParams>;
|
|
7
|
+
|
|
7
8
|
type GetTranslationReturn<TSupportedLocales extends readonly string[], TLocaleSet extends Record<TSupportedLocales[number], Record<string, any>>, TTypeSafe extends boolean, TSheetTitle extends TTypeSafe extends true ? keyof TLocaleSet[TSupportedLocales[number]] : string> = {
|
|
8
|
-
t: <TMessageId extends TTypeSafe extends true ? keyof TLocaleSet[TSupportedLocales[number]][TSheetTitle] : string, TValues extends $TParams
|
|
9
|
+
t: <TMessageId extends TTypeSafe extends true ? keyof TLocaleSet[TSupportedLocales[number]][TSheetTitle] : string, TValues extends $TParams[0], TOpts extends $TParams[1], TDescriptor extends $TParams[2]>(id: TMessageId, values?: TValues, opts?: TOpts, _descriptor?: TDescriptor) => TTypeSafe extends true ? TMessageId : any;
|
|
9
10
|
} & {
|
|
10
11
|
t: {
|
|
11
|
-
dynamic: <TMessageId extends TTypeSafe extends true ? keyof TLocaleSet[TSupportedLocales[number]][TSheetTitle] : string, TValues extends $TParams
|
|
12
|
-
promise: <TMessageId extends TTypeSafe extends true ? keyof TLocaleSet[TSupportedLocales[number]][TSheetTitle] : string, TValues extends $TParams
|
|
12
|
+
dynamic: <TMessageId extends TTypeSafe extends true ? keyof TLocaleSet[TSupportedLocales[number]][TSheetTitle] : string, TValues extends $TParams[0], TOpts extends $TParams[1], TDescriptor extends $TParams[2]>(id: string, values?: TValues, opts?: TOpts, _descriptor?: TDescriptor) => TTypeSafe extends true ? string : any;
|
|
13
|
+
promise: <TMessageId extends TTypeSafe extends true ? keyof TLocaleSet[TSupportedLocales[number]][TSheetTitle] : string, TValues extends $TParams[0], TOpts extends $TParams[1], TDescriptor extends $TParams[2]>(id: TMessageId, values?: TValues, opts?: TOpts, _descriptor?: TDescriptor) => TTypeSafe extends true ? Promise<TMessageId> : any;
|
|
13
14
|
};
|
|
14
15
|
};
|
|
15
16
|
|
|
16
|
-
type UseIntlParams<D = MessageDescriptor> = Parameters<IntlShape['$t']> extends [D, ...infer R] ? [...R, Omit<D, 'id'>] : never;
|
|
17
|
-
type $TParams = Partial<UseIntlParams>;
|
|
18
17
|
type UseTranslationReturn<TSupportedLocales extends readonly string[], TLocaleSet extends Record<TSupportedLocales[number], Record<string, any>>, TTypeSafe extends boolean, TSheetTitle extends TTypeSafe extends true ? keyof TLocaleSet[TSupportedLocales[number]] : string> = {
|
|
19
18
|
t: <TMessageId extends TTypeSafe extends true ? keyof TLocaleSet[TSupportedLocales[number]][TSheetTitle] : string, TValues extends $TParams[0], TOpts extends $TParams[1], TDescriptor extends $TParams[2]>(id: TMessageId, values?: TValues, opts?: TOpts, _descriptor?: TDescriptor) => TTypeSafe extends true ? TMessageId : any;
|
|
20
19
|
} & {
|
package/dist/index.d.ts
CHANGED
|
@@ -2,19 +2,18 @@ import { MessageDescriptor, IntlShape } from 'react-intl';
|
|
|
2
2
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
3
|
import { I18nStore } from '@sheet-i18n/react-core';
|
|
4
4
|
|
|
5
|
-
type UseIntlParams
|
|
6
|
-
type $TParams
|
|
5
|
+
type UseIntlParams<D = MessageDescriptor> = Parameters<IntlShape['$t']> extends [D, ...infer R] ? [...R, Omit<D, 'id'>] : never;
|
|
6
|
+
type $TParams = Partial<UseIntlParams>;
|
|
7
|
+
|
|
7
8
|
type GetTranslationReturn<TSupportedLocales extends readonly string[], TLocaleSet extends Record<TSupportedLocales[number], Record<string, any>>, TTypeSafe extends boolean, TSheetTitle extends TTypeSafe extends true ? keyof TLocaleSet[TSupportedLocales[number]] : string> = {
|
|
8
|
-
t: <TMessageId extends TTypeSafe extends true ? keyof TLocaleSet[TSupportedLocales[number]][TSheetTitle] : string, TValues extends $TParams
|
|
9
|
+
t: <TMessageId extends TTypeSafe extends true ? keyof TLocaleSet[TSupportedLocales[number]][TSheetTitle] : string, TValues extends $TParams[0], TOpts extends $TParams[1], TDescriptor extends $TParams[2]>(id: TMessageId, values?: TValues, opts?: TOpts, _descriptor?: TDescriptor) => TTypeSafe extends true ? TMessageId : any;
|
|
9
10
|
} & {
|
|
10
11
|
t: {
|
|
11
|
-
dynamic: <TMessageId extends TTypeSafe extends true ? keyof TLocaleSet[TSupportedLocales[number]][TSheetTitle] : string, TValues extends $TParams
|
|
12
|
-
promise: <TMessageId extends TTypeSafe extends true ? keyof TLocaleSet[TSupportedLocales[number]][TSheetTitle] : string, TValues extends $TParams
|
|
12
|
+
dynamic: <TMessageId extends TTypeSafe extends true ? keyof TLocaleSet[TSupportedLocales[number]][TSheetTitle] : string, TValues extends $TParams[0], TOpts extends $TParams[1], TDescriptor extends $TParams[2]>(id: string, values?: TValues, opts?: TOpts, _descriptor?: TDescriptor) => TTypeSafe extends true ? string : any;
|
|
13
|
+
promise: <TMessageId extends TTypeSafe extends true ? keyof TLocaleSet[TSupportedLocales[number]][TSheetTitle] : string, TValues extends $TParams[0], TOpts extends $TParams[1], TDescriptor extends $TParams[2]>(id: TMessageId, values?: TValues, opts?: TOpts, _descriptor?: TDescriptor) => TTypeSafe extends true ? Promise<TMessageId> : any;
|
|
13
14
|
};
|
|
14
15
|
};
|
|
15
16
|
|
|
16
|
-
type UseIntlParams<D = MessageDescriptor> = Parameters<IntlShape['$t']> extends [D, ...infer R] ? [...R, Omit<D, 'id'>] : never;
|
|
17
|
-
type $TParams = Partial<UseIntlParams>;
|
|
18
17
|
type UseTranslationReturn<TSupportedLocales extends readonly string[], TLocaleSet extends Record<TSupportedLocales[number], Record<string, any>>, TTypeSafe extends boolean, TSheetTitle extends TTypeSafe extends true ? keyof TLocaleSet[TSupportedLocales[number]] : string> = {
|
|
19
18
|
t: <TMessageId extends TTypeSafe extends true ? keyof TLocaleSet[TSupportedLocales[number]][TSheetTitle] : string, TValues extends $TParams[0], TOpts extends $TParams[1], TDescriptor extends $TParams[2]>(id: TMessageId, values?: TValues, opts?: TOpts, _descriptor?: TDescriptor) => TTypeSafe extends true ? TMessageId : any;
|
|
20
19
|
} & {
|
package/dist/index.js
CHANGED
|
@@ -55,21 +55,37 @@ function IntlProvider({
|
|
|
55
55
|
currentLocale,
|
|
56
56
|
children
|
|
57
57
|
}) {
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
const { locale } = useIntlLocale({ i18nStore, currentLocale });
|
|
59
|
+
const onIntlError = (err) => {
|
|
60
|
+
const typeSafe = i18nStore.typeSafe;
|
|
61
|
+
if (typeSafe) {
|
|
62
|
+
console.error(err);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
64
65
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
65
66
|
import_react_intl.IntlProvider,
|
|
66
67
|
{
|
|
67
68
|
locale,
|
|
68
69
|
messages: i18nStore == null ? void 0 : i18nStore.localeSet[locale],
|
|
70
|
+
onError: onIntlError,
|
|
69
71
|
children
|
|
70
72
|
}
|
|
71
73
|
);
|
|
72
74
|
}
|
|
75
|
+
function useIntlLocale({
|
|
76
|
+
i18nStore,
|
|
77
|
+
currentLocale
|
|
78
|
+
}) {
|
|
79
|
+
var _a;
|
|
80
|
+
const locale = (_a = currentLocale != null ? currentLocale : detectClientLanguage(i18nStore)) != null ? _a : i18nStore.defaultLocale;
|
|
81
|
+
i18nStore.setCurrentLocale(locale);
|
|
82
|
+
(0, import_react.useEffect)(() => {
|
|
83
|
+
i18nStore.setCurrentLocale(locale);
|
|
84
|
+
}, [locale]);
|
|
85
|
+
return {
|
|
86
|
+
locale
|
|
87
|
+
};
|
|
88
|
+
}
|
|
73
89
|
function detectClientLanguage(i18nStore) {
|
|
74
90
|
const { defaultLocale, supportedLocales } = i18nStore;
|
|
75
91
|
if (typeof navigator !== "undefined" && (navigator == null ? void 0 : navigator.languages)) {
|
|
@@ -116,7 +132,9 @@ var IntlInstanceCache = class _IntlInstanceCache {
|
|
|
116
132
|
this.createServerIntlInstance = (sheetTitle, i18nStore) => {
|
|
117
133
|
const currentLocale = i18nStore.getCurrentLocale();
|
|
118
134
|
const targetMessages = i18nStore.getTargetMessages(sheetTitle);
|
|
119
|
-
if (!i18nStore || !currentLocale)
|
|
135
|
+
if (!i18nStore || !currentLocale) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
120
138
|
const newIntl = (0, import_react_intl2.createIntl)(
|
|
121
139
|
{ locale: currentLocale, messages: targetMessages },
|
|
122
140
|
intlCache
|
|
@@ -144,6 +162,46 @@ var IntlInstanceCache = class _IntlInstanceCache {
|
|
|
144
162
|
};
|
|
145
163
|
var intlInstanceCache = IntlInstanceCache.init();
|
|
146
164
|
|
|
165
|
+
// src/Service/TranslationService.ts
|
|
166
|
+
var TranslationService = class {
|
|
167
|
+
constructor(intlInstance) {
|
|
168
|
+
this.intlInstance = intlInstance;
|
|
169
|
+
}
|
|
170
|
+
translate(id, values, opts, _descriptor) {
|
|
171
|
+
const descriptor = this.createDescriptor(id, _descriptor);
|
|
172
|
+
const targetTranslation = this.findTargetTranslation(id, {
|
|
173
|
+
descriptor,
|
|
174
|
+
values,
|
|
175
|
+
opts
|
|
176
|
+
});
|
|
177
|
+
return targetTranslation;
|
|
178
|
+
}
|
|
179
|
+
/** helpers */
|
|
180
|
+
createDescriptor(id, _descriptor) {
|
|
181
|
+
var _a;
|
|
182
|
+
return __spreadProps(__spreadValues({}, _descriptor != null ? _descriptor : {}), {
|
|
183
|
+
id,
|
|
184
|
+
defaultMessage: (_a = _descriptor == null ? void 0 : _descriptor.defaultMessage) != null ? _a : id
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
findTargetTranslation(id, $tParams) {
|
|
188
|
+
var _a, _b, _c, _d, _e;
|
|
189
|
+
const targetTranslation = (_b = (_a = this == null ? void 0 : this.intlInstance) == null ? void 0 : _a.messages) == null ? void 0 : _b[id];
|
|
190
|
+
if (typeof targetTranslation === "string" && targetTranslation.trim() === "") {
|
|
191
|
+
return "";
|
|
192
|
+
}
|
|
193
|
+
if (!$tParams || !($tParams == null ? void 0 : $tParams.descriptor)) {
|
|
194
|
+
return "";
|
|
195
|
+
}
|
|
196
|
+
return (_e = (_d = (_c = this.intlInstance) == null ? void 0 : _c.$t) == null ? void 0 : _d.call(
|
|
197
|
+
_c,
|
|
198
|
+
$tParams.descriptor,
|
|
199
|
+
$tParams.values,
|
|
200
|
+
$tParams.opts
|
|
201
|
+
)) != null ? _e : "";
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
|
|
147
205
|
// src/useTranslation.ts
|
|
148
206
|
function useTranslation({
|
|
149
207
|
sheetTitle,
|
|
@@ -154,20 +212,12 @@ function useTranslation({
|
|
|
154
212
|
i18nStore
|
|
155
213
|
);
|
|
156
214
|
const t = (id, values, opts, _descriptor) => {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
id,
|
|
160
|
-
defaultMessage: (_a = _descriptor == null ? void 0 : _descriptor.defaultMessage) != null ? _a : id
|
|
161
|
-
});
|
|
162
|
-
return (_d = (_c = (_b = intlInstance == null ? void 0 : intlInstance.$t) == null ? void 0 : _b.call(intlInstance, descriptor, values, opts)) != null ? _c : id) != null ? _d : "";
|
|
215
|
+
const translationService = new TranslationService(intlInstance);
|
|
216
|
+
return translationService.translate(id, values, opts, _descriptor);
|
|
163
217
|
};
|
|
164
218
|
t.dynamic = (id, values, opts, _descriptor) => {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
id,
|
|
168
|
-
defaultMessage: (_a = _descriptor == null ? void 0 : _descriptor.defaultMessage) != null ? _a : id
|
|
169
|
-
});
|
|
170
|
-
return (_d = (_c = (_b = intlInstance == null ? void 0 : intlInstance.$t) == null ? void 0 : _b.call(intlInstance, descriptor, values, opts)) != null ? _c : id) != null ? _d : "";
|
|
219
|
+
const translationService = new TranslationService(intlInstance);
|
|
220
|
+
return translationService.translate(id, values, opts, _descriptor);
|
|
171
221
|
};
|
|
172
222
|
return { t };
|
|
173
223
|
}
|
|
@@ -185,37 +235,24 @@ function getTranslation({
|
|
|
185
235
|
i18nStore
|
|
186
236
|
}) {
|
|
187
237
|
const t = (id, values, opts, _descriptor) => {
|
|
188
|
-
var _a, _b, _c, _d;
|
|
189
|
-
const descriptor = __spreadProps(__spreadValues({}, _descriptor != null ? _descriptor : {}), {
|
|
190
|
-
id,
|
|
191
|
-
defaultMessage: (_a = _descriptor == null ? void 0 : _descriptor.defaultMessage) != null ? _a : id
|
|
192
|
-
});
|
|
193
238
|
const intlInstance = intlInstanceCache.getCachedIntlInstance(
|
|
194
239
|
sheetTitle,
|
|
195
240
|
i18nStore,
|
|
196
241
|
"server"
|
|
197
242
|
);
|
|
198
|
-
|
|
243
|
+
const translationService = new TranslationService(intlInstance);
|
|
244
|
+
return translationService.translate(id, values, opts, _descriptor);
|
|
199
245
|
};
|
|
200
246
|
t.dynamic = (id, values, opts, _descriptor) => {
|
|
201
|
-
var _a, _b, _c, _d;
|
|
202
|
-
const descriptor = __spreadProps(__spreadValues({}, _descriptor != null ? _descriptor : {}), {
|
|
203
|
-
id,
|
|
204
|
-
defaultMessage: (_a = _descriptor == null ? void 0 : _descriptor.defaultMessage) != null ? _a : id
|
|
205
|
-
});
|
|
206
247
|
const intlInstance = intlInstanceCache.getCachedIntlInstance(
|
|
207
248
|
sheetTitle,
|
|
208
249
|
i18nStore,
|
|
209
250
|
"server"
|
|
210
251
|
);
|
|
211
|
-
|
|
252
|
+
const translationService = new TranslationService(intlInstance);
|
|
253
|
+
return translationService.translate(id, values, opts, _descriptor);
|
|
212
254
|
};
|
|
213
255
|
t.promise = (id, values, opts, _descriptor) => {
|
|
214
|
-
var _a;
|
|
215
|
-
const descriptor = __spreadProps(__spreadValues({}, _descriptor != null ? _descriptor : {}), {
|
|
216
|
-
id,
|
|
217
|
-
defaultMessage: (_a = _descriptor == null ? void 0 : _descriptor.defaultMessage) != null ? _a : id
|
|
218
|
-
});
|
|
219
256
|
const intlInitPromise = new Promise((resolve) => {
|
|
220
257
|
setTimeout(() => {
|
|
221
258
|
const intlInstance = intlInstanceCache.getCachedIntlInstance(
|
|
@@ -228,27 +265,11 @@ function getTranslation({
|
|
|
228
265
|
});
|
|
229
266
|
return new Promise((resolve) => {
|
|
230
267
|
intlInitPromise.then((intlInstance) => {
|
|
231
|
-
|
|
232
|
-
resolve(
|
|
268
|
+
const translationService = new TranslationService(intlInstance);
|
|
269
|
+
resolve(translationService.translate(id, values, opts, _descriptor));
|
|
233
270
|
});
|
|
234
271
|
});
|
|
235
272
|
};
|
|
236
|
-
t.lazy = (id, values, opts, _descriptor) => {
|
|
237
|
-
var _a;
|
|
238
|
-
const descriptor = __spreadProps(__spreadValues({}, _descriptor != null ? _descriptor : {}), {
|
|
239
|
-
id,
|
|
240
|
-
defaultMessage: (_a = _descriptor == null ? void 0 : _descriptor.defaultMessage) != null ? _a : id
|
|
241
|
-
});
|
|
242
|
-
const intlInstance = intlInstanceCache.getCachedIntlInstance(
|
|
243
|
-
sheetTitle,
|
|
244
|
-
i18nStore,
|
|
245
|
-
"server"
|
|
246
|
-
);
|
|
247
|
-
return () => {
|
|
248
|
-
var _a2, _b, _c;
|
|
249
|
-
return (_c = (_b = (_a2 = intlInstance == null ? void 0 : intlInstance.$t) == null ? void 0 : _a2.call(intlInstance, descriptor, values, opts)) != null ? _b : id) != null ? _c : "";
|
|
250
|
-
};
|
|
251
|
-
};
|
|
252
273
|
return { t };
|
|
253
274
|
}
|
|
254
275
|
|
package/dist/index.mjs
CHANGED
|
@@ -32,21 +32,37 @@ function IntlProvider({
|
|
|
32
32
|
currentLocale,
|
|
33
33
|
children
|
|
34
34
|
}) {
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
const { locale } = useIntlLocale({ i18nStore, currentLocale });
|
|
36
|
+
const onIntlError = (err) => {
|
|
37
|
+
const typeSafe = i18nStore.typeSafe;
|
|
38
|
+
if (typeSafe) {
|
|
39
|
+
console.error(err);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
41
42
|
return /* @__PURE__ */ jsx(
|
|
42
43
|
ReactIntlProvider,
|
|
43
44
|
{
|
|
44
45
|
locale,
|
|
45
46
|
messages: i18nStore == null ? void 0 : i18nStore.localeSet[locale],
|
|
47
|
+
onError: onIntlError,
|
|
46
48
|
children
|
|
47
49
|
}
|
|
48
50
|
);
|
|
49
51
|
}
|
|
52
|
+
function useIntlLocale({
|
|
53
|
+
i18nStore,
|
|
54
|
+
currentLocale
|
|
55
|
+
}) {
|
|
56
|
+
var _a;
|
|
57
|
+
const locale = (_a = currentLocale != null ? currentLocale : detectClientLanguage(i18nStore)) != null ? _a : i18nStore.defaultLocale;
|
|
58
|
+
i18nStore.setCurrentLocale(locale);
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
i18nStore.setCurrentLocale(locale);
|
|
61
|
+
}, [locale]);
|
|
62
|
+
return {
|
|
63
|
+
locale
|
|
64
|
+
};
|
|
65
|
+
}
|
|
50
66
|
function detectClientLanguage(i18nStore) {
|
|
51
67
|
const { defaultLocale, supportedLocales } = i18nStore;
|
|
52
68
|
if (typeof navigator !== "undefined" && (navigator == null ? void 0 : navigator.languages)) {
|
|
@@ -93,7 +109,9 @@ var IntlInstanceCache = class _IntlInstanceCache {
|
|
|
93
109
|
this.createServerIntlInstance = (sheetTitle, i18nStore) => {
|
|
94
110
|
const currentLocale = i18nStore.getCurrentLocale();
|
|
95
111
|
const targetMessages = i18nStore.getTargetMessages(sheetTitle);
|
|
96
|
-
if (!i18nStore || !currentLocale)
|
|
112
|
+
if (!i18nStore || !currentLocale) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
97
115
|
const newIntl = createIntl(
|
|
98
116
|
{ locale: currentLocale, messages: targetMessages },
|
|
99
117
|
intlCache
|
|
@@ -121,6 +139,46 @@ var IntlInstanceCache = class _IntlInstanceCache {
|
|
|
121
139
|
};
|
|
122
140
|
var intlInstanceCache = IntlInstanceCache.init();
|
|
123
141
|
|
|
142
|
+
// src/Service/TranslationService.ts
|
|
143
|
+
var TranslationService = class {
|
|
144
|
+
constructor(intlInstance) {
|
|
145
|
+
this.intlInstance = intlInstance;
|
|
146
|
+
}
|
|
147
|
+
translate(id, values, opts, _descriptor) {
|
|
148
|
+
const descriptor = this.createDescriptor(id, _descriptor);
|
|
149
|
+
const targetTranslation = this.findTargetTranslation(id, {
|
|
150
|
+
descriptor,
|
|
151
|
+
values,
|
|
152
|
+
opts
|
|
153
|
+
});
|
|
154
|
+
return targetTranslation;
|
|
155
|
+
}
|
|
156
|
+
/** helpers */
|
|
157
|
+
createDescriptor(id, _descriptor) {
|
|
158
|
+
var _a;
|
|
159
|
+
return __spreadProps(__spreadValues({}, _descriptor != null ? _descriptor : {}), {
|
|
160
|
+
id,
|
|
161
|
+
defaultMessage: (_a = _descriptor == null ? void 0 : _descriptor.defaultMessage) != null ? _a : id
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
findTargetTranslation(id, $tParams) {
|
|
165
|
+
var _a, _b, _c, _d, _e;
|
|
166
|
+
const targetTranslation = (_b = (_a = this == null ? void 0 : this.intlInstance) == null ? void 0 : _a.messages) == null ? void 0 : _b[id];
|
|
167
|
+
if (typeof targetTranslation === "string" && targetTranslation.trim() === "") {
|
|
168
|
+
return "";
|
|
169
|
+
}
|
|
170
|
+
if (!$tParams || !($tParams == null ? void 0 : $tParams.descriptor)) {
|
|
171
|
+
return "";
|
|
172
|
+
}
|
|
173
|
+
return (_e = (_d = (_c = this.intlInstance) == null ? void 0 : _c.$t) == null ? void 0 : _d.call(
|
|
174
|
+
_c,
|
|
175
|
+
$tParams.descriptor,
|
|
176
|
+
$tParams.values,
|
|
177
|
+
$tParams.opts
|
|
178
|
+
)) != null ? _e : "";
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
|
|
124
182
|
// src/useTranslation.ts
|
|
125
183
|
function useTranslation({
|
|
126
184
|
sheetTitle,
|
|
@@ -131,20 +189,12 @@ function useTranslation({
|
|
|
131
189
|
i18nStore
|
|
132
190
|
);
|
|
133
191
|
const t = (id, values, opts, _descriptor) => {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
id,
|
|
137
|
-
defaultMessage: (_a = _descriptor == null ? void 0 : _descriptor.defaultMessage) != null ? _a : id
|
|
138
|
-
});
|
|
139
|
-
return (_d = (_c = (_b = intlInstance == null ? void 0 : intlInstance.$t) == null ? void 0 : _b.call(intlInstance, descriptor, values, opts)) != null ? _c : id) != null ? _d : "";
|
|
192
|
+
const translationService = new TranslationService(intlInstance);
|
|
193
|
+
return translationService.translate(id, values, opts, _descriptor);
|
|
140
194
|
};
|
|
141
195
|
t.dynamic = (id, values, opts, _descriptor) => {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
id,
|
|
145
|
-
defaultMessage: (_a = _descriptor == null ? void 0 : _descriptor.defaultMessage) != null ? _a : id
|
|
146
|
-
});
|
|
147
|
-
return (_d = (_c = (_b = intlInstance == null ? void 0 : intlInstance.$t) == null ? void 0 : _b.call(intlInstance, descriptor, values, opts)) != null ? _c : id) != null ? _d : "";
|
|
196
|
+
const translationService = new TranslationService(intlInstance);
|
|
197
|
+
return translationService.translate(id, values, opts, _descriptor);
|
|
148
198
|
};
|
|
149
199
|
return { t };
|
|
150
200
|
}
|
|
@@ -162,37 +212,24 @@ function getTranslation({
|
|
|
162
212
|
i18nStore
|
|
163
213
|
}) {
|
|
164
214
|
const t = (id, values, opts, _descriptor) => {
|
|
165
|
-
var _a, _b, _c, _d;
|
|
166
|
-
const descriptor = __spreadProps(__spreadValues({}, _descriptor != null ? _descriptor : {}), {
|
|
167
|
-
id,
|
|
168
|
-
defaultMessage: (_a = _descriptor == null ? void 0 : _descriptor.defaultMessage) != null ? _a : id
|
|
169
|
-
});
|
|
170
215
|
const intlInstance = intlInstanceCache.getCachedIntlInstance(
|
|
171
216
|
sheetTitle,
|
|
172
217
|
i18nStore,
|
|
173
218
|
"server"
|
|
174
219
|
);
|
|
175
|
-
|
|
220
|
+
const translationService = new TranslationService(intlInstance);
|
|
221
|
+
return translationService.translate(id, values, opts, _descriptor);
|
|
176
222
|
};
|
|
177
223
|
t.dynamic = (id, values, opts, _descriptor) => {
|
|
178
|
-
var _a, _b, _c, _d;
|
|
179
|
-
const descriptor = __spreadProps(__spreadValues({}, _descriptor != null ? _descriptor : {}), {
|
|
180
|
-
id,
|
|
181
|
-
defaultMessage: (_a = _descriptor == null ? void 0 : _descriptor.defaultMessage) != null ? _a : id
|
|
182
|
-
});
|
|
183
224
|
const intlInstance = intlInstanceCache.getCachedIntlInstance(
|
|
184
225
|
sheetTitle,
|
|
185
226
|
i18nStore,
|
|
186
227
|
"server"
|
|
187
228
|
);
|
|
188
|
-
|
|
229
|
+
const translationService = new TranslationService(intlInstance);
|
|
230
|
+
return translationService.translate(id, values, opts, _descriptor);
|
|
189
231
|
};
|
|
190
232
|
t.promise = (id, values, opts, _descriptor) => {
|
|
191
|
-
var _a;
|
|
192
|
-
const descriptor = __spreadProps(__spreadValues({}, _descriptor != null ? _descriptor : {}), {
|
|
193
|
-
id,
|
|
194
|
-
defaultMessage: (_a = _descriptor == null ? void 0 : _descriptor.defaultMessage) != null ? _a : id
|
|
195
|
-
});
|
|
196
233
|
const intlInitPromise = new Promise((resolve) => {
|
|
197
234
|
setTimeout(() => {
|
|
198
235
|
const intlInstance = intlInstanceCache.getCachedIntlInstance(
|
|
@@ -205,27 +242,11 @@ function getTranslation({
|
|
|
205
242
|
});
|
|
206
243
|
return new Promise((resolve) => {
|
|
207
244
|
intlInitPromise.then((intlInstance) => {
|
|
208
|
-
|
|
209
|
-
resolve(
|
|
245
|
+
const translationService = new TranslationService(intlInstance);
|
|
246
|
+
resolve(translationService.translate(id, values, opts, _descriptor));
|
|
210
247
|
});
|
|
211
248
|
});
|
|
212
249
|
};
|
|
213
|
-
t.lazy = (id, values, opts, _descriptor) => {
|
|
214
|
-
var _a;
|
|
215
|
-
const descriptor = __spreadProps(__spreadValues({}, _descriptor != null ? _descriptor : {}), {
|
|
216
|
-
id,
|
|
217
|
-
defaultMessage: (_a = _descriptor == null ? void 0 : _descriptor.defaultMessage) != null ? _a : id
|
|
218
|
-
});
|
|
219
|
-
const intlInstance = intlInstanceCache.getCachedIntlInstance(
|
|
220
|
-
sheetTitle,
|
|
221
|
-
i18nStore,
|
|
222
|
-
"server"
|
|
223
|
-
);
|
|
224
|
-
return () => {
|
|
225
|
-
var _a2, _b, _c;
|
|
226
|
-
return (_c = (_b = (_a2 = intlInstance == null ? void 0 : intlInstance.$t) == null ? void 0 : _a2.call(intlInstance, descriptor, values, opts)) != null ? _b : id) != null ? _c : "";
|
|
227
|
-
};
|
|
228
|
-
};
|
|
229
250
|
return { t };
|
|
230
251
|
}
|
|
231
252
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sheet-i18n/react-client",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "a client package for react modules used by sheet-i18n",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -27,14 +27,14 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"react": "^18.2.0",
|
|
29
29
|
"react-intl": "^7.0.4",
|
|
30
|
-
"@sheet-i18n/errors": "1.3.
|
|
31
|
-
"@sheet-i18n/shared-utils": "1.3.
|
|
32
|
-
"@sheet-i18n/react-core": "1.0.
|
|
30
|
+
"@sheet-i18n/errors": "1.3.8",
|
|
31
|
+
"@sheet-i18n/shared-utils": "1.3.8",
|
|
32
|
+
"@sheet-i18n/react-core": "1.0.6"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/react": "^19.0.2",
|
|
36
36
|
"@types/react-dom": "^19.0.2",
|
|
37
|
-
"@sheet-i18n/typescript-config": "1.3.
|
|
37
|
+
"@sheet-i18n/typescript-config": "1.3.8"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "tsup",
|