@orderly.network/i18n 3.0.4 → 3.1.0-alpha.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/{constant-CIx423sl.d.mts → constant-C85biO-A.d.mts} +6 -0
- package/dist/{constant-CIx423sl.d.ts → constant-C85biO-A.d.ts} +6 -0
- package/dist/constant.d.mts +1 -1
- package/dist/constant.d.ts +1 -1
- package/dist/constant.js +9 -0
- package/dist/constant.js.map +1 -1
- package/dist/constant.mjs +9 -0
- package/dist/constant.mjs.map +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -1
- package/dist/index.mjs.map +1 -1
- package/dist/locale.csv +1270 -1270
- package/dist/locales/ar.json +1271 -0
- package/dist/locales/de.json +2 -2
- package/dist/locales/es.json +2 -2
- package/dist/locales/fa.json +1271 -0
- package/dist/locales/fr.json +2 -2
- package/dist/locales/he.json +1271 -0
- package/dist/locales/id.json +2 -2
- package/dist/locales/it.json +2 -2
- package/dist/locales/ja.json +2 -2
- package/dist/locales/ko.json +2 -2
- package/dist/locales/nl.json +2 -2
- package/dist/locales/pl.json +2 -2
- package/dist/locales/pt.json +2 -2
- package/dist/locales/ru.json +2 -2
- package/dist/locales/tc.json +2 -2
- package/dist/locales/tr.json +1 -1
- package/dist/locales/uk.json +2 -2
- package/dist/locales/vi.json +2 -2
- package/dist/locales/zh.json +2 -2
- package/dist/utils.d.mts +8 -2
- package/dist/utils.d.ts +8 -2
- package/dist/utils.js +15 -0
- package/dist/utils.js.map +1 -1
- package/dist/utils.mjs +14 -1
- package/dist/utils.mjs.map +1 -1
- package/docs/guide/integration.md +6 -6
- package/package.json +2 -2
- package/scripts/mergeAiLocaleChunks.js +77 -0
- package/scripts/splitEnLocaleChunks.js +42 -0
|
@@ -137,12 +137,12 @@ For host apps, bundling SDK locales with your `extend` JSON via `LocaleProvider`
|
|
|
137
137
|
|
|
138
138
|
Async external resources are also registered as preloaders while their provider is mounted. Calls to the package singleton `i18n.changeLanguage(locale)` wait for those mounted external resources to load the target locale before the language is switched. This keeps plugin/host extension bundles lazy by locale while ensuring the first render after the language switch already has the target external messages registered.
|
|
139
139
|
|
|
140
|
-
####
|
|
140
|
+
#### Recommended async provider
|
|
141
141
|
|
|
142
|
-
For external SDK packages or plugin packages, ship a provider
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
142
|
+
For external SDK packages or plugin packages, ship a package-local provider:
|
|
143
|
+
preload the default English messages, load non-English JSON chunks lazily with
|
|
144
|
+
statically analyzable imports, and wrap the package subtree with
|
|
145
|
+
`ExternalLocaleProvider`.
|
|
146
146
|
|
|
147
147
|
This keeps the host app in charge of the root `LocaleProvider` while your package contributes its own translation resources to the shared singleton `i18n` instance. Use explicit per-locale dynamic imports so webpack/Next can resolve locale JSON chunks reliably. Vite accepts the same pattern.
|
|
148
148
|
|
|
@@ -206,7 +206,7 @@ The exported `LocaleProvider` above is your package-local provider. It is not th
|
|
|
206
206
|
|
|
207
207
|
`LocaleMessages` should be the package's English/default message map, and `./locales/<locale>.json` should contain the translated package messages for that locale. If your package supports only a subset of languages, keep the full `Record<LocaleEnum, ...>` shape but leave unsupported loaders as `undefined`; `importLocaleJsonModule(undefined)` safely returns an empty resource object.
|
|
208
208
|
|
|
209
|
-
|
|
209
|
+
#### Static resources example
|
|
210
210
|
|
|
211
211
|
```tsx
|
|
212
212
|
import {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orderly.network/i18n",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.1.0-alpha.0",
|
|
4
4
|
"description": "Internationalization for orderly sdk",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"react-dom": "^18.2.0",
|
|
51
51
|
"tsup": "^8.5.1",
|
|
52
52
|
"typescript": "^5.1.6",
|
|
53
|
-
"tsconfig": "1.0.
|
|
53
|
+
"tsconfig": "1.1.0-alpha.0"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"react": ">=18",
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Merge translated chunk JSON files into locales/fa.json and locales/he.json.
|
|
4
|
+
* Expects files named fa-00.json … fa-NN.json (and he-00.json …) under chunkDir.
|
|
5
|
+
*
|
|
6
|
+
* Usage (from packages/i18n):
|
|
7
|
+
* node scripts/mergeAiLocaleChunks.js ./locales/_ai_translate_chunks/fa locales/fa.json --fallback-en
|
|
8
|
+
* node scripts/mergeAiLocaleChunks.js ./locales/_ai_translate_chunks/he locales/he.json --fallback-en
|
|
9
|
+
*
|
|
10
|
+
* Without --fallback-en: throws if any key from en.json is missing in merged chunks.
|
|
11
|
+
*/
|
|
12
|
+
const fs = require("fs-extra");
|
|
13
|
+
const path = require("path");
|
|
14
|
+
|
|
15
|
+
async function merge(chunkDir, outFile, enPath, fallbackEn) {
|
|
16
|
+
const files = (await fs.readdir(chunkDir))
|
|
17
|
+
.filter((f) => f.endsWith(".json"))
|
|
18
|
+
.sort();
|
|
19
|
+
|
|
20
|
+
if (!files.length) {
|
|
21
|
+
throw new Error(`No JSON chunks under ${chunkDir}`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const merged = {};
|
|
25
|
+
for (const f of files) {
|
|
26
|
+
const part = await fs.readJSON(path.join(chunkDir, f));
|
|
27
|
+
Object.assign(merged, part);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const en = await fs.readJSON(enPath);
|
|
31
|
+
const missing = Object.keys(en).filter((k) => !(k in merged));
|
|
32
|
+
|
|
33
|
+
if (missing.length) {
|
|
34
|
+
if (!fallbackEn) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
`Missing ${missing.length} keys (e.g. ${missing.slice(0, 5).join(", ")}) for ${path.basename(outFile)}`,
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
for (const k of missing) {
|
|
40
|
+
merged[k] = en[k];
|
|
41
|
+
}
|
|
42
|
+
console.warn(
|
|
43
|
+
`[mergeAiLocaleChunks] ${missing.length} keys fell back to English in ${path.basename(outFile)}`,
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const sorted = {};
|
|
48
|
+
for (const k of Object.keys(en)) {
|
|
49
|
+
sorted[k] = merged[k];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
await fs.outputJSON(outFile, sorted, { spaces: 2 });
|
|
53
|
+
console.log("wrote", outFile);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function main() {
|
|
57
|
+
const [, , chunkDir, outFile, flag] = process.argv;
|
|
58
|
+
if (!chunkDir || !outFile) {
|
|
59
|
+
console.error(
|
|
60
|
+
"Usage: node scripts/mergeAiLocaleChunks.js <chunkDir> <outFile> [--fallback-en]",
|
|
61
|
+
);
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
const fallbackEn = flag === "--fallback-en";
|
|
65
|
+
const enPath = path.resolve(__dirname, "../locales/en.json");
|
|
66
|
+
await merge(
|
|
67
|
+
path.resolve(chunkDir),
|
|
68
|
+
path.resolve(outFile),
|
|
69
|
+
enPath,
|
|
70
|
+
fallbackEn,
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
main().catch((e) => {
|
|
75
|
+
console.error(e);
|
|
76
|
+
process.exit(1);
|
|
77
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Split locales/en.json into smaller JSON files so each part can be pasted into Cursor / another LLM
|
|
4
|
+
* for Persian (fa) or Hebrew (he) translation without calling external translation APIs.
|
|
5
|
+
*
|
|
6
|
+
* Usage (from packages/i18n):
|
|
7
|
+
* node scripts/splitEnLocaleChunks.js [chunkSize] [outDir]
|
|
8
|
+
*
|
|
9
|
+
* Defaults: chunkSize=80, outDir=locales/_ai_translate_chunks/en
|
|
10
|
+
*/
|
|
11
|
+
const fs = require("fs-extra");
|
|
12
|
+
const path = require("path");
|
|
13
|
+
|
|
14
|
+
async function main() {
|
|
15
|
+
const chunkSize = Number(process.argv[2]) || 80;
|
|
16
|
+
const outDir = path.resolve(
|
|
17
|
+
process.argv[3] ||
|
|
18
|
+
path.join(__dirname, "../locales/_ai_translate_chunks/en"),
|
|
19
|
+
);
|
|
20
|
+
const enPath = path.resolve(__dirname, "../locales/en.json");
|
|
21
|
+
const en = await fs.readJSON(enPath);
|
|
22
|
+
const keys = Object.keys(en).sort();
|
|
23
|
+
|
|
24
|
+
await fs.ensureDir(outDir);
|
|
25
|
+
let idx = 0;
|
|
26
|
+
for (let i = 0; i < keys.length; i += chunkSize, idx++) {
|
|
27
|
+
const slice = keys.slice(i, i + chunkSize);
|
|
28
|
+
const chunk = {};
|
|
29
|
+
for (const k of slice) {
|
|
30
|
+
chunk[k] = en[k];
|
|
31
|
+
}
|
|
32
|
+
const name = `en-${String(idx).padStart(2, "0")}.json`;
|
|
33
|
+
await fs.outputJSON(path.join(outDir, name), chunk, { spaces: 2 });
|
|
34
|
+
console.log("wrote", name, Object.keys(chunk).length, "keys");
|
|
35
|
+
}
|
|
36
|
+
console.log("done =>", outDir);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
main().catch((e) => {
|
|
40
|
+
console.error(e);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
});
|