react-native-i18njs 0.0.2 → 1.0.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/LICENSE +15 -0
- package/README.md +74 -8
- package/dist/index.d.mts +58 -74
- package/dist/index.d.ts +58 -74
- package/dist/index.js +1 -536
- package/dist/index.mjs +1 -497
- package/package.json +13 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-present, wangws
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
CHANGED
|
@@ -4,21 +4,33 @@
|
|
|
4
4
|
[](https://www.npmjs.com/package/react-native-i18njs)
|
|
5
5
|
[](https://reactnative.dev)
|
|
6
6
|
[](https://www.typescriptlang.org)
|
|
7
|
+
[](https://www.npmjs.com/package/react-native-i18njs)
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
一个**极致轻量**、类型安全、零心智负担的 React Native 国际化解决方案。
|
|
10
|
+
构建产物经 minify + gzip 后约 **3.3 KB**,对包体积几乎无感。
|
|
9
11
|
|
|
10
|
-
专为 React Native
|
|
12
|
+
专为 React Native 设计,集成了最佳实践,解决繁琐配置、类型缺失、复杂 API 以及系统语言跟随等问题。
|
|
11
13
|
|
|
12
14
|
## ✨ 特性
|
|
13
15
|
|
|
14
|
-
-
|
|
16
|
+
- 📦 **极小体积**:ESM 构建 gzip 约 3.3 KB,CJS 约 3.5 KB;源码极致压缩,无冗余依赖。
|
|
17
|
+
- ✨ **零配置启动**:内置智能默认值,安装即用。
|
|
15
18
|
- 🛡️ **极致类型安全**:完全 TypeScript 编写,提供从 Key 到插值参数的完整类型推导。
|
|
16
19
|
- 📱 **自动跟随系统**:基于 `react-native-localize`,自动检测并响应设备语言变更。
|
|
17
20
|
- ⚡ **高性能**:基于 `i18n-js` 核心,轻量高效,无多余运行时开销。
|
|
18
|
-
- 🔌 **灵活 API**:同时支持 Hook (`useI18n`)、高阶组件 (`
|
|
21
|
+
- 🔌 **灵活 API**:同时支持 Hook (`useI18n`)、高阶组件 (`withI18n`) 和全局函数 (`t`)。
|
|
19
22
|
- 📝 **富文本支持**:`Trans` 组件轻松处理嵌套样式和组件插值。
|
|
20
23
|
- 🌍 **格式化内置**:开箱即用的数字、货币、日期格式化支持。
|
|
21
24
|
|
|
25
|
+
## 📦 体积说明 (Bundle Size)
|
|
26
|
+
|
|
27
|
+
| 格式 | 未压缩 | gzip |
|
|
28
|
+
|------|--------|------|
|
|
29
|
+
| ESM (`.mjs`) | ~8.1 KB | **~3.3 KB** |
|
|
30
|
+
| CJS (`.js`) | ~8.9 KB | **~3.5 KB** |
|
|
31
|
+
|
|
32
|
+
以上为单入口打包、开启 minify 后的体积;实际打进业务的增量取决于打包工具的 tree-shaking。推荐使用 ESM 以获得更优体积与 gzip 表现。
|
|
33
|
+
|
|
22
34
|
## 📦 安装
|
|
23
35
|
|
|
24
36
|
```bash
|
|
@@ -129,13 +141,13 @@ const message = t('errors.network_timeout');
|
|
|
129
141
|
|
|
130
142
|
#### 进阶:监听语言变化
|
|
131
143
|
|
|
132
|
-
|
|
144
|
+
如果你需要在组件外监听语言变更(例如同步更新全局状态),可以使用顶层 `subscribe` 函数:
|
|
133
145
|
|
|
134
146
|
```ts
|
|
135
|
-
import
|
|
147
|
+
import { subscribe } from 'react-native-i18njs';
|
|
136
148
|
|
|
137
149
|
// 订阅语言变更
|
|
138
|
-
const unsubscribe =
|
|
150
|
+
const unsubscribe = subscribe((locale) => {
|
|
139
151
|
console.log('Language changed to:', locale);
|
|
140
152
|
// 更新 API 默认 Header 或其他全局状态
|
|
141
153
|
});
|
|
@@ -144,6 +156,27 @@ const unsubscribe = i18n.subscribe((locale) => {
|
|
|
144
156
|
// unsubscribe();
|
|
145
157
|
```
|
|
146
158
|
|
|
159
|
+
#### 进阶:重置为跟随系统
|
|
160
|
+
|
|
161
|
+
用户手动调用 `setLocale` 后会锁定语言,不再自动跟随系统。如果需要恢复跟随系统语言:
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
import { resetToSystem } from 'react-native-i18njs';
|
|
165
|
+
|
|
166
|
+
// 撤销用户锁定,重新跟随系统语言
|
|
167
|
+
resetToSystem();
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
#### 进阶:RTL 检测
|
|
171
|
+
|
|
172
|
+
```ts
|
|
173
|
+
import { isRTL } from 'react-native-i18njs';
|
|
174
|
+
|
|
175
|
+
if (isRTL()) {
|
|
176
|
+
// 当前为从右到左语言(如阿拉伯语、希伯来语)
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
147
180
|
#### 实战示例:Axios 拦截器
|
|
148
181
|
|
|
149
182
|
```ts
|
|
@@ -192,7 +225,7 @@ async function loadFrench() {
|
|
|
192
225
|
|
|
193
226
|
### 4. 格式化工具
|
|
194
227
|
|
|
195
|
-
利用 `Intl`
|
|
228
|
+
利用 `Intl` 标准进行格式化,在组件中通过 Hook 使用:
|
|
196
229
|
|
|
197
230
|
```ts
|
|
198
231
|
const { formatNumber, formatCurrency, formatDate } = useI18n();
|
|
@@ -207,6 +240,16 @@ formatCurrency(99.99, 'USD'); // "$99.99"
|
|
|
207
240
|
formatDate(new Date(), { dateStyle: 'full' }); // "Tuesday, October 10, 2023"
|
|
208
241
|
```
|
|
209
242
|
|
|
243
|
+
在非组件环境中,也可以直接使用顶层导出:
|
|
244
|
+
|
|
245
|
+
```ts
|
|
246
|
+
import { formatNumber, formatCurrency, formatDate } from 'react-native-i18njs';
|
|
247
|
+
|
|
248
|
+
formatNumber(1234.56);
|
|
249
|
+
formatCurrency(99.99, 'USD');
|
|
250
|
+
formatDate(new Date());
|
|
251
|
+
```
|
|
252
|
+
|
|
210
253
|
## ⚙️ 配置选项 (I18nOptions)
|
|
211
254
|
|
|
212
255
|
`initI18n` 接受的第二个参数对象:
|
|
@@ -221,8 +264,31 @@ formatDate(new Date(), { dateStyle: 'full' }); // "Tuesday, October 10, 2023"
|
|
|
221
264
|
| `onMissingKey` | `function` | - | 缺失 key 的回调 |
|
|
222
265
|
| `onLocaleChange` | `function` | - | 语言变更回调 |
|
|
223
266
|
|
|
267
|
+
## ✅ 生产就绪 (Production Ready)
|
|
268
|
+
|
|
269
|
+
本库在功能与健壮性上已按生产标准实现,具备:
|
|
270
|
+
|
|
271
|
+
| 能力 | 说明 |
|
|
272
|
+
|------|------|
|
|
273
|
+
| **多场景使用** | 组件内(Hook / HOC)、组件外(全局 `t`、格式化、Redux/拦截器等)统一 API |
|
|
274
|
+
| **插值与复数** | `%{name}` 插值、`one`/`other` 等复数规则(透传 i18n-js),支持 `defaultValue` |
|
|
275
|
+
| **缺失策略** | `missingBehavior`:回退 key / 空串 / 抛错;`onMissingKey` 便于上报与兜底 |
|
|
276
|
+
| **语言链** | 当前 locale 自动降级(如 en-US → en)、自定义 `fallbackLocales`、可函数动态回退 |
|
|
277
|
+
| **系统语言** | 基于 `react-native-localize`,App 回到前台自动同步;`setLocale` 用户锁定、`resetToSystem` 恢复跟随 |
|
|
278
|
+
| **动态文案** | `loadTranslations` 合并新语种/命名空间,`subscribe` 通知 UI 更新 |
|
|
279
|
+
| **RTL** | 按语言/script 检测 RTL,调用 `I18nManager`(需重启生效,属 RN 限制) |
|
|
280
|
+
| **格式化** | 数字/货币/日期使用 `Intl` 并带缓存,无 Intl 环境有降级 |
|
|
281
|
+
| **富文本** | `Trans` 支持标签解析、组件映射、插值内嵌 React 节点 |
|
|
282
|
+
| **类型安全** | `Path<T>`、`useI18n<T>` 提供 key 补全与校验 |
|
|
283
|
+
| **环境兼容** | 无 `Intl` / 无 `react-native-localize` 时 try-catch 降级,不抛错 |
|
|
284
|
+
|
|
285
|
+
使用前请在 App 入口**先调用 `initI18n`**,再使用 `t` / `useI18n` / `Trans` 等。
|
|
286
|
+
|
|
224
287
|
## 🧩 常见问题
|
|
225
288
|
|
|
289
|
+
### 使用前必须先 init 吗?
|
|
290
|
+
是的。在调用 `t`、`useI18n`、`Trans` 等之前,请在应用入口(如 `App.tsx`)执行一次 `initI18n(translations, options)`,否则会使用空翻译表。
|
|
291
|
+
|
|
226
292
|
### TypeScript 类型提示不工作?
|
|
227
293
|
确保你在使用 `useI18n<MyTranslations>()` 时传入了你的翻译类型定义。
|
|
228
294
|
|
package/dist/index.d.mts
CHANGED
|
@@ -2,87 +2,70 @@ import { Scope, TranslateOptions } from 'i18n-js';
|
|
|
2
2
|
import React, { ReactNode } from 'react';
|
|
3
3
|
import { TextProps } from 'react-native';
|
|
4
4
|
|
|
5
|
+
type Translations = Record<string, any>;
|
|
6
|
+
type Listener = (locale: string, change?: {
|
|
7
|
+
type: 'locale' | 'translations';
|
|
8
|
+
version: number;
|
|
9
|
+
}) => void;
|
|
5
10
|
interface I18nOptions {
|
|
6
11
|
defaultLocale?: string;
|
|
7
12
|
enableFallback?: boolean;
|
|
8
13
|
onLocaleChange?: (locale: string) => void;
|
|
9
14
|
fallbackLocales?: string[] | ((locale: string) => string[]);
|
|
10
|
-
/**
|
|
11
|
-
* 是否跟随系统语言变化自动切换。
|
|
12
|
-
* - 默认 true:初始化会使用系统语言;App 回到前台时会再次同步系统语言(直到用户手动 setLocale)。
|
|
13
|
-
* - 设为 false:始终使用 defaultLocale / 手动 setLocale,不再自动同步系统语言。
|
|
14
|
-
*/
|
|
15
15
|
followSystem?: boolean;
|
|
16
16
|
missingBehavior?: 'key' | 'empty' | 'throw';
|
|
17
17
|
onMissingKey?: (key: string, locale: string) => void;
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
subscribe(listener: Listener): () => void;
|
|
37
|
-
isRTL(): boolean;
|
|
38
|
-
ready(): Promise<void>;
|
|
39
|
-
isReady(): boolean;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* 默认的 i18n-js 引擎实现
|
|
43
|
-
*/
|
|
44
|
-
declare class DefaultI18nEngine implements I18nEngine {
|
|
45
|
-
private i18n;
|
|
46
|
-
private listeners;
|
|
47
|
-
private onLocaleChange?;
|
|
48
|
-
private fallbackLocales?;
|
|
49
|
-
private missingBehavior;
|
|
50
|
-
private onMissingKey?;
|
|
51
|
-
private enableFallback;
|
|
52
|
-
private followSystem;
|
|
53
|
-
private localeSource;
|
|
54
|
-
private initialized;
|
|
55
|
-
private version;
|
|
56
|
-
private readyPromise;
|
|
57
|
-
private resolveReady?;
|
|
19
|
+
declare class E {
|
|
20
|
+
private i;
|
|
21
|
+
private ls;
|
|
22
|
+
private cb?;
|
|
23
|
+
private fb?;
|
|
24
|
+
private mb;
|
|
25
|
+
private mk?;
|
|
26
|
+
private ef;
|
|
27
|
+
private fs;
|
|
28
|
+
private sr;
|
|
29
|
+
private ok;
|
|
30
|
+
private v;
|
|
31
|
+
private rp;
|
|
32
|
+
private rr?;
|
|
33
|
+
private nc;
|
|
34
|
+
private dc;
|
|
35
|
+
private lc;
|
|
58
36
|
constructor();
|
|
59
|
-
init(
|
|
60
|
-
loadTranslations(
|
|
37
|
+
init(tr: Translations, o?: I18nOptions): void;
|
|
38
|
+
loadTranslations(tr: Translations): void;
|
|
61
39
|
updateLocale(): void;
|
|
62
|
-
setLocale(
|
|
40
|
+
setLocale(l: string): void;
|
|
63
41
|
getLocale(): string;
|
|
42
|
+
resetToSystem(): void;
|
|
64
43
|
t(scope: Scope, options?: TranslateOptions): string;
|
|
65
|
-
formatNumber(n: number,
|
|
66
|
-
formatCurrency(n: number,
|
|
67
|
-
formatDate(
|
|
68
|
-
subscribe(
|
|
44
|
+
formatNumber(n: number, o?: Intl.NumberFormatOptions): string;
|
|
45
|
+
formatCurrency(n: number, c: string, o?: Intl.NumberFormatOptions): string;
|
|
46
|
+
formatDate(d: Date | number, o?: Intl.DateTimeFormatOptions): string;
|
|
47
|
+
subscribe(l: Listener): () => void;
|
|
69
48
|
isRTL(): boolean;
|
|
70
49
|
ready(): Promise<void>;
|
|
71
50
|
isReady(): boolean;
|
|
72
|
-
private
|
|
73
|
-
private
|
|
74
|
-
private
|
|
75
|
-
private
|
|
76
|
-
private
|
|
77
|
-
private
|
|
78
|
-
private
|
|
79
|
-
private
|
|
80
|
-
private
|
|
81
|
-
private
|
|
82
|
-
private
|
|
51
|
+
private cl;
|
|
52
|
+
private gn;
|
|
53
|
+
private gd;
|
|
54
|
+
private em;
|
|
55
|
+
private ap;
|
|
56
|
+
private hr;
|
|
57
|
+
private ta;
|
|
58
|
+
private dg;
|
|
59
|
+
private gc;
|
|
60
|
+
private ht;
|
|
61
|
+
private nr;
|
|
62
|
+
private nt;
|
|
83
63
|
}
|
|
84
|
-
declare const i18nService:
|
|
64
|
+
declare const i18nService: E;
|
|
85
65
|
|
|
66
|
+
type Path<T> = T extends object ? {
|
|
67
|
+
[K in keyof T]: `${Exclude<K, symbol>}${"" | `.${Path<T[K]>}`}`;
|
|
68
|
+
}[keyof T] : never;
|
|
86
69
|
interface I18nContextType {
|
|
87
70
|
locale: string;
|
|
88
71
|
setLocale: (locale: string) => void;
|
|
@@ -98,12 +81,6 @@ interface I18nProviderProps {
|
|
|
98
81
|
fallback?: ReactNode;
|
|
99
82
|
}
|
|
100
83
|
declare const I18nProvider: React.FC<I18nProviderProps>;
|
|
101
|
-
declare function withI18n<P extends object>(Component: React.ComponentType<P & I18nContextType>): React.FC<Omit<P, keyof I18nContextType>>;
|
|
102
|
-
|
|
103
|
-
type Path<T> = T extends object ? {
|
|
104
|
-
[K in keyof T]: `${Exclude<K, symbol>}${"" | `.${Path<T[K]>}`}`;
|
|
105
|
-
}[keyof T] : never;
|
|
106
|
-
|
|
107
84
|
type TFunction<T> = (scope: T extends Translations ? Path<T> : string, options?: TranslateOptions) => string;
|
|
108
85
|
declare function useI18n<T = Translations>(): {
|
|
109
86
|
t: TFunction<T>;
|
|
@@ -113,6 +90,7 @@ declare function useI18n<T = Translations>(): {
|
|
|
113
90
|
formatCurrency: (n: number, currency: string, options?: Intl.NumberFormatOptions) => string;
|
|
114
91
|
formatDate: (date: Date | number, options?: Intl.DateTimeFormatOptions) => string;
|
|
115
92
|
};
|
|
93
|
+
declare function withI18n<P extends object>(C: React.ComponentType<P & I18nContextType>): React.FC<Omit<P, keyof I18nContextType>>;
|
|
116
94
|
|
|
117
95
|
interface TransProps extends TextProps {
|
|
118
96
|
i18nKey: string;
|
|
@@ -121,12 +99,18 @@ interface TransProps extends TextProps {
|
|
|
121
99
|
}
|
|
122
100
|
declare const Trans: React.FC<TransProps>;
|
|
123
101
|
|
|
124
|
-
declare const initI18n: (
|
|
125
|
-
declare const loadTranslations: (
|
|
126
|
-
declare const setLocale: (
|
|
102
|
+
declare const initI18n: (t: Translations, o?: I18nOptions) => void;
|
|
103
|
+
declare const loadTranslations: (t: Translations) => void;
|
|
104
|
+
declare const setLocale: (l: string) => void;
|
|
127
105
|
declare const getLocale: () => string;
|
|
128
|
-
declare const t: (scope: Scope,
|
|
106
|
+
declare const t: (scope: Scope, o?: TranslateOptions) => string;
|
|
107
|
+
declare const formatNumber: (n: number, o?: Intl.NumberFormatOptions) => string;
|
|
108
|
+
declare const formatCurrency: (n: number, c: string, o?: Intl.NumberFormatOptions) => string;
|
|
109
|
+
declare const formatDate: (d: Date | number, o?: Intl.DateTimeFormatOptions) => string;
|
|
110
|
+
declare const subscribe: (l: Listener) => () => void;
|
|
111
|
+
declare const isRTL: () => boolean;
|
|
112
|
+
declare const resetToSystem: () => void;
|
|
129
113
|
declare const readyI18n: () => Promise<void>;
|
|
130
114
|
declare const isI18nReady: () => boolean;
|
|
131
115
|
|
|
132
|
-
export { I18nContext, type I18nContextType, type I18nOptions, I18nProvider, type I18nProviderProps, type Path, Trans, type Translations, i18nService as default, getLocale, initI18n, isI18nReady, loadTranslations, readyI18n, setLocale, t, useI18n, withI18n };
|
|
116
|
+
export { I18nContext, type I18nContextType, type I18nOptions, I18nProvider, type I18nProviderProps, type Listener, type Path, Trans, type Translations, i18nService as default, formatCurrency, formatDate, formatNumber, getLocale, initI18n, isI18nReady, isRTL, loadTranslations, readyI18n, resetToSystem, setLocale, subscribe, t, useI18n, withI18n };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,87 +2,70 @@ import { Scope, TranslateOptions } from 'i18n-js';
|
|
|
2
2
|
import React, { ReactNode } from 'react';
|
|
3
3
|
import { TextProps } from 'react-native';
|
|
4
4
|
|
|
5
|
+
type Translations = Record<string, any>;
|
|
6
|
+
type Listener = (locale: string, change?: {
|
|
7
|
+
type: 'locale' | 'translations';
|
|
8
|
+
version: number;
|
|
9
|
+
}) => void;
|
|
5
10
|
interface I18nOptions {
|
|
6
11
|
defaultLocale?: string;
|
|
7
12
|
enableFallback?: boolean;
|
|
8
13
|
onLocaleChange?: (locale: string) => void;
|
|
9
14
|
fallbackLocales?: string[] | ((locale: string) => string[]);
|
|
10
|
-
/**
|
|
11
|
-
* 是否跟随系统语言变化自动切换。
|
|
12
|
-
* - 默认 true:初始化会使用系统语言;App 回到前台时会再次同步系统语言(直到用户手动 setLocale)。
|
|
13
|
-
* - 设为 false:始终使用 defaultLocale / 手动 setLocale,不再自动同步系统语言。
|
|
14
|
-
*/
|
|
15
15
|
followSystem?: boolean;
|
|
16
16
|
missingBehavior?: 'key' | 'empty' | 'throw';
|
|
17
17
|
onMissingKey?: (key: string, locale: string) => void;
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
subscribe(listener: Listener): () => void;
|
|
37
|
-
isRTL(): boolean;
|
|
38
|
-
ready(): Promise<void>;
|
|
39
|
-
isReady(): boolean;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* 默认的 i18n-js 引擎实现
|
|
43
|
-
*/
|
|
44
|
-
declare class DefaultI18nEngine implements I18nEngine {
|
|
45
|
-
private i18n;
|
|
46
|
-
private listeners;
|
|
47
|
-
private onLocaleChange?;
|
|
48
|
-
private fallbackLocales?;
|
|
49
|
-
private missingBehavior;
|
|
50
|
-
private onMissingKey?;
|
|
51
|
-
private enableFallback;
|
|
52
|
-
private followSystem;
|
|
53
|
-
private localeSource;
|
|
54
|
-
private initialized;
|
|
55
|
-
private version;
|
|
56
|
-
private readyPromise;
|
|
57
|
-
private resolveReady?;
|
|
19
|
+
declare class E {
|
|
20
|
+
private i;
|
|
21
|
+
private ls;
|
|
22
|
+
private cb?;
|
|
23
|
+
private fb?;
|
|
24
|
+
private mb;
|
|
25
|
+
private mk?;
|
|
26
|
+
private ef;
|
|
27
|
+
private fs;
|
|
28
|
+
private sr;
|
|
29
|
+
private ok;
|
|
30
|
+
private v;
|
|
31
|
+
private rp;
|
|
32
|
+
private rr?;
|
|
33
|
+
private nc;
|
|
34
|
+
private dc;
|
|
35
|
+
private lc;
|
|
58
36
|
constructor();
|
|
59
|
-
init(
|
|
60
|
-
loadTranslations(
|
|
37
|
+
init(tr: Translations, o?: I18nOptions): void;
|
|
38
|
+
loadTranslations(tr: Translations): void;
|
|
61
39
|
updateLocale(): void;
|
|
62
|
-
setLocale(
|
|
40
|
+
setLocale(l: string): void;
|
|
63
41
|
getLocale(): string;
|
|
42
|
+
resetToSystem(): void;
|
|
64
43
|
t(scope: Scope, options?: TranslateOptions): string;
|
|
65
|
-
formatNumber(n: number,
|
|
66
|
-
formatCurrency(n: number,
|
|
67
|
-
formatDate(
|
|
68
|
-
subscribe(
|
|
44
|
+
formatNumber(n: number, o?: Intl.NumberFormatOptions): string;
|
|
45
|
+
formatCurrency(n: number, c: string, o?: Intl.NumberFormatOptions): string;
|
|
46
|
+
formatDate(d: Date | number, o?: Intl.DateTimeFormatOptions): string;
|
|
47
|
+
subscribe(l: Listener): () => void;
|
|
69
48
|
isRTL(): boolean;
|
|
70
49
|
ready(): Promise<void>;
|
|
71
50
|
isReady(): boolean;
|
|
72
|
-
private
|
|
73
|
-
private
|
|
74
|
-
private
|
|
75
|
-
private
|
|
76
|
-
private
|
|
77
|
-
private
|
|
78
|
-
private
|
|
79
|
-
private
|
|
80
|
-
private
|
|
81
|
-
private
|
|
82
|
-
private
|
|
51
|
+
private cl;
|
|
52
|
+
private gn;
|
|
53
|
+
private gd;
|
|
54
|
+
private em;
|
|
55
|
+
private ap;
|
|
56
|
+
private hr;
|
|
57
|
+
private ta;
|
|
58
|
+
private dg;
|
|
59
|
+
private gc;
|
|
60
|
+
private ht;
|
|
61
|
+
private nr;
|
|
62
|
+
private nt;
|
|
83
63
|
}
|
|
84
|
-
declare const i18nService:
|
|
64
|
+
declare const i18nService: E;
|
|
85
65
|
|
|
66
|
+
type Path<T> = T extends object ? {
|
|
67
|
+
[K in keyof T]: `${Exclude<K, symbol>}${"" | `.${Path<T[K]>}`}`;
|
|
68
|
+
}[keyof T] : never;
|
|
86
69
|
interface I18nContextType {
|
|
87
70
|
locale: string;
|
|
88
71
|
setLocale: (locale: string) => void;
|
|
@@ -98,12 +81,6 @@ interface I18nProviderProps {
|
|
|
98
81
|
fallback?: ReactNode;
|
|
99
82
|
}
|
|
100
83
|
declare const I18nProvider: React.FC<I18nProviderProps>;
|
|
101
|
-
declare function withI18n<P extends object>(Component: React.ComponentType<P & I18nContextType>): React.FC<Omit<P, keyof I18nContextType>>;
|
|
102
|
-
|
|
103
|
-
type Path<T> = T extends object ? {
|
|
104
|
-
[K in keyof T]: `${Exclude<K, symbol>}${"" | `.${Path<T[K]>}`}`;
|
|
105
|
-
}[keyof T] : never;
|
|
106
|
-
|
|
107
84
|
type TFunction<T> = (scope: T extends Translations ? Path<T> : string, options?: TranslateOptions) => string;
|
|
108
85
|
declare function useI18n<T = Translations>(): {
|
|
109
86
|
t: TFunction<T>;
|
|
@@ -113,6 +90,7 @@ declare function useI18n<T = Translations>(): {
|
|
|
113
90
|
formatCurrency: (n: number, currency: string, options?: Intl.NumberFormatOptions) => string;
|
|
114
91
|
formatDate: (date: Date | number, options?: Intl.DateTimeFormatOptions) => string;
|
|
115
92
|
};
|
|
93
|
+
declare function withI18n<P extends object>(C: React.ComponentType<P & I18nContextType>): React.FC<Omit<P, keyof I18nContextType>>;
|
|
116
94
|
|
|
117
95
|
interface TransProps extends TextProps {
|
|
118
96
|
i18nKey: string;
|
|
@@ -121,12 +99,18 @@ interface TransProps extends TextProps {
|
|
|
121
99
|
}
|
|
122
100
|
declare const Trans: React.FC<TransProps>;
|
|
123
101
|
|
|
124
|
-
declare const initI18n: (
|
|
125
|
-
declare const loadTranslations: (
|
|
126
|
-
declare const setLocale: (
|
|
102
|
+
declare const initI18n: (t: Translations, o?: I18nOptions) => void;
|
|
103
|
+
declare const loadTranslations: (t: Translations) => void;
|
|
104
|
+
declare const setLocale: (l: string) => void;
|
|
127
105
|
declare const getLocale: () => string;
|
|
128
|
-
declare const t: (scope: Scope,
|
|
106
|
+
declare const t: (scope: Scope, o?: TranslateOptions) => string;
|
|
107
|
+
declare const formatNumber: (n: number, o?: Intl.NumberFormatOptions) => string;
|
|
108
|
+
declare const formatCurrency: (n: number, c: string, o?: Intl.NumberFormatOptions) => string;
|
|
109
|
+
declare const formatDate: (d: Date | number, o?: Intl.DateTimeFormatOptions) => string;
|
|
110
|
+
declare const subscribe: (l: Listener) => () => void;
|
|
111
|
+
declare const isRTL: () => boolean;
|
|
112
|
+
declare const resetToSystem: () => void;
|
|
129
113
|
declare const readyI18n: () => Promise<void>;
|
|
130
114
|
declare const isI18nReady: () => boolean;
|
|
131
115
|
|
|
132
|
-
export { I18nContext, type I18nContextType, type I18nOptions, I18nProvider, type I18nProviderProps, type Path, Trans, type Translations, i18nService as default, getLocale, initI18n, isI18nReady, loadTranslations, readyI18n, setLocale, t, useI18n, withI18n };
|
|
116
|
+
export { I18nContext, type I18nContextType, type I18nOptions, I18nProvider, type I18nProviderProps, type Listener, type Path, Trans, type Translations, i18nService as default, formatCurrency, formatDate, formatNumber, getLocale, initI18n, isI18nReady, isRTL, loadTranslations, readyI18n, resetToSystem, setLocale, subscribe, t, useI18n, withI18n };
|