react-native-i18njs 0.0.1-beta → 0.0.1

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/README.md CHANGED
@@ -1,39 +1,247 @@
1
1
  # react-native-i18njs
2
2
 
3
- #### 介绍
4
- {**以下是 Gitee 平台说明,您可以替换此简介**
5
- Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台
6
- 无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)}
3
+ 一个轻量级、类型安全、零心智负担的 React Native 国际化解决方案。
7
4
 
8
- #### 软件架构
9
- 软件架构说明
5
+ ## 特性
10
6
 
7
+ - 🚀 **开箱即用**:专为 React Native 设计,API 简单直观。
8
+ - 📦 **自动语言检测**:基于 `react-native-localize` 自动匹配设备语言。
9
+ - 🔄 **自动重渲染**:语言切换时,UI 自动更新。
10
+ - 🛡️ **TypeScript 支持**:完全使用 TypeScript 编写,提供完整的类型提示。
11
+ - 🧩 **基于 `i18n-js`**:轻量封装,默认使用 `i18n-js` 作为翻译引擎。
12
+ - 🔌 **Hooks 支持**:提供 `useI18n` Hook,方便在组件中使用。
13
+ - 📝 **富文本支持**:支持在翻译中嵌入组件。
14
+ - 🔢 **格式化支持**:基于 JS 内置 `Intl` 的数字/货币/日期格式化(可传 options 自定义;环境不支持会自动降级)。
11
15
 
12
- #### 安装教程
16
+ ## 安装
13
17
 
14
- 1. xxxx
15
- 2. xxxx
16
- 3. xxxx
18
+ 首先安装本库及其依赖:
17
19
 
18
- #### 使用说明
20
+ ```bash
21
+ npm install react-native-i18njs i18n-js react-native-localize
22
+ # 或者
23
+ yarn add react-native-i18njs i18n-js react-native-localize
24
+ ```
19
25
 
20
- 1. xxxx
21
- 2. xxxx
22
- 3. xxxx
26
+ > 插值语法说明:本库基于 `i18n-js`,默认使用 `%{name}`(不是 `{{name}}`)。
23
27
 
24
- #### 参与贡献
28
+ ## 上手方式(两种都支持)
25
29
 
26
- 1. Fork 本仓库
27
- 2. 新建 Feat_xxx 分支
28
- 3. 提交代码
29
- 4. 新建 Pull Request
30
+ - **方式 A:不使用 `I18nProvider`(推荐)**:任何地方都能直接 `t()`,没有 React 心智负担;适合工具层/启动阶段/非 UI 代码。
31
+ - **方式 B:使用 `I18nProvider`(可选)**:需要“切换语言后 UI 自动刷新”时再用。
30
32
 
33
+ ## 模块 1:初始化与全局函数(不需要 Provider)
31
34
 
32
- #### 特技
35
+ ### 1) 准备翻译资源
33
36
 
34
- 1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
35
- 2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
36
- 3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
37
- 4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
38
- 5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
39
- 6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
37
+ ```ts
38
+ export const translations = {
39
+ en: { welcome: 'Welcome', hello: 'Hello, %{name}!' },
40
+ zh: { welcome: '欢迎', hello: '你好,%{name}!' },
41
+ };
42
+ ```
43
+
44
+ ### 2) 初始化(只做一次)
45
+
46
+ ```ts
47
+ import { initI18n } from 'react-native-i18njs';
48
+ import { translations } from './locales';
49
+
50
+ initI18n(translations, { defaultLocale: 'en', enableFallback: true });
51
+ ```
52
+
53
+ ### 3) 在任何地方直接使用 `t()`
54
+
55
+ ```ts
56
+ import { t, setLocale, getLocale } from 'react-native-i18njs';
57
+
58
+ setLocale('zh');
59
+ getLocale(); // 'zh'
60
+ t('hello', { name: 'Trae' }); // '你好,Trae!'
61
+ t('missing.key', { defaultValue: '默认文案' });
62
+ ```
63
+
64
+ ### 不用 Provider 的典型场景
65
+
66
+ - 网络层(如 axios 拦截器)拼接错误文案
67
+ - 表单校验/工具函数/Toast 文案
68
+ - Redux/Saga/Store 初始化阶段
69
+ - React 组件之外(比如 navigation 配置、原生桥接回调)
70
+
71
+ > 注意:不用 Provider 时,切换语言不会自动触发页面重渲染;如果你需要 UI 自动刷新,请看“模块 2”。
72
+
73
+ ## 模块 2:React 自动重渲染(I18nProvider + useI18n)
74
+
75
+ ```tsx
76
+ import React from 'react';
77
+ import { Text, Button } from 'react-native';
78
+ import { I18nProvider, useI18n } from 'react-native-i18njs';
79
+
80
+ function Home() {
81
+ const { t, locale, setLocale } = useI18n();
82
+ return (
83
+ <>
84
+ <Text>{t('welcome')}</Text>
85
+ <Text>{t('hello', { name: 'User' })}</Text>
86
+ <Text>{locale}</Text>
87
+ <Button title="EN" onPress={() => setLocale('en')} />
88
+ <Button title="中文" onPress={() => setLocale('zh')} />
89
+ </>
90
+ );
91
+ }
92
+
93
+ export default function App() {
94
+ return (
95
+ <I18nProvider>
96
+ <Home />
97
+ </I18nProvider>
98
+ );
99
+ }
100
+ ```
101
+
102
+ ### `I18nProvider` 参数
103
+
104
+ - `readyGate?: boolean`:为 `true` 时,未 ready 前不渲染 children
105
+ - `fallback?: React.ReactNode`:`readyGate` 期间显示的占位
106
+
107
+ ### `useI18n<T>()`(类型安全 key)
108
+
109
+ ```ts
110
+ type MyTranslations = typeof translations.en;
111
+ const { t } = useI18n<MyTranslations>();
112
+ t('welcome');
113
+ t('home.title');
114
+ ```
115
+
116
+ ## 模块 3:动态加载翻译(loadTranslations)
117
+
118
+ ```ts
119
+ import { loadTranslations } from 'react-native-i18njs';
120
+
121
+ loadTranslations({ fr: { welcome: 'Bonjour' } });
122
+ ```
123
+
124
+ ## 模块 4:富文本(Trans)
125
+
126
+ ```tsx
127
+ import React from 'react';
128
+ import { Text } from 'react-native';
129
+ import { Trans } from 'react-native-i18njs';
130
+
131
+ // translations.en:
132
+ // { description: 'This is <bold>bold</bold> text.', agree: 'I agree to %{terms}' }
133
+
134
+ <Trans i18nKey="description" components={{ bold: <Text style={{ fontWeight: 'bold' }} /> }} />
135
+ <Trans i18nKey="agree" values={{ terms: <Text style={{ fontWeight: 'bold' }}>Terms</Text> }} />
136
+ ```
137
+
138
+ ### `Trans` 参数
139
+
140
+ - `i18nKey: string`
141
+ - `values?: Record<string, any>`:插值值(字符串/数字/ReactElement 都支持)
142
+ - `components?: Record<string, React.ReactNode>`:标签映射(如 `bold/link`)
143
+
144
+ ### `Trans` 能覆盖的场景
145
+
146
+ - 句子内局部加粗/斜体/变色/可点击链接(用 `components` 映射 `<bold></bold>` / `<link></link>`)
147
+ - 插值里插入组件(用 `values` 传 ReactElement,例如把 “Terms” 做成可点击文本)
148
+ - 嵌套标签(例如 `<bold>...<italic>...</italic>...</bold>`)
149
+ - 自闭合标签(例如 `<br/>`),可映射成 `components={{ br: <Text>{'\n'}</Text> }}`
150
+
151
+ ### `Trans` 的边界(不适合的场景)
152
+
153
+ - 不支持标签属性/HTML(例如 `<a href="...">` / `<span style="...">`),需要你把“样式/点击行为”放到 `components` 或 `values` 传入的组件里
154
+ - `components` 目前接收的是“元素”(例如 `<Text />`),不是组件函数(例如 `Text` / `Bold`),因为内部是 `cloneElement`
155
+ - `Trans` 总是返回一个外层 `<Text>`;并且被插入的组件也必须是 `Text` 可渲染的内容(不要把 `<View>` 直接塞进文本里)
156
+ - 不提供 ICU MessageFormat(select/plural/gender)语法;更复杂的语言结构建议拆 key + 用 JS 逻辑组合,或引入 ICU 方案
157
+ - 翻译里如果出现不成对/不匹配的标签,会按纯文本保留(避免静默吞字),建议在翻译侧保持标签成对
158
+
159
+ ## 模块 5:Class 组件(withI18n)
160
+
161
+ ```tsx
162
+ import React from 'react';
163
+ import { Text } from 'react-native';
164
+ import { withI18n } from 'react-native-i18njs';
165
+
166
+ class Screen extends React.PureComponent<{ t: any }> {
167
+ render() {
168
+ return <Text>{this.props.t('welcome')}</Text>;
169
+ }
170
+ }
171
+
172
+ export default withI18n(Screen);
173
+ ```
174
+
175
+ ## 模块 6:初始化就绪(readyI18n / isI18nReady)
176
+
177
+ ```ts
178
+ import { readyI18n, isI18nReady } from 'react-native-i18njs';
179
+
180
+ await readyI18n();
181
+ isI18nReady();
182
+ ```
183
+
184
+ ## 模块 7:数字/货币/日期格式化(formatNumber / formatCurrency / formatDate)
185
+
186
+ `Intl` 是 JavaScript 自带的一套“国际化格式化”能力(浏览器和 Node 都有,React Native 取决于引擎/是否带完整 Intl)。
187
+
188
+ 这三个方法基于 `Intl`,默认使用“当前 locale”来格式化,并且都支持传入 `options` 自定义格式。
189
+
190
+ ```ts
191
+ import { useI18n } from 'react-native-i18njs';
192
+
193
+ const { formatNumber, formatCurrency, formatDate } = useI18n();
194
+
195
+ formatNumber(1234567.891, { maximumFractionDigits: 2 });
196
+ formatCurrency(99.9, 'CNY', { currencyDisplay: 'narrowSymbol' });
197
+ formatDate(Date.now(), { dateStyle: 'medium', timeStyle: 'short' });
198
+ ```
199
+
200
+ 通用性边界:
201
+
202
+ - 若运行环境没有完整 `Intl`(部分 RN/Hermes 场景),库会自动降级:
203
+ - number:`String(n)`
204
+ - currency:``${n} ${currency}``
205
+ - date:`toISOString()`
206
+ - 如果你希望所有平台表现完全一致,请在你的 App 侧引入 `Intl` polyfill。
207
+ - 如果你想用“非当前 locale”做格式化,请直接使用 `new Intl.NumberFormat('xx', options)` 自行处理。
208
+
209
+ ## 配置参数(I18nOptions)
210
+
211
+ ### `initI18n(translations, options?)`
212
+
213
+ - `translations: Record<string, any>`:翻译资源(locale 为 key)
214
+ - `options?`:
215
+ - `defaultLocale?: string`:默认 `'en'`
216
+ - `enableFallback?: boolean`:默认 `true`
217
+ - `followSystem?: boolean`:默认 `true`;用户手动 `setLocale` 后不再跟随系统
218
+ - `fallbackLocales?: string[] | ((locale: string) => string[])`:自定义回退链(按顺序)
219
+ - `missingBehavior?: 'key' | 'empty' | 'throw'`:默认 `'key'`
220
+ - `onMissingKey?: (key: string, locale: string) => void`:缺失 key 回调
221
+ - `onLocaleChange?: (locale: string) => void`:语言变更回调
222
+
223
+ ## API 速查(按模块)
224
+
225
+ - **初始化/函数**
226
+ - `initI18n`, `t`, `setLocale`, `getLocale`, `loadTranslations`, `readyI18n`, `isI18nReady`
227
+ - **React 绑定(可选)**
228
+ - `I18nProvider`, `useI18n`, `I18nContext`, `withI18n`
229
+ - **组件**
230
+ - `Trans`
231
+ - **类型**
232
+ - `I18nOptions`, `Translations`, `Path`
233
+ - **默认导出**
234
+ - `i18nService`:服务单例(`formatNumber/formatCurrency/formatDate/subscribe/updateLocale` 等)
235
+
236
+ ## 常见问题
237
+
238
+ ### 1) `Invalid hook call` / 多个 React 实例
239
+
240
+ 如果你在 monorepo / workspace 中把本库以源码方式链接到示例或业务 App,可能出现重复 React 导致的 Hook 报错。参考本仓库示例的 Metro 配置做依赖指向与屏蔽:
241
+
242
+ - 示例配置:[example/metro.config.js](./example/metro.config.js)
243
+
244
+ ## 平台支持
245
+
246
+ - **iOS / Android**: 完全支持。
247
+ - **Web**: 需要配置 `webpack` 以支持 `react-native-localize`。请参考 [react-native-localize 文档](https://github.com/zoontek/react-native-localize)。
@@ -0,0 +1,132 @@
1
+ import { Scope, TranslateOptions } from 'i18n-js';
2
+ import React, { ReactNode } from 'react';
3
+ import { TextProps } from 'react-native';
4
+
5
+ interface I18nOptions {
6
+ defaultLocale?: string;
7
+ enableFallback?: boolean;
8
+ onLocaleChange?: (locale: string) => void;
9
+ fallbackLocales?: string[] | ((locale: string) => string[]);
10
+ /**
11
+ * 是否跟随系统语言变化自动切换。
12
+ * - 默认 true:初始化会使用系统语言;App 回到前台时会再次同步系统语言(直到用户手动 setLocale)。
13
+ * - 设为 false:始终使用 defaultLocale / 手动 setLocale,不再自动同步系统语言。
14
+ */
15
+ followSystem?: boolean;
16
+ missingBehavior?: 'key' | 'empty' | 'throw';
17
+ onMissingKey?: (key: string, locale: string) => void;
18
+ }
19
+ type Translations = Record<string, any>;
20
+ type Listener = (locale: string, change?: {
21
+ type: 'locale' | 'translations';
22
+ version: number;
23
+ }) => void;
24
+ /**
25
+ * i18n 引擎接口,定义了任何翻译引擎必须实现的方法
26
+ */
27
+ interface I18nEngine {
28
+ init(translations: Translations, options?: I18nOptions): void;
29
+ loadTranslations(translations: Translations): void;
30
+ setLocale(locale: string): void;
31
+ getLocale(): string;
32
+ t(scope: Scope, options?: TranslateOptions): string;
33
+ formatNumber(n: number, options?: Intl.NumberFormatOptions): string;
34
+ formatCurrency(n: number, currency: string, options?: Intl.NumberFormatOptions): string;
35
+ formatDate(date: Date | number, options?: Intl.DateTimeFormatOptions): string;
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?;
58
+ constructor();
59
+ init(translations: Translations, options?: I18nOptions): void;
60
+ loadTranslations(translations: Translations): void;
61
+ updateLocale(): void;
62
+ setLocale(locale: string): void;
63
+ getLocale(): string;
64
+ t(scope: Scope, options?: TranslateOptions): string;
65
+ formatNumber(n: number, options?: Intl.NumberFormatOptions): string;
66
+ formatCurrency(n: number, currency: string, options?: Intl.NumberFormatOptions): string;
67
+ formatDate(date: Date | number, options?: Intl.DateTimeFormatOptions): string;
68
+ subscribe(listener: Listener): () => void;
69
+ isRTL(): boolean;
70
+ ready(): Promise<void>;
71
+ isReady(): boolean;
72
+ private handleRTL;
73
+ private notifyListeners;
74
+ private setLocaleFromSystem;
75
+ private applyLocale;
76
+ private translateAtLocale;
77
+ private getLocaleChain;
78
+ private hasTranslation;
79
+ private normalizeTranslateResult;
80
+ private normalizeLocaleTag;
81
+ private normalizeTranslations;
82
+ private isRTLLocale;
83
+ }
84
+ declare const i18nService: DefaultI18nEngine;
85
+
86
+ interface I18nContextType {
87
+ locale: string;
88
+ setLocale: (locale: string) => void;
89
+ t: (scope: Scope, options?: TranslateOptions) => string;
90
+ formatNumber: (n: number, options?: Intl.NumberFormatOptions) => string;
91
+ formatCurrency: (n: number, currency: string, options?: Intl.NumberFormatOptions) => string;
92
+ formatDate: (date: Date | number, options?: Intl.DateTimeFormatOptions) => string;
93
+ }
94
+ declare const I18nContext: React.Context<I18nContextType>;
95
+ interface I18nProviderProps {
96
+ children: ReactNode;
97
+ readyGate?: boolean;
98
+ fallback?: ReactNode;
99
+ }
100
+ 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
+ type TFunction<T> = (scope: T extends Translations ? Path<T> : string, options?: TranslateOptions) => string;
108
+ declare function useI18n<T = Translations>(): {
109
+ t: TFunction<T>;
110
+ locale: string;
111
+ setLocale: (locale: string) => void;
112
+ formatNumber: (n: number, options?: Intl.NumberFormatOptions) => string;
113
+ formatCurrency: (n: number, currency: string, options?: Intl.NumberFormatOptions) => string;
114
+ formatDate: (date: Date | number, options?: Intl.DateTimeFormatOptions) => string;
115
+ };
116
+
117
+ interface TransProps extends TextProps {
118
+ i18nKey: string;
119
+ values?: Record<string, any>;
120
+ components?: Record<string, ReactNode>;
121
+ }
122
+ declare const Trans: React.FC<TransProps>;
123
+
124
+ declare const initI18n: (translations: Translations, options?: I18nOptions) => void;
125
+ declare const loadTranslations: (translations: Translations) => void;
126
+ declare const setLocale: (locale: string) => void;
127
+ declare const getLocale: () => string;
128
+ declare const t: (scope: Scope, options?: TranslateOptions) => string;
129
+ declare const readyI18n: () => Promise<void>;
130
+ declare const isI18nReady: () => boolean;
131
+
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 };
@@ -0,0 +1,132 @@
1
+ import { Scope, TranslateOptions } from 'i18n-js';
2
+ import React, { ReactNode } from 'react';
3
+ import { TextProps } from 'react-native';
4
+
5
+ interface I18nOptions {
6
+ defaultLocale?: string;
7
+ enableFallback?: boolean;
8
+ onLocaleChange?: (locale: string) => void;
9
+ fallbackLocales?: string[] | ((locale: string) => string[]);
10
+ /**
11
+ * 是否跟随系统语言变化自动切换。
12
+ * - 默认 true:初始化会使用系统语言;App 回到前台时会再次同步系统语言(直到用户手动 setLocale)。
13
+ * - 设为 false:始终使用 defaultLocale / 手动 setLocale,不再自动同步系统语言。
14
+ */
15
+ followSystem?: boolean;
16
+ missingBehavior?: 'key' | 'empty' | 'throw';
17
+ onMissingKey?: (key: string, locale: string) => void;
18
+ }
19
+ type Translations = Record<string, any>;
20
+ type Listener = (locale: string, change?: {
21
+ type: 'locale' | 'translations';
22
+ version: number;
23
+ }) => void;
24
+ /**
25
+ * i18n 引擎接口,定义了任何翻译引擎必须实现的方法
26
+ */
27
+ interface I18nEngine {
28
+ init(translations: Translations, options?: I18nOptions): void;
29
+ loadTranslations(translations: Translations): void;
30
+ setLocale(locale: string): void;
31
+ getLocale(): string;
32
+ t(scope: Scope, options?: TranslateOptions): string;
33
+ formatNumber(n: number, options?: Intl.NumberFormatOptions): string;
34
+ formatCurrency(n: number, currency: string, options?: Intl.NumberFormatOptions): string;
35
+ formatDate(date: Date | number, options?: Intl.DateTimeFormatOptions): string;
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?;
58
+ constructor();
59
+ init(translations: Translations, options?: I18nOptions): void;
60
+ loadTranslations(translations: Translations): void;
61
+ updateLocale(): void;
62
+ setLocale(locale: string): void;
63
+ getLocale(): string;
64
+ t(scope: Scope, options?: TranslateOptions): string;
65
+ formatNumber(n: number, options?: Intl.NumberFormatOptions): string;
66
+ formatCurrency(n: number, currency: string, options?: Intl.NumberFormatOptions): string;
67
+ formatDate(date: Date | number, options?: Intl.DateTimeFormatOptions): string;
68
+ subscribe(listener: Listener): () => void;
69
+ isRTL(): boolean;
70
+ ready(): Promise<void>;
71
+ isReady(): boolean;
72
+ private handleRTL;
73
+ private notifyListeners;
74
+ private setLocaleFromSystem;
75
+ private applyLocale;
76
+ private translateAtLocale;
77
+ private getLocaleChain;
78
+ private hasTranslation;
79
+ private normalizeTranslateResult;
80
+ private normalizeLocaleTag;
81
+ private normalizeTranslations;
82
+ private isRTLLocale;
83
+ }
84
+ declare const i18nService: DefaultI18nEngine;
85
+
86
+ interface I18nContextType {
87
+ locale: string;
88
+ setLocale: (locale: string) => void;
89
+ t: (scope: Scope, options?: TranslateOptions) => string;
90
+ formatNumber: (n: number, options?: Intl.NumberFormatOptions) => string;
91
+ formatCurrency: (n: number, currency: string, options?: Intl.NumberFormatOptions) => string;
92
+ formatDate: (date: Date | number, options?: Intl.DateTimeFormatOptions) => string;
93
+ }
94
+ declare const I18nContext: React.Context<I18nContextType>;
95
+ interface I18nProviderProps {
96
+ children: ReactNode;
97
+ readyGate?: boolean;
98
+ fallback?: ReactNode;
99
+ }
100
+ 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
+ type TFunction<T> = (scope: T extends Translations ? Path<T> : string, options?: TranslateOptions) => string;
108
+ declare function useI18n<T = Translations>(): {
109
+ t: TFunction<T>;
110
+ locale: string;
111
+ setLocale: (locale: string) => void;
112
+ formatNumber: (n: number, options?: Intl.NumberFormatOptions) => string;
113
+ formatCurrency: (n: number, currency: string, options?: Intl.NumberFormatOptions) => string;
114
+ formatDate: (date: Date | number, options?: Intl.DateTimeFormatOptions) => string;
115
+ };
116
+
117
+ interface TransProps extends TextProps {
118
+ i18nKey: string;
119
+ values?: Record<string, any>;
120
+ components?: Record<string, ReactNode>;
121
+ }
122
+ declare const Trans: React.FC<TransProps>;
123
+
124
+ declare const initI18n: (translations: Translations, options?: I18nOptions) => void;
125
+ declare const loadTranslations: (translations: Translations) => void;
126
+ declare const setLocale: (locale: string) => void;
127
+ declare const getLocale: () => string;
128
+ declare const t: (scope: Scope, options?: TranslateOptions) => string;
129
+ declare const readyI18n: () => Promise<void>;
130
+ declare const isI18nReady: () => boolean;
131
+
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 };