@orderly.network/i18n 3.0.0-beta.1 → 3.0.0-beta.10
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 +23 -469
- package/dist/{constant-BeXwHrGj.d.mts → constant-BwPxVQ3H.d.mts} +45 -40
- package/dist/{constant-BeXwHrGj.d.ts → constant-BwPxVQ3H.d.ts} +45 -40
- package/dist/constant.d.mts +1 -1
- package/dist/constant.d.ts +1 -1
- package/dist/constant.js.map +1 -1
- package/dist/constant.mjs.map +1 -1
- package/dist/index.d.mts +74 -30
- package/dist/index.d.ts +74 -30
- package/dist/index.js +156 -120
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +148 -118
- package/dist/index.mjs.map +1 -1
- package/dist/locale.csv +42 -107
- package/dist/locales/de.json +42 -39
- package/dist/locales/en.json +42 -39
- package/dist/locales/es.json +42 -39
- package/dist/locales/fr.json +42 -39
- package/dist/locales/id.json +42 -39
- package/dist/locales/it.json +42 -39
- package/dist/locales/ja.json +42 -39
- package/dist/locales/ko.json +42 -39
- package/dist/locales/nl.json +42 -39
- package/dist/locales/pl.json +42 -39
- package/dist/locales/pt.json +42 -39
- package/dist/locales/ru.json +42 -39
- package/dist/locales/tc.json +42 -39
- package/dist/locales/tr.json +42 -39
- package/dist/locales/uk.json +42 -39
- package/dist/locales/vi.json +42 -39
- package/dist/locales/zh.json +42 -39
- package/dist/utils.d.mts +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +51 -48
- package/dist/utils.js.map +1 -1
- package/dist/utils.mjs +51 -48
- package/dist/utils.mjs.map +1 -1
- package/docs/guide/AGENTS.md +109 -0
- package/docs/guide/cli.md +133 -0
- package/docs/guide/examples.md +455 -0
- package/docs/guide/exports.md +14 -0
- package/docs/guide/integration.md +223 -0
- package/docs/guide/utils.md +14 -0
- package/package.json +8 -6
- package/scripts/copyLocales.js +11 -0
- package/scripts/csv2json.js +28 -0
- package/scripts/diffCsv.js +175 -0
- package/scripts/fillJson.js +33 -0
- package/scripts/filterLocaleKeys.js +127 -0
- package/scripts/generateCsv.js +36 -0
- package/scripts/generateEnJson.js +11 -0
- package/scripts/generateMissingKeys.js +49 -0
- package/scripts/json-csv-converter.js +286 -0
- package/scripts/json2csv.js +38 -0
- package/scripts/mergeJson.js +67 -0
- package/scripts/separateJson.js +50 -0
- package/scripts/utils.js +94 -0
package/dist/index.d.mts
CHANGED
|
@@ -1,54 +1,75 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { b as Language, d as
|
|
1
|
+
import { R as Resources, A as AsyncResources, L as LocaleCode, a as LanguageContextState } from './constant-BwPxVQ3H.mjs';
|
|
2
|
+
export { b as Language, d as LanguageContext, f as LocaleEnum, e as LocaleMessages, P as PopupMode, c as PopupProps, g as defaultLanguages, h as defaultLng, i as defaultNS, l as en, k as i18nCookieKey, j as i18nLocalStorageKey, u as useLanguageContext } from './constant-BwPxVQ3H.mjs';
|
|
3
3
|
import * as react_i18next from 'react-i18next';
|
|
4
|
-
import {
|
|
4
|
+
import { FallbackNs, UseTranslationOptions } from 'react-i18next';
|
|
5
5
|
export * from 'react-i18next';
|
|
6
6
|
import * as i18next from 'i18next';
|
|
7
7
|
import { InitOptions, FlatNamespace, KeyPrefix } from 'i18next';
|
|
8
8
|
export { createInstance, default as i18next } from 'i18next';
|
|
9
|
-
import {
|
|
9
|
+
import { PropsWithChildren, FC } from 'react';
|
|
10
10
|
import { $Tuple } from 'react-i18next/helpers';
|
|
11
11
|
export { generatePath, getLocalePathFromPathname, parseI18nLang, removeLangPrefix } from './utils.mjs';
|
|
12
12
|
|
|
13
13
|
declare function createI18nInstance(options?: InitOptions): i18next.i18n;
|
|
14
14
|
declare const i18n: i18next.i18n;
|
|
15
15
|
|
|
16
|
+
declare function registerResources(resources: Resources | AsyncResources | undefined, localeCode: LocaleCode): Promise<void>;
|
|
17
|
+
|
|
16
18
|
type BackendOptions = {
|
|
17
19
|
loadPath: (lang: LocaleCode, ns: string) => string | string[] | undefined;
|
|
18
20
|
};
|
|
21
|
+
declare class Backend {
|
|
22
|
+
options: BackendOptions;
|
|
23
|
+
cache: Set<string>;
|
|
24
|
+
constructor(options: BackendOptions);
|
|
25
|
+
fetchData(url: string): Promise<any>;
|
|
26
|
+
loadLanguage(lang: LocaleCode, ns: string): Promise<void>;
|
|
27
|
+
}
|
|
19
28
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Register the default language bundle before your React tree renders to reduce
|
|
31
|
+
* flicker of raw translation keys.
|
|
32
|
+
*/
|
|
33
|
+
declare const registerDefaultResource: (messages: Record<string, string>) => void;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Shape of a locale JSON file loaded via dynamic import / Vite `import.meta.glob`.
|
|
37
|
+
*/
|
|
38
|
+
type LocaleJsonModule = {
|
|
39
|
+
default?: Record<string, string> | string | null;
|
|
40
|
+
};
|
|
41
|
+
declare function asMessageRecord(value: Record<string, string> | string | null | undefined): Record<string, string>;
|
|
42
|
+
/**
|
|
43
|
+
* Loads a locale JSON module via a Vite `import.meta.glob` loader or a dynamic `import()` thunk,
|
|
44
|
+
* and normalizes `default` to a flat message record.
|
|
45
|
+
* Missing `loader`, rejected `loader()`, or missing/invalid `default` yields `{}` (see {@link asMessageRecord}).
|
|
46
|
+
*/
|
|
47
|
+
declare function importLocaleJsonModule(loader: (() => Promise<LocaleJsonModule>) | undefined): Promise<Record<string, string>>;
|
|
48
|
+
|
|
49
|
+
type LanguageProviderProps = PropsWithChildren<{
|
|
50
|
+
backend?: BackendOptions;
|
|
27
51
|
/**
|
|
28
52
|
* supported languages, you can select supported languages from default languages
|
|
29
53
|
*/
|
|
30
54
|
supportedLanguages?: LocaleCode[];
|
|
31
55
|
/** optional conversion function to use to modify the detected language code */
|
|
32
56
|
convertDetectedLanguage?: (lang: string) => LocaleCode;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
declare const LocaleProvider: React.FC<LocaleProviderProps>;
|
|
57
|
+
} & Partial<LanguageContextState>>;
|
|
58
|
+
declare const LanguageProvider: FC<LanguageProviderProps>;
|
|
36
59
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
60
|
+
type LocaleProviderProps = LanguageProviderProps & {
|
|
61
|
+
/** Active locale; when set and bundles exist, syncs i18n language via `changeLanguage`. */
|
|
62
|
+
locale?: LocaleCode;
|
|
63
|
+
/** Flat key-value messages for `defaultNS`; used together with `locale` when `resources` is not provided. */
|
|
64
|
+
resource?: Record<string, string>;
|
|
65
|
+
/**
|
|
66
|
+
* Preload locale bundles: static `Resources` map, or an async loader (same contract as
|
|
67
|
+
* `ExternalLocaleProvider`). When set, takes precedence over `locale` + `resource`.
|
|
68
|
+
*/
|
|
69
|
+
resources?: Resources | AsyncResources;
|
|
70
|
+
};
|
|
71
|
+
declare const LocaleProvider: FC<LocaleProviderProps>;
|
|
45
72
|
|
|
46
|
-
/**
|
|
47
|
-
* Async loader contract for pulling translation resources from an external system.
|
|
48
|
-
* Implementations are expected to return the full message table for the given locale
|
|
49
|
-
* and namespace so that the bundle can be replaced atomically.
|
|
50
|
-
*/
|
|
51
|
-
type AsyncResources = (lang: LocaleCode, ns: string) => Promise<Record<string, string>>;
|
|
52
73
|
type ExternalLocaleProviderProps = PropsWithChildren<{
|
|
53
74
|
resources?: Resources | AsyncResources;
|
|
54
75
|
}>;
|
|
@@ -62,8 +83,31 @@ type ExternalLocaleProviderProps = PropsWithChildren<{
|
|
|
62
83
|
* synchronously on mount.
|
|
63
84
|
*
|
|
64
85
|
* This component renders no UI; it only manages i18n side effects and simply
|
|
65
|
-
* returns its children.
|
|
86
|
+
* returns its children. Same behavior as calling `useRegisterExternalResources(resources)`
|
|
87
|
+
* in your own component under `LocaleProvider`.
|
|
66
88
|
*/
|
|
67
89
|
declare const ExternalLocaleProvider: FC<ExternalLocaleProviderProps>;
|
|
68
90
|
|
|
69
|
-
|
|
91
|
+
declare function useTranslation<Ns extends FlatNamespace | $Tuple<FlatNamespace> | undefined, KPrefix extends KeyPrefix<FallbackNs<Ns>> = undefined>(ns?: Ns, options?: UseTranslationOptions<KPrefix>): react_i18next.UseTranslationResponse<FallbackNs<Ns>, KPrefix>;
|
|
92
|
+
|
|
93
|
+
declare function useLocaleCode(): LocaleCode;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Registers host-provided i18n resources into the shared i18n instance whenever
|
|
97
|
+
* the active locale or `resources` reference changes.
|
|
98
|
+
*
|
|
99
|
+
* - When `resources` is a function, it is invoked for the current locale to
|
|
100
|
+
* load the bundle (e.g. from another bundle, backend, or runtime loader).
|
|
101
|
+
* - When `resources` is a static map, all provided locale bundles are registered.
|
|
102
|
+
*
|
|
103
|
+
* Prefer a stable `resources` reference (e.g. `useCallback` for loaders, module
|
|
104
|
+
* scope or `useMemo` for static maps) to avoid unnecessary re-registration.
|
|
105
|
+
*/
|
|
106
|
+
declare function useRegisterExternalResources(resources?: Resources | AsyncResources): void;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* preload default locale resources to prevent flickering of raw translation keys
|
|
110
|
+
*/
|
|
111
|
+
declare const preloadDefaultResource: (messages: Record<string, string>) => void;
|
|
112
|
+
|
|
113
|
+
export { AsyncResources, Backend, type BackendOptions, ExternalLocaleProvider, type ExternalLocaleProviderProps, LanguageContextState, LanguageProvider, type LanguageProviderProps, LocaleCode, type LocaleJsonModule, LocaleProvider, type LocaleProviderProps, Resources, asMessageRecord, createI18nInstance, i18n, importLocaleJsonModule, preloadDefaultResource, registerDefaultResource, registerResources, useLocaleCode, useRegisterExternalResources, useTranslation };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,54 +1,75 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { b as Language, d as
|
|
1
|
+
import { R as Resources, A as AsyncResources, L as LocaleCode, a as LanguageContextState } from './constant-BwPxVQ3H.js';
|
|
2
|
+
export { b as Language, d as LanguageContext, f as LocaleEnum, e as LocaleMessages, P as PopupMode, c as PopupProps, g as defaultLanguages, h as defaultLng, i as defaultNS, l as en, k as i18nCookieKey, j as i18nLocalStorageKey, u as useLanguageContext } from './constant-BwPxVQ3H.js';
|
|
3
3
|
import * as react_i18next from 'react-i18next';
|
|
4
|
-
import {
|
|
4
|
+
import { FallbackNs, UseTranslationOptions } from 'react-i18next';
|
|
5
5
|
export * from 'react-i18next';
|
|
6
6
|
import * as i18next from 'i18next';
|
|
7
7
|
import { InitOptions, FlatNamespace, KeyPrefix } from 'i18next';
|
|
8
8
|
export { createInstance, default as i18next } from 'i18next';
|
|
9
|
-
import {
|
|
9
|
+
import { PropsWithChildren, FC } from 'react';
|
|
10
10
|
import { $Tuple } from 'react-i18next/helpers';
|
|
11
11
|
export { generatePath, getLocalePathFromPathname, parseI18nLang, removeLangPrefix } from './utils.js';
|
|
12
12
|
|
|
13
13
|
declare function createI18nInstance(options?: InitOptions): i18next.i18n;
|
|
14
14
|
declare const i18n: i18next.i18n;
|
|
15
15
|
|
|
16
|
+
declare function registerResources(resources: Resources | AsyncResources | undefined, localeCode: LocaleCode): Promise<void>;
|
|
17
|
+
|
|
16
18
|
type BackendOptions = {
|
|
17
19
|
loadPath: (lang: LocaleCode, ns: string) => string | string[] | undefined;
|
|
18
20
|
};
|
|
21
|
+
declare class Backend {
|
|
22
|
+
options: BackendOptions;
|
|
23
|
+
cache: Set<string>;
|
|
24
|
+
constructor(options: BackendOptions);
|
|
25
|
+
fetchData(url: string): Promise<any>;
|
|
26
|
+
loadLanguage(lang: LocaleCode, ns: string): Promise<void>;
|
|
27
|
+
}
|
|
19
28
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Register the default language bundle before your React tree renders to reduce
|
|
31
|
+
* flicker of raw translation keys.
|
|
32
|
+
*/
|
|
33
|
+
declare const registerDefaultResource: (messages: Record<string, string>) => void;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Shape of a locale JSON file loaded via dynamic import / Vite `import.meta.glob`.
|
|
37
|
+
*/
|
|
38
|
+
type LocaleJsonModule = {
|
|
39
|
+
default?: Record<string, string> | string | null;
|
|
40
|
+
};
|
|
41
|
+
declare function asMessageRecord(value: Record<string, string> | string | null | undefined): Record<string, string>;
|
|
42
|
+
/**
|
|
43
|
+
* Loads a locale JSON module via a Vite `import.meta.glob` loader or a dynamic `import()` thunk,
|
|
44
|
+
* and normalizes `default` to a flat message record.
|
|
45
|
+
* Missing `loader`, rejected `loader()`, or missing/invalid `default` yields `{}` (see {@link asMessageRecord}).
|
|
46
|
+
*/
|
|
47
|
+
declare function importLocaleJsonModule(loader: (() => Promise<LocaleJsonModule>) | undefined): Promise<Record<string, string>>;
|
|
48
|
+
|
|
49
|
+
type LanguageProviderProps = PropsWithChildren<{
|
|
50
|
+
backend?: BackendOptions;
|
|
27
51
|
/**
|
|
28
52
|
* supported languages, you can select supported languages from default languages
|
|
29
53
|
*/
|
|
30
54
|
supportedLanguages?: LocaleCode[];
|
|
31
55
|
/** optional conversion function to use to modify the detected language code */
|
|
32
56
|
convertDetectedLanguage?: (lang: string) => LocaleCode;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
declare const LocaleProvider: React.FC<LocaleProviderProps>;
|
|
57
|
+
} & Partial<LanguageContextState>>;
|
|
58
|
+
declare const LanguageProvider: FC<LanguageProviderProps>;
|
|
36
59
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
60
|
+
type LocaleProviderProps = LanguageProviderProps & {
|
|
61
|
+
/** Active locale; when set and bundles exist, syncs i18n language via `changeLanguage`. */
|
|
62
|
+
locale?: LocaleCode;
|
|
63
|
+
/** Flat key-value messages for `defaultNS`; used together with `locale` when `resources` is not provided. */
|
|
64
|
+
resource?: Record<string, string>;
|
|
65
|
+
/**
|
|
66
|
+
* Preload locale bundles: static `Resources` map, or an async loader (same contract as
|
|
67
|
+
* `ExternalLocaleProvider`). When set, takes precedence over `locale` + `resource`.
|
|
68
|
+
*/
|
|
69
|
+
resources?: Resources | AsyncResources;
|
|
70
|
+
};
|
|
71
|
+
declare const LocaleProvider: FC<LocaleProviderProps>;
|
|
45
72
|
|
|
46
|
-
/**
|
|
47
|
-
* Async loader contract for pulling translation resources from an external system.
|
|
48
|
-
* Implementations are expected to return the full message table for the given locale
|
|
49
|
-
* and namespace so that the bundle can be replaced atomically.
|
|
50
|
-
*/
|
|
51
|
-
type AsyncResources = (lang: LocaleCode, ns: string) => Promise<Record<string, string>>;
|
|
52
73
|
type ExternalLocaleProviderProps = PropsWithChildren<{
|
|
53
74
|
resources?: Resources | AsyncResources;
|
|
54
75
|
}>;
|
|
@@ -62,8 +83,31 @@ type ExternalLocaleProviderProps = PropsWithChildren<{
|
|
|
62
83
|
* synchronously on mount.
|
|
63
84
|
*
|
|
64
85
|
* This component renders no UI; it only manages i18n side effects and simply
|
|
65
|
-
* returns its children.
|
|
86
|
+
* returns its children. Same behavior as calling `useRegisterExternalResources(resources)`
|
|
87
|
+
* in your own component under `LocaleProvider`.
|
|
66
88
|
*/
|
|
67
89
|
declare const ExternalLocaleProvider: FC<ExternalLocaleProviderProps>;
|
|
68
90
|
|
|
69
|
-
|
|
91
|
+
declare function useTranslation<Ns extends FlatNamespace | $Tuple<FlatNamespace> | undefined, KPrefix extends KeyPrefix<FallbackNs<Ns>> = undefined>(ns?: Ns, options?: UseTranslationOptions<KPrefix>): react_i18next.UseTranslationResponse<FallbackNs<Ns>, KPrefix>;
|
|
92
|
+
|
|
93
|
+
declare function useLocaleCode(): LocaleCode;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Registers host-provided i18n resources into the shared i18n instance whenever
|
|
97
|
+
* the active locale or `resources` reference changes.
|
|
98
|
+
*
|
|
99
|
+
* - When `resources` is a function, it is invoked for the current locale to
|
|
100
|
+
* load the bundle (e.g. from another bundle, backend, or runtime loader).
|
|
101
|
+
* - When `resources` is a static map, all provided locale bundles are registered.
|
|
102
|
+
*
|
|
103
|
+
* Prefer a stable `resources` reference (e.g. `useCallback` for loaders, module
|
|
104
|
+
* scope or `useMemo` for static maps) to avoid unnecessary re-registration.
|
|
105
|
+
*/
|
|
106
|
+
declare function useRegisterExternalResources(resources?: Resources | AsyncResources): void;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* preload default locale resources to prevent flickering of raw translation keys
|
|
110
|
+
*/
|
|
111
|
+
declare const preloadDefaultResource: (messages: Record<string, string>) => void;
|
|
112
|
+
|
|
113
|
+
export { AsyncResources, Backend, type BackendOptions, ExternalLocaleProvider, type ExternalLocaleProviderProps, LanguageContextState, LanguageProvider, type LanguageProviderProps, LocaleCode, type LocaleJsonModule, LocaleProvider, type LocaleProviderProps, Resources, asMessageRecord, createI18nInstance, i18n, importLocaleJsonModule, preloadDefaultResource, registerDefaultResource, registerResources, useLocaleCode, useRegisterExternalResources, useTranslation };
|