@orderly.network/i18n 2.1.0 → 2.1.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 +129 -39
- package/bin/cli.js +98 -30
- package/dist/index.d.mts +96 -639
- package/dist/index.d.ts +96 -639
- package/dist/index.js +20 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -4
- package/dist/index.mjs.map +1 -1
- package/dist/locale.csv +611 -603
- package/dist/locales/de.json +612 -0
- package/dist/locales/en.json +612 -0
- package/dist/locales/es.json +612 -0
- package/dist/locales/fr.json +612 -0
- package/dist/locales/ja.json +612 -0
- package/dist/locales/ko.json +612 -0
- package/dist/locales/vi.json +612 -0
- package/dist/locales/zh.json +612 -0
- package/package.json +23 -8
- package/script/copyLocales.js +11 -0
- package/script/csv2json.js +28 -0
- package/script/diffCsv.js +153 -0
- package/script/fillJson.js +33 -0
- package/script/generateCsv.js +36 -0
- package/script/generateEnJson.js +11 -0
- package/script/json-csv-converter.js +176 -0
- package/script/json2csv.js +38 -0
- package/script/mergeJson.js +49 -0
- package/script/separateJson.js +50 -0
- package/script/utils.js +88 -0
package/README.md
CHANGED
|
@@ -2,35 +2,115 @@
|
|
|
2
2
|
|
|
3
3
|
Internationalization and cli tools for Orderly SDK. Based on i18next ecosystem.
|
|
4
4
|
|
|
5
|
-
## Integration
|
|
5
|
+
## Integration Guide
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Follow these steps to integrate localization support in your app using Orderly SDK:
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
### 1. Wrap Your App with LocaleProvider
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
The LocaleProvider is the core component that supplies localized resources to your application. Make sure to wrap your app’s root component with LocaleProvider.
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
- Currently, we provider English (en) and Chinese (zh) locale files.
|
|
16
|
-
- You can also extend the built-in messages by merging them with your own locale files.
|
|
17
|
-
- With each release we will generate csv files (dist/locale.csv) for easy translation and we provide a cli to convert between csv and json files.
|
|
18
|
-
- It can translate not only the ui in the SDK, but also other components you write outside of the SDK.
|
|
13
|
+
```tsx
|
|
14
|
+
import { LocaleProvider } from "@orderly.network/i18n";
|
|
19
15
|
|
|
20
|
-
|
|
16
|
+
<LocaleProvider>
|
|
17
|
+
<YourApp />
|
|
18
|
+
</LocaleProvider>;
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### 2. Provide Locale Data
|
|
22
|
+
|
|
23
|
+
#### Default Language
|
|
24
|
+
|
|
25
|
+
- English (`en`) is included by default.
|
|
26
|
+
|
|
27
|
+
#### Supported Locales
|
|
28
|
+
|
|
29
|
+
We currently support **8 locales**, located in the `dist/locales` directory:
|
|
30
|
+
|
|
31
|
+
| Locale Code | Language |
|
|
32
|
+
| ----------- | ---------- |
|
|
33
|
+
| `en.json` | English |
|
|
34
|
+
| `zh.json` | Chinese |
|
|
35
|
+
| `ja.json` | Japanese |
|
|
36
|
+
| `es.json` | Spanish |
|
|
37
|
+
| `ko.json` | Korean |
|
|
38
|
+
| `vi.json` | Vietnamese |
|
|
39
|
+
| `de.json` | German |
|
|
40
|
+
| `fr.json` | French |
|
|
41
|
+
|
|
42
|
+
> We plan to add more languages in future updates.
|
|
43
|
+
|
|
44
|
+
#### CSV for Easy Translation
|
|
45
|
+
|
|
46
|
+
- Each release generates a `dist/locale.csv` file to simplify translation workflows.
|
|
47
|
+
- We provide a CLI tool to convert between CSV and JSON formats.
|
|
48
|
+
|
|
49
|
+
### 3. Extending Locale Files
|
|
50
|
+
|
|
51
|
+
You can localize both the SDK UI and your own custom components.
|
|
52
|
+
|
|
53
|
+
- When adding custom keys, prefix them with `extend.` to avoid conflicts with default keys.
|
|
54
|
+
|
|
55
|
+
```json
|
|
56
|
+
{
|
|
57
|
+
"extend.custom.button.label": "My Custom Button"
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Example
|
|
62
|
+
|
|
63
|
+
Here's a complete example of how to set up the i18n integration:
|
|
21
64
|
|
|
22
|
-
|
|
65
|
+
### Async load locale files
|
|
23
66
|
|
|
24
67
|
```typescript
|
|
25
68
|
import { FC, ReactNode } from "react";
|
|
26
69
|
import { WalletConnectorProvider } from "@orderly.network/wallet-connector";
|
|
27
70
|
import { OrderlyAppProvider } from "@orderly.network/react-app";
|
|
28
|
-
import {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
LocaleCode
|
|
32
|
-
|
|
33
|
-
|
|
71
|
+
import { LocaleProvider, LocaleEnum, LocaleCode } from "@orderly.network/i18n";
|
|
72
|
+
|
|
73
|
+
const OrderlyProvider: FC<{ children: ReactNode }> = (props) => {
|
|
74
|
+
const onLanguageChanged = async (lang: LocaleCode) => {};
|
|
75
|
+
|
|
76
|
+
// please copy build-in locale files to you public/locales
|
|
77
|
+
// and copy you extend locale files to public/locales/extend
|
|
78
|
+
const loadPath = (lang: LocaleCode) => {
|
|
79
|
+
const _lang = parseI18nLang(lang);
|
|
80
|
+
if (_lang === LocaleEnum.en) {
|
|
81
|
+
// because en is built-in, we need to load the en extend only
|
|
82
|
+
return `/locales/extend/${_lang}.json`;
|
|
83
|
+
}
|
|
84
|
+
return [`/locales/${_lang}.json`, `/locales/extend/${_lang}.json`];
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<LocaleProvider
|
|
89
|
+
onLanguageChanged={onLanguageChanged}
|
|
90
|
+
backend={{ loadPath }}
|
|
91
|
+
>
|
|
92
|
+
<WalletConnectorProvider>
|
|
93
|
+
<OrderlyAppProvider
|
|
94
|
+
brokerId="orderly"
|
|
95
|
+
brokerName="Orderly"
|
|
96
|
+
networkId="testnet"
|
|
97
|
+
>
|
|
98
|
+
{props.children}
|
|
99
|
+
</OrderlyAppProvider>
|
|
100
|
+
</WalletConnectorProvider>
|
|
101
|
+
</LocaleProvider>
|
|
102
|
+
);
|
|
103
|
+
};
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Sync Load locale data
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
import { FC, ReactNode } from "react";
|
|
110
|
+
import { WalletConnectorProvider } from "@orderly.network/wallet-connector";
|
|
111
|
+
import { OrderlyAppProvider } from "@orderly.network/react-app";
|
|
112
|
+
import { LocaleProvider, LocaleCode, Resources } from "@orderly.network/i18n";
|
|
113
|
+
import zh from "@orderly.network/i18n/locales/zh.json";
|
|
34
114
|
|
|
35
115
|
// extend or overrides English translations
|
|
36
116
|
const extendEn = {
|
|
@@ -42,10 +122,8 @@ const extendZh = {
|
|
|
42
122
|
"extend.trading": "交易",
|
|
43
123
|
};
|
|
44
124
|
|
|
45
|
-
type ExtendLocaleMessages = typeof extendEn;
|
|
46
|
-
|
|
47
125
|
// define language resources
|
|
48
|
-
const resources: Resources
|
|
126
|
+
const resources: Resources = {
|
|
49
127
|
en: extendEn,
|
|
50
128
|
zh: {
|
|
51
129
|
...zh,
|
|
@@ -54,10 +132,10 @@ const resources: Resources<ExtendLocaleMessages> = {
|
|
|
54
132
|
};
|
|
55
133
|
|
|
56
134
|
const OrderlyProvider: FC<{ children: ReactNode }> = (props) => {
|
|
57
|
-
const
|
|
135
|
+
const onLanguageChanged = (locale: LocaleCode) => {};
|
|
58
136
|
|
|
59
137
|
return (
|
|
60
|
-
<LocaleProvider resources={resources}
|
|
138
|
+
<LocaleProvider resources={resources} onLanguageChanged={onLocaleChange}>
|
|
61
139
|
<WalletConnectorProvider>
|
|
62
140
|
<OrderlyAppProvider
|
|
63
141
|
brokerId="orderly"
|
|
@@ -72,7 +150,7 @@ const OrderlyProvider: FC<{ children: ReactNode }> = (props) => {
|
|
|
72
150
|
};
|
|
73
151
|
```
|
|
74
152
|
|
|
75
|
-
### Add
|
|
153
|
+
### Add custom languages
|
|
76
154
|
|
|
77
155
|
We also support adding more custom languages
|
|
78
156
|
|
|
@@ -83,7 +161,6 @@ import { OrderlyAppProvider } from "@orderly.network/react-app";
|
|
|
83
161
|
import {
|
|
84
162
|
LocaleProvider,
|
|
85
163
|
Resources,
|
|
86
|
-
zh,
|
|
87
164
|
LocaleEnum,
|
|
88
165
|
LocaleCode,
|
|
89
166
|
Language,
|
|
@@ -101,7 +178,6 @@ const ko = {
|
|
|
101
178
|
|
|
102
179
|
// define language resources
|
|
103
180
|
const resources: Resources = {
|
|
104
|
-
en,
|
|
105
181
|
ja,
|
|
106
182
|
ko,
|
|
107
183
|
};
|
|
@@ -114,13 +190,13 @@ const languages: Language[] = [
|
|
|
114
190
|
];
|
|
115
191
|
|
|
116
192
|
const OrderlyProvider: FC<{ children: ReactNode }> = (props) => {
|
|
117
|
-
const
|
|
193
|
+
const onLanguageChanged = (locale: LocaleCode) => {};
|
|
118
194
|
|
|
119
195
|
return (
|
|
120
196
|
<LocaleProvider
|
|
121
197
|
resources={resources}
|
|
122
198
|
languages={languages}
|
|
123
|
-
|
|
199
|
+
onLanguageChanged={onLanguageChanged}
|
|
124
200
|
>
|
|
125
201
|
<WalletConnectorProvider>
|
|
126
202
|
<OrderlyAppProvider
|
|
@@ -159,7 +235,7 @@ npx @orderly.network/i18n csv2json <input> <outputDir>
|
|
|
159
235
|
Example:
|
|
160
236
|
|
|
161
237
|
```bash
|
|
162
|
-
npx @orderly.network/i18n csv2json ./dist/locale.csv ./dist/
|
|
238
|
+
npx @orderly.network/i18n csv2json ./dist/locale.csv ./dist/locales
|
|
163
239
|
```
|
|
164
240
|
|
|
165
241
|
### json2csv
|
|
@@ -167,13 +243,13 @@ npx @orderly.network/i18n csv2json ./dist/locale.csv ./dist/locale
|
|
|
167
243
|
Convert multiple locale JSON files to a single locale CSV file.
|
|
168
244
|
|
|
169
245
|
```bash
|
|
170
|
-
npx @orderly.network/i18n json2csv <
|
|
246
|
+
npx @orderly.network/i18n json2csv <inputDir> <output>
|
|
171
247
|
```
|
|
172
248
|
|
|
173
249
|
Example:
|
|
174
250
|
|
|
175
251
|
```bash
|
|
176
|
-
npx @orderly.network/i18n json2csv ./
|
|
252
|
+
npx @orderly.network/i18n json2csv ./locales ./dist/locale.csv
|
|
177
253
|
```
|
|
178
254
|
|
|
179
255
|
### diffcsv
|
|
@@ -190,30 +266,44 @@ Example:
|
|
|
190
266
|
npx @orderly.network/i18n diffcsv ./dist/locale1.csv ./dist/locale2.csv
|
|
191
267
|
```
|
|
192
268
|
|
|
193
|
-
###
|
|
269
|
+
### fillJson
|
|
194
270
|
|
|
195
|
-
|
|
271
|
+
Fill values from an input locale JSON file and generate a new locale JSON file.
|
|
196
272
|
|
|
197
273
|
```bash
|
|
198
|
-
npx @orderly.network/i18n
|
|
274
|
+
npx @orderly.network/i18n fillJson <input> <output>
|
|
199
275
|
```
|
|
200
276
|
|
|
201
277
|
Example:
|
|
202
278
|
|
|
203
279
|
```bash
|
|
204
|
-
npx @orderly.network/i18n
|
|
280
|
+
npx @orderly.network/i18n fillJson ./src/locale/zh.json ./dist/locale/zh.json
|
|
205
281
|
```
|
|
206
282
|
|
|
207
|
-
###
|
|
283
|
+
### separateJson
|
|
208
284
|
|
|
209
|
-
|
|
285
|
+
Separate JSON files into default and extend key values based on a specified key.
|
|
210
286
|
|
|
211
287
|
```bash
|
|
212
|
-
npx @orderly.network/i18n
|
|
288
|
+
npx @orderly.network/i18n separateJson <inputDir> <outputDir> <separateKey>
|
|
213
289
|
```
|
|
214
290
|
|
|
215
291
|
Example:
|
|
216
292
|
|
|
217
293
|
```bash
|
|
218
|
-
npx @orderly.network/i18n
|
|
294
|
+
npx @orderly.network/i18n separateJson ./locales ./dist/locales extend
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### mergeJson
|
|
298
|
+
|
|
299
|
+
Merge default and extend JSON files back into one file.
|
|
300
|
+
|
|
301
|
+
```bash
|
|
302
|
+
npx @orderly.network/i18n mergeJson <inputDir> <outputDir>
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
Example:
|
|
306
|
+
|
|
307
|
+
```bash
|
|
308
|
+
npx @orderly.network/i18n mergeJson ./dist/locales1 ./dist/locales2
|
|
219
309
|
```
|
package/bin/cli.js
CHANGED
|
@@ -2,24 +2,35 @@
|
|
|
2
2
|
|
|
3
3
|
const yargs = require("yargs/yargs");
|
|
4
4
|
const { hideBin } = require("yargs/helpers");
|
|
5
|
-
const { generateCsv } = require("../script/generateCsv");
|
|
5
|
+
// const { generateCsv } = require("../script/generateCsv");
|
|
6
6
|
const { json2csv } = require("../script/json2csv");
|
|
7
7
|
const { csv2json } = require("../script/csv2json");
|
|
8
8
|
const { diffCsv } = require("../script/diffCsv");
|
|
9
9
|
const { fillJson } = require("../script/fillJson");
|
|
10
|
+
const { separateJson } = require("../script/separateJson");
|
|
11
|
+
const { mergeJson } = require("../script/mergeJson");
|
|
10
12
|
main();
|
|
11
13
|
|
|
12
14
|
async function main() {
|
|
13
15
|
const argv = getArgv();
|
|
14
16
|
|
|
15
|
-
const {
|
|
17
|
+
const {
|
|
18
|
+
_,
|
|
19
|
+
input,
|
|
20
|
+
output,
|
|
21
|
+
oldFile,
|
|
22
|
+
newFile,
|
|
23
|
+
inputDir,
|
|
24
|
+
outputDir,
|
|
25
|
+
separateKey,
|
|
26
|
+
} = argv;
|
|
16
27
|
|
|
17
28
|
const command = _[0];
|
|
18
29
|
// console.log("argv", argv);
|
|
19
30
|
|
|
20
31
|
switch (command) {
|
|
21
32
|
case "json2csv":
|
|
22
|
-
await json2csv(
|
|
33
|
+
await json2csv(inputDir, output);
|
|
23
34
|
break;
|
|
24
35
|
case "csv2json":
|
|
25
36
|
await csv2json(input, outputDir);
|
|
@@ -27,12 +38,18 @@ async function main() {
|
|
|
27
38
|
case "diffcsv":
|
|
28
39
|
await diffCsv(oldFile, newFile);
|
|
29
40
|
break;
|
|
30
|
-
case "generateCsv":
|
|
31
|
-
|
|
32
|
-
|
|
41
|
+
// case "generateCsv":
|
|
42
|
+
// await generateCsv(output);
|
|
43
|
+
// break;
|
|
33
44
|
case "fillJson":
|
|
34
45
|
await fillJson(input, output);
|
|
35
46
|
break;
|
|
47
|
+
case "separateJson":
|
|
48
|
+
await separateJson(inputDir, outputDir, separateKey);
|
|
49
|
+
break;
|
|
50
|
+
case "mergeJson":
|
|
51
|
+
await mergeJson(inputDir, outputDir);
|
|
52
|
+
break;
|
|
36
53
|
default:
|
|
37
54
|
console.log("Invalid command");
|
|
38
55
|
break;
|
|
@@ -77,13 +94,13 @@ function getArgv() {
|
|
|
77
94
|
|
|
78
95
|
// json2csv command
|
|
79
96
|
.command(
|
|
80
|
-
"json2csv <
|
|
97
|
+
"json2csv <inputDir> <output>",
|
|
81
98
|
"Convert locale JSON files to a locale CSV file",
|
|
82
99
|
(yargs) => {
|
|
83
100
|
return yargs
|
|
84
|
-
.positional("
|
|
101
|
+
.positional("inputDir", {
|
|
85
102
|
describe:
|
|
86
|
-
"
|
|
103
|
+
"Input directory for locale JSON files (all JSON files in the directory will be converted)",
|
|
87
104
|
type: "string",
|
|
88
105
|
demandOption: true,
|
|
89
106
|
})
|
|
@@ -94,11 +111,8 @@ function getArgv() {
|
|
|
94
111
|
});
|
|
95
112
|
},
|
|
96
113
|
(argv) => {
|
|
97
|
-
const inputFiles = argv.input.split(","); // Parse multiple input files
|
|
98
114
|
console.log(
|
|
99
|
-
`Converting locale JSON files: ${
|
|
100
|
-
", "
|
|
101
|
-
)} to locale CSV: ${argv.output}`
|
|
115
|
+
`Converting locale JSON files: ${argv.inputDir} to locale CSV: ${argv.output}`
|
|
102
116
|
);
|
|
103
117
|
}
|
|
104
118
|
)
|
|
@@ -128,21 +142,21 @@ function getArgv() {
|
|
|
128
142
|
)
|
|
129
143
|
|
|
130
144
|
// generateCsv command
|
|
131
|
-
.command(
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
)
|
|
145
|
+
// .command(
|
|
146
|
+
// "generateCsv <output>",
|
|
147
|
+
// "Generate a locale CSV file",
|
|
148
|
+
// (yargs) => {
|
|
149
|
+
// return yargs.positional("output", {
|
|
150
|
+
// describe: "Output path for the locale CSV file",
|
|
151
|
+
// type: "string",
|
|
152
|
+
// // Required
|
|
153
|
+
// demandOption: true,
|
|
154
|
+
// });
|
|
155
|
+
// },
|
|
156
|
+
// (argv) => {
|
|
157
|
+
// console.log(`Generating locale CSV file at: ${argv.output}`);
|
|
158
|
+
// }
|
|
159
|
+
// )
|
|
146
160
|
|
|
147
161
|
// fillJson command
|
|
148
162
|
.command(
|
|
@@ -166,7 +180,61 @@ function getArgv() {
|
|
|
166
180
|
`Filling values from the input locale JSON file: ${argv.input} and generating a new locale JSON file: ${argv.output}`
|
|
167
181
|
);
|
|
168
182
|
}
|
|
169
|
-
)
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
// separateJson command
|
|
186
|
+
.command(
|
|
187
|
+
"separateJson <inputDir> <outputDir> <separateKey>",
|
|
188
|
+
"Separate json file default and extend key values based on the key",
|
|
189
|
+
(yargs) => {
|
|
190
|
+
return yargs
|
|
191
|
+
.positional("inputDir", {
|
|
192
|
+
describe: "Input directory for locale JSON files",
|
|
193
|
+
type: "string",
|
|
194
|
+
demandOption: true,
|
|
195
|
+
})
|
|
196
|
+
.positional("outputDir", {
|
|
197
|
+
describe: "Output directory for locale JSON files",
|
|
198
|
+
type: "string",
|
|
199
|
+
demandOption: true,
|
|
200
|
+
})
|
|
201
|
+
.positional("separateKey", {
|
|
202
|
+
describe: "Key to separate the json files",
|
|
203
|
+
type: "string",
|
|
204
|
+
demandOption: true,
|
|
205
|
+
});
|
|
206
|
+
},
|
|
207
|
+
(argv) => {
|
|
208
|
+
console.log(
|
|
209
|
+
`Separating json files into multiple files: ${argv.inputDir} to ${argv.outputDir} with key: ${argv.key}`
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
// mergeJson command
|
|
215
|
+
.command(
|
|
216
|
+
"mergeJson <inputDir> <outputDir>",
|
|
217
|
+
"Merge default and extend JSON files back into one file",
|
|
218
|
+
(yargs) => {
|
|
219
|
+
return yargs
|
|
220
|
+
.positional("inputDir", {
|
|
221
|
+
describe:
|
|
222
|
+
"Input directory containing both default and extend JSON files",
|
|
223
|
+
type: "string",
|
|
224
|
+
demandOption: true,
|
|
225
|
+
})
|
|
226
|
+
.positional("outputDir", {
|
|
227
|
+
describe: "Output directory for merged JSON files",
|
|
228
|
+
type: "string",
|
|
229
|
+
demandOption: true,
|
|
230
|
+
});
|
|
231
|
+
},
|
|
232
|
+
(argv) => {
|
|
233
|
+
console.log(
|
|
234
|
+
`Merging JSON files from ${argv.inputDir} to ${argv.outputDir}`
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
);
|
|
170
238
|
|
|
171
|
-
return argv;
|
|
239
|
+
return argv.argv;
|
|
172
240
|
}
|