@kodiak-finance/orderly-i18n 2.7.4
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 +334 -0
- package/bin/cli.js +240 -0
- package/dist/constant.d.mts +2 -0
- package/dist/constant.d.ts +2 -0
- package/dist/constant.js +12 -0
- package/dist/constant.js.map +1 -0
- package/dist/constant.mjs +5 -0
- package/dist/constant.mjs.map +1 -0
- package/dist/index.d.mts +44 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.js +49 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +13 -0
- package/dist/index.mjs.map +1 -0
- package/dist/locale.csv +979 -0
- package/dist/locales/de.json +980 -0
- package/dist/locales/en.json +980 -0
- package/dist/locales/es.json +980 -0
- package/dist/locales/fr.json +980 -0
- package/dist/locales/id.json +980 -0
- package/dist/locales/it.json +980 -0
- package/dist/locales/ja.json +980 -0
- package/dist/locales/ko.json +980 -0
- package/dist/locales/nl.json +980 -0
- package/dist/locales/pl.json +980 -0
- package/dist/locales/pt.json +980 -0
- package/dist/locales/ru.json +980 -0
- package/dist/locales/tr.json +980 -0
- package/dist/locales/uk.json +980 -0
- package/dist/locales/vi.json +980 -0
- package/dist/locales/zh.json +980 -0
- package/dist/types-Bcx1nSla.d.ts +1078 -0
- package/dist/utils.d.mts +64 -0
- package/dist/utils.d.ts +64 -0
- package/dist/utils.js +17 -0
- package/dist/utils.js.map +1 -0
- package/dist/utils.mjs +8 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +75 -0
- package/script/copyLocales.js +11 -0
- package/script/csv2json.js +28 -0
- package/script/diffCsv.js +175 -0
- package/script/fillJson.js +33 -0
- package/script/generateCsv.js +36 -0
- package/script/generateEnJson.js +11 -0
- package/script/generateMissingKeys.js +48 -0
- package/script/json-csv-converter.js +201 -0
- package/script/json2csv.js +38 -0
- package/script/mergeJson.js +62 -0
- package/script/separateJson.js +50 -0
- package/script/utils.js +88 -0
package/README.md
ADDED
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
# @orderly.network/i18n
|
|
2
|
+
|
|
3
|
+
Internationalization and cli tools for Orderly SDK. Based on i18next ecosystem.
|
|
4
|
+
|
|
5
|
+
## Integration Guide
|
|
6
|
+
|
|
7
|
+
Follow these steps to integrate localization support in your app using Orderly SDK:
|
|
8
|
+
|
|
9
|
+
### 1. Wrap Your App with LocaleProvider
|
|
10
|
+
|
|
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
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
import { LocaleProvider } from "@orderly.network/i18n";
|
|
15
|
+
|
|
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 **16 locales**
|
|
30
|
+
|
|
31
|
+
| Locale Code | Language |
|
|
32
|
+
| ----------- | ---------- |
|
|
33
|
+
| `en` | English |
|
|
34
|
+
| `zh` | Chinese |
|
|
35
|
+
| `ja` | Japanese |
|
|
36
|
+
| `es` | Spanish |
|
|
37
|
+
| `ko` | Korean |
|
|
38
|
+
| `vi` | Vietnamese |
|
|
39
|
+
| `de` | German |
|
|
40
|
+
| `fr` | French |
|
|
41
|
+
| `ru` | Russian |
|
|
42
|
+
| `id` | Indonesian |
|
|
43
|
+
| `tr` | Turkish |
|
|
44
|
+
| `it` | Italian |
|
|
45
|
+
| `pt` | Portuguese |
|
|
46
|
+
| `uk` | Ukrainian |
|
|
47
|
+
| `pl` | Polish |
|
|
48
|
+
| `nl` | Dutch |
|
|
49
|
+
|
|
50
|
+
#### CSV for Easy Translation
|
|
51
|
+
|
|
52
|
+
- Each release generates a `dist/locale.csv` file to simplify translation workflows.
|
|
53
|
+
- We provide a CLI tool to convert between CSV and JSON formats.
|
|
54
|
+
|
|
55
|
+
### 3. Extending Locale Files
|
|
56
|
+
|
|
57
|
+
You can localize both the SDK UI and your own custom components.
|
|
58
|
+
|
|
59
|
+
- When adding custom keys, prefix them with `extend.` to avoid conflicts with default keys.
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"extend.custom.button.label": "My Custom Button"
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Example
|
|
68
|
+
|
|
69
|
+
Here's a complete example of how to set up the i18n integration:
|
|
70
|
+
|
|
71
|
+
### Async load locale files
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { FC, ReactNode } from "react";
|
|
75
|
+
import { WalletConnectorProvider } from "@orderly.network/wallet-connector";
|
|
76
|
+
import { OrderlyAppProvider } from "@orderly.network/react-app";
|
|
77
|
+
import { LocaleProvider, LocaleEnum, LocaleCode } from "@orderly.network/i18n";
|
|
78
|
+
|
|
79
|
+
const OrderlyProvider: FC<{ children: ReactNode }> = (props) => {
|
|
80
|
+
const onLanguageChanged = async (lang: LocaleCode) => {};
|
|
81
|
+
|
|
82
|
+
// please copy build-in locale files (@orderly.network/i18n/locales) to you public/locales
|
|
83
|
+
// and copy you extend locale files to public/locales/extend
|
|
84
|
+
const loadPath = (lang: LocaleCode) => {
|
|
85
|
+
if (lang === LocaleEnum.en) {
|
|
86
|
+
// because en is built-in, we need to load the en extend only
|
|
87
|
+
return `/locales/extend/${lang}.json`;
|
|
88
|
+
}
|
|
89
|
+
return [`/locales/${lang}.json`, `/locales/extend/${lang}.json`];
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<LocaleProvider
|
|
94
|
+
onLanguageChanged={onLanguageChanged}
|
|
95
|
+
backend={{ loadPath }}
|
|
96
|
+
>
|
|
97
|
+
<WalletConnectorProvider>
|
|
98
|
+
<OrderlyAppProvider
|
|
99
|
+
brokerId="orderly"
|
|
100
|
+
brokerName="Orderly"
|
|
101
|
+
networkId="testnet"
|
|
102
|
+
>
|
|
103
|
+
{props.children}
|
|
104
|
+
</OrderlyAppProvider>
|
|
105
|
+
</WalletConnectorProvider>
|
|
106
|
+
</LocaleProvider>
|
|
107
|
+
);
|
|
108
|
+
};
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Sync Load locale data
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
import { FC, ReactNode } from "react";
|
|
115
|
+
import { WalletConnectorProvider } from "@orderly.network/wallet-connector";
|
|
116
|
+
import { OrderlyAppProvider } from "@orderly.network/react-app";
|
|
117
|
+
import { LocaleProvider, LocaleCode, Resources } from "@orderly.network/i18n";
|
|
118
|
+
import zh from "@orderly.network/i18n/locales/zh.json";
|
|
119
|
+
import ja from "@orderly.network/i18n/locales/ja.json";
|
|
120
|
+
import ko from "@orderly.network/i18n/locales/ko.json";
|
|
121
|
+
|
|
122
|
+
// extend or overrides English translations
|
|
123
|
+
const extendEn = {
|
|
124
|
+
"extend.trading": "Trading",
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// extend or overrides chinese translations
|
|
128
|
+
const extendZh = {
|
|
129
|
+
"extend.trading": "交易",
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// extend or overrides japanese translations
|
|
133
|
+
const extendJa = {
|
|
134
|
+
"extend.trading": "取引",
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// extend or overrides korean translations
|
|
138
|
+
const extendKo = {
|
|
139
|
+
"extend.trading": "거래",
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// define language resources
|
|
143
|
+
const resources: Resources = {
|
|
144
|
+
en: extendEn,
|
|
145
|
+
zh: {
|
|
146
|
+
...zh,
|
|
147
|
+
...extendZh,
|
|
148
|
+
},
|
|
149
|
+
ja: {
|
|
150
|
+
...ja,
|
|
151
|
+
...extendJa,
|
|
152
|
+
},
|
|
153
|
+
ko: {
|
|
154
|
+
...ko,
|
|
155
|
+
...extendKo,
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
const OrderlyProvider: FC<{ children: ReactNode }> = (props) => {
|
|
160
|
+
const onLanguageChanged = (locale: LocaleCode) => {};
|
|
161
|
+
|
|
162
|
+
return (
|
|
163
|
+
<LocaleProvider resources={resources} onLanguageChanged={onLocaleChange}>
|
|
164
|
+
<WalletConnectorProvider>
|
|
165
|
+
<OrderlyAppProvider
|
|
166
|
+
brokerId="orderly"
|
|
167
|
+
brokerName="Orderly"
|
|
168
|
+
networkId="testnet"
|
|
169
|
+
>
|
|
170
|
+
{props.children}
|
|
171
|
+
</OrderlyAppProvider>
|
|
172
|
+
</WalletConnectorProvider>
|
|
173
|
+
</LocaleProvider>
|
|
174
|
+
);
|
|
175
|
+
};
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Add custom languages
|
|
179
|
+
|
|
180
|
+
We also support adding more custom languages
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
import { FC, ReactNode } from "react";
|
|
184
|
+
import { WalletConnectorProvider } from "@orderly.network/wallet-connector";
|
|
185
|
+
import { OrderlyAppProvider } from "@orderly.network/react-app";
|
|
186
|
+
import {
|
|
187
|
+
LocaleProvider,
|
|
188
|
+
Resources,
|
|
189
|
+
LocaleEnum,
|
|
190
|
+
LocaleCode,
|
|
191
|
+
Language,
|
|
192
|
+
} from "@orderly.network/i18n";
|
|
193
|
+
|
|
194
|
+
// japanese locale
|
|
195
|
+
const ja = {
|
|
196
|
+
"extend.ja": "日本語",
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
// korean locale
|
|
200
|
+
const ko = {
|
|
201
|
+
"extend.ko": "한국어",
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
// define language resources
|
|
205
|
+
const resources: Resources = {
|
|
206
|
+
ja,
|
|
207
|
+
ko,
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
// custom languages
|
|
211
|
+
const languages: Language[] = [
|
|
212
|
+
{ localCode: LocaleEnum.en, displayName: "English" },
|
|
213
|
+
{ localCode: LocaleEnum.ja, displayName: "日本語" },
|
|
214
|
+
{ localCode: LocaleEnum.ko, displayName: "한국어" },
|
|
215
|
+
];
|
|
216
|
+
|
|
217
|
+
const OrderlyProvider: FC<{ children: ReactNode }> = (props) => {
|
|
218
|
+
const onLanguageChanged = (locale: LocaleCode) => {};
|
|
219
|
+
|
|
220
|
+
return (
|
|
221
|
+
<LocaleProvider
|
|
222
|
+
resources={resources}
|
|
223
|
+
languages={languages}
|
|
224
|
+
onLanguageChanged={onLanguageChanged}
|
|
225
|
+
>
|
|
226
|
+
<WalletConnectorProvider>
|
|
227
|
+
<OrderlyAppProvider
|
|
228
|
+
brokerId="orderly"
|
|
229
|
+
brokerName="Orderly"
|
|
230
|
+
networkId="testnet"
|
|
231
|
+
>
|
|
232
|
+
{props.children}
|
|
233
|
+
</OrderlyAppProvider>
|
|
234
|
+
</WalletConnectorProvider>
|
|
235
|
+
</LocaleProvider>
|
|
236
|
+
);
|
|
237
|
+
};
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
## CLI
|
|
241
|
+
|
|
242
|
+
## Usage
|
|
243
|
+
|
|
244
|
+
The package provides a CLI tool for managing Internationalization files.
|
|
245
|
+
|
|
246
|
+
```bash
|
|
247
|
+
npx @orderly.network/i18n <command> [options]
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## Commands
|
|
251
|
+
|
|
252
|
+
### csv2json
|
|
253
|
+
|
|
254
|
+
Convert a locale CSV file to multiple locale JSON files.
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
npx @orderly.network/i18n csv2json <input> <outputDir>
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
Example:
|
|
261
|
+
|
|
262
|
+
```bash
|
|
263
|
+
npx @orderly.network/i18n csv2json ./dist/locale.csv ./dist/locales
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### json2csv
|
|
267
|
+
|
|
268
|
+
Convert multiple locale JSON files to a single locale CSV file.
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
npx @orderly.network/i18n json2csv <inputDir> <output>
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
Example:
|
|
275
|
+
|
|
276
|
+
```bash
|
|
277
|
+
npx @orderly.network/i18n json2csv ./locales ./dist/locale.csv
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### diffcsv
|
|
281
|
+
|
|
282
|
+
Compare two locale CSV files to find differences.
|
|
283
|
+
|
|
284
|
+
```bash
|
|
285
|
+
npx @orderly.network/i18n diffcsv <oldFile> <newFile>
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
Example:
|
|
289
|
+
|
|
290
|
+
```bash
|
|
291
|
+
npx @orderly.network/i18n diffcsv ./dist/locale1.csv ./dist/locale2.csv
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
### fillJson
|
|
295
|
+
|
|
296
|
+
Fill values from an input locale JSON file and generate a new locale JSON file.
|
|
297
|
+
|
|
298
|
+
```bash
|
|
299
|
+
npx @orderly.network/i18n fillJson <input> <output>
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
Example:
|
|
303
|
+
|
|
304
|
+
```bash
|
|
305
|
+
npx @orderly.network/i18n fillJson ./src/locale/zh.json ./dist/locale/zh.json
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
### separateJson
|
|
309
|
+
|
|
310
|
+
Separate JSON files into default and extend key values based on a specified key.
|
|
311
|
+
|
|
312
|
+
```bash
|
|
313
|
+
npx @orderly.network/i18n separateJson <inputDir> <outputDir> <separateKey>
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
Example:
|
|
317
|
+
|
|
318
|
+
```bash
|
|
319
|
+
npx @orderly.network/i18n separateJson ./locales ./dist/locales extend
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
### mergeJson
|
|
323
|
+
|
|
324
|
+
Merge default and extend JSON files back into one file.
|
|
325
|
+
|
|
326
|
+
```bash
|
|
327
|
+
npx @orderly.network/i18n mergeJson <inputDir> <outputDir>
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
Example:
|
|
331
|
+
|
|
332
|
+
```bash
|
|
333
|
+
npx @orderly.network/i18n mergeJson ./dist/locales1 ./dist/locales2
|
|
334
|
+
```
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const yargs = require("yargs/yargs");
|
|
4
|
+
const { hideBin } = require("yargs/helpers");
|
|
5
|
+
// const { generateCsv } = require("../script/generateCsv");
|
|
6
|
+
const { json2csv } = require("../script/json2csv");
|
|
7
|
+
const { csv2json } = require("../script/csv2json");
|
|
8
|
+
const { diffCsv } = require("../script/diffCsv");
|
|
9
|
+
const { fillJson } = require("../script/fillJson");
|
|
10
|
+
const { separateJson } = require("../script/separateJson");
|
|
11
|
+
const { mergeJson } = require("../script/mergeJson");
|
|
12
|
+
main();
|
|
13
|
+
|
|
14
|
+
async function main() {
|
|
15
|
+
const argv = getArgv();
|
|
16
|
+
|
|
17
|
+
const {
|
|
18
|
+
_,
|
|
19
|
+
input,
|
|
20
|
+
output,
|
|
21
|
+
oldFile,
|
|
22
|
+
newFile,
|
|
23
|
+
inputDir,
|
|
24
|
+
outputDir,
|
|
25
|
+
separateKey,
|
|
26
|
+
} = argv;
|
|
27
|
+
|
|
28
|
+
const command = _[0];
|
|
29
|
+
// console.log("argv", argv);
|
|
30
|
+
|
|
31
|
+
switch (command) {
|
|
32
|
+
case "json2csv":
|
|
33
|
+
await json2csv(inputDir, output);
|
|
34
|
+
break;
|
|
35
|
+
case "csv2json":
|
|
36
|
+
await csv2json(input, outputDir);
|
|
37
|
+
break;
|
|
38
|
+
case "diffcsv":
|
|
39
|
+
await diffCsv(oldFile, newFile);
|
|
40
|
+
break;
|
|
41
|
+
// case "generateCsv":
|
|
42
|
+
// await generateCsv(output);
|
|
43
|
+
// break;
|
|
44
|
+
case "fillJson":
|
|
45
|
+
await fillJson(input, output);
|
|
46
|
+
break;
|
|
47
|
+
case "separateJson":
|
|
48
|
+
await separateJson(inputDir, outputDir, separateKey);
|
|
49
|
+
break;
|
|
50
|
+
case "mergeJson":
|
|
51
|
+
await mergeJson(inputDir, outputDir);
|
|
52
|
+
break;
|
|
53
|
+
default:
|
|
54
|
+
console.log("Invalid command");
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function getArgv() {
|
|
60
|
+
const argv = yargs(hideBin(process.argv))
|
|
61
|
+
.scriptName("")
|
|
62
|
+
.usage("i18n locale tools")
|
|
63
|
+
.usage("$0 <command> [options]")
|
|
64
|
+
.strict()
|
|
65
|
+
// Error if no subcommand is provided
|
|
66
|
+
.demandCommand(1, "Please provide a valid subcommand")
|
|
67
|
+
.help()
|
|
68
|
+
// Add `-h` as an alias for `--help`
|
|
69
|
+
.alias("h", "help")
|
|
70
|
+
|
|
71
|
+
// csv2json command
|
|
72
|
+
.command(
|
|
73
|
+
"csv2json <input> <outputDir>",
|
|
74
|
+
"Convert locale CSV to multiple locale JSON files",
|
|
75
|
+
(yargs) => {
|
|
76
|
+
return yargs
|
|
77
|
+
.positional("input", {
|
|
78
|
+
describe: "Input path for the locale CSV file",
|
|
79
|
+
type: "string",
|
|
80
|
+
demandOption: true,
|
|
81
|
+
})
|
|
82
|
+
.positional("outputDir", {
|
|
83
|
+
describe: "Output directory for locale JSON files",
|
|
84
|
+
type: "string",
|
|
85
|
+
demandOption: true,
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
(argv) => {
|
|
89
|
+
console.log(
|
|
90
|
+
`Converting ${argv.input} to locale JSON files, output directory: ${argv.outputDir}`
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
// json2csv command
|
|
96
|
+
.command(
|
|
97
|
+
"json2csv <inputDir> <output>",
|
|
98
|
+
"Convert locale JSON files to a locale CSV file",
|
|
99
|
+
(yargs) => {
|
|
100
|
+
return yargs
|
|
101
|
+
.positional("inputDir", {
|
|
102
|
+
describe:
|
|
103
|
+
"Input directory for locale JSON files (all JSON files in the directory will be converted)",
|
|
104
|
+
type: "string",
|
|
105
|
+
demandOption: true,
|
|
106
|
+
})
|
|
107
|
+
.positional("output", {
|
|
108
|
+
describe: "Output path for the locale CSV file",
|
|
109
|
+
type: "string",
|
|
110
|
+
demandOption: true,
|
|
111
|
+
});
|
|
112
|
+
},
|
|
113
|
+
(argv) => {
|
|
114
|
+
console.log(
|
|
115
|
+
`Converting locale JSON files: ${argv.inputDir} to locale CSV: ${argv.output}`
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
// diffcsv command
|
|
121
|
+
.command(
|
|
122
|
+
"diffcsv <oldFile> <newFile>",
|
|
123
|
+
"Compare two locale CSV files",
|
|
124
|
+
(yargs) => {
|
|
125
|
+
return yargs
|
|
126
|
+
.positional("oldFile", {
|
|
127
|
+
describe: "Path to the first locale CSV file",
|
|
128
|
+
type: "string",
|
|
129
|
+
demandOption: true,
|
|
130
|
+
})
|
|
131
|
+
.positional("newFile", {
|
|
132
|
+
describe: "Path to the second CSV file",
|
|
133
|
+
type: "string",
|
|
134
|
+
demandOption: true,
|
|
135
|
+
});
|
|
136
|
+
},
|
|
137
|
+
(argv) => {
|
|
138
|
+
console.log(
|
|
139
|
+
`Comparing locale CSV files: ${argv.oldFile} and ${argv.newFile}`
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
// generateCsv command
|
|
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
|
+
// )
|
|
160
|
+
|
|
161
|
+
// fillJson command
|
|
162
|
+
.command(
|
|
163
|
+
"fillJson <input> <output>",
|
|
164
|
+
"Fill values from the input locale JSON file and generate a new locale JSON file",
|
|
165
|
+
(yargs) => {
|
|
166
|
+
return yargs
|
|
167
|
+
.positional("input", {
|
|
168
|
+
describe: "Input path for the locale JSON file",
|
|
169
|
+
type: "string",
|
|
170
|
+
demandOption: true,
|
|
171
|
+
})
|
|
172
|
+
.positional("output", {
|
|
173
|
+
describe: "Output path for the locale JSON file",
|
|
174
|
+
type: "string",
|
|
175
|
+
demandOption: true,
|
|
176
|
+
});
|
|
177
|
+
},
|
|
178
|
+
(argv) => {
|
|
179
|
+
console.log(
|
|
180
|
+
`Filling values from the input locale JSON file: ${argv.input} and generating a new locale JSON file: ${argv.output}`
|
|
181
|
+
);
|
|
182
|
+
}
|
|
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
|
+
);
|
|
238
|
+
|
|
239
|
+
return argv.argv;
|
|
240
|
+
}
|
package/dist/constant.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var e=(a=>(a.en="en",a.zh="zh",a.ja="ja",a.es="es",a.ko="ko",a.vi="vi",a.de="de",a.fr="fr",a.ru="ru",a.id="id",a.tr="tr",a.it="it",a.pt="pt",a.uk="uk",a.pl="pl",a.nl="nl",a))(e||{}),l=[{localCode:"en",displayName:"English"},{localCode:"zh",displayName:"\u4E2D\u6587"},{localCode:"ja",displayName:"\u65E5\u672C\u8A9E"},{localCode:"es",displayName:"Espa\xF1ol"},{localCode:"ko",displayName:"\uD55C\uAD6D\uC5B4"},{localCode:"vi",displayName:"Ti\u1EBFng Vi\u1EC7t"},{localCode:"de",displayName:"Deutsch"},{localCode:"fr",displayName:"Fran\xE7ais"},{localCode:"ru",displayName:"\u0420\u0443\u0441\u0441\u043A\u0438\u0439"},{localCode:"id",displayName:"Bahasa Indonesia"},{localCode:"tr",displayName:"T\xFCrk\xE7e"},{localCode:"it",displayName:"Italiano"},{localCode:"pt",displayName:"Portugu\xEAs"},{localCode:"uk",displayName:"\u0423\u043A\u0440\u0430\u0457\u043D\u0441\u044C\u043A\u0430"},{localCode:"pl",displayName:"Polski"},{localCode:"nl",displayName:"Nederlands"}],o="en",d="translation",i="orderly_i18nLng",s="orderly_i18nLng";
|
|
4
|
+
|
|
5
|
+
exports.LocaleEnum = e;
|
|
6
|
+
exports.defaultLanguages = l;
|
|
7
|
+
exports.defaultLng = o;
|
|
8
|
+
exports.defaultNS = d;
|
|
9
|
+
exports.i18nCookieKey = s;
|
|
10
|
+
exports.i18nLocalStorageKey = i;
|
|
11
|
+
//# sourceMappingURL=out.js.map
|
|
12
|
+
//# sourceMappingURL=constant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/constant.ts"],"names":["LocaleEnum","defaultLanguages","defaultLng","defaultNS","i18nLocalStorageKey","i18nCookieKey"],"mappings":"AAEO,IAAKA,OAEVA,EAAA,GAAK,KAELA,EAAA,GAAK,KAELA,EAAA,GAAK,KAELA,EAAA,GAAK,KAELA,EAAA,GAAK,KAELA,EAAA,GAAK,KAELA,EAAA,GAAK,KAELA,EAAA,GAAK,KAELA,EAAA,GAAK,KAELA,EAAA,GAAK,KAELA,EAAA,GAAK,KAELA,EAAA,GAAK,KAELA,EAAA,GAAK,KAELA,EAAA,GAAK,KAELA,EAAA,GAAK,KAELA,EAAA,GAAK,KAhCKA,OAAA,IAmCCC,EAA+B,CAC1C,CAAE,UAAW,KAAe,YAAa,SAAU,EACnD,CAAE,UAAW,KAAe,YAAa,cAAK,EAC9C,CAAE,UAAW,KAAe,YAAa,oBAAM,EAC/C,CAAE,UAAW,KAAe,YAAa,YAAU,EACnD,CAAE,UAAW,KAAe,YAAa,oBAAM,EAC/C,CAAE,UAAW,KAAe,YAAa,sBAAa,EACtD,CAAE,UAAW,KAAe,YAAa,SAAU,EACnD,CAAE,UAAW,KAAe,YAAa,aAAW,EACpD,CAAE,UAAW,KAAe,YAAa,4CAAU,EACnD,CAAE,UAAW,KAAe,YAAa,kBAAmB,EAC5D,CAAE,UAAW,KAAe,YAAa,cAAS,EAClD,CAAE,UAAW,KAAe,YAAa,UAAW,EACpD,CAAE,UAAW,KAAe,YAAa,cAAY,EACrD,CAAE,UAAW,KAAe,YAAa,8DAAa,EACtD,CAAE,UAAW,KAAe,YAAa,QAAS,EAClD,CAAE,UAAW,KAAe,YAAa,YAAa,CACxD,EACaC,EAAa,KACbC,EAAY,cAEZC,EAAsB,kBAGtBC,EAAgB","sourcesContent":["import { Language } from \"./context\";\n\nexport enum LocaleEnum {\n /** English */\n en = \"en\",\n /** Chinese */\n zh = \"zh\",\n /** Japanese */\n ja = \"ja\",\n /** Spanish */\n es = \"es\",\n /** Korean */\n ko = \"ko\",\n /** Vietnamese */\n vi = \"vi\",\n /** German */\n de = \"de\",\n /** French */\n fr = \"fr\",\n /** Russian */\n ru = \"ru\",\n /** Indonesian */\n id = \"id\",\n /** Turkish */\n tr = \"tr\",\n /** Italian */\n it = \"it\",\n /** Portuguese */\n pt = \"pt\",\n /** Ukrainian */\n uk = \"uk\",\n /** Polish */\n pl = \"pl\",\n /** Dutch */\n nl = \"nl\",\n}\n\nexport const defaultLanguages: Language[] = [\n { localCode: LocaleEnum.en, displayName: \"English\" }, // English\n { localCode: LocaleEnum.zh, displayName: \"中文\" }, // Chinese\n { localCode: LocaleEnum.ja, displayName: \"日本語\" }, // Japanese\n { localCode: LocaleEnum.es, displayName: \"Español\" }, // Spanish\n { localCode: LocaleEnum.ko, displayName: \"한국어\" }, // Korean\n { localCode: LocaleEnum.vi, displayName: \"Tiếng Việt\" }, // Vietnamese\n { localCode: LocaleEnum.de, displayName: \"Deutsch\" }, // German\n { localCode: LocaleEnum.fr, displayName: \"Français\" }, // French\n { localCode: LocaleEnum.ru, displayName: \"Русский\" }, // Russian\n { localCode: LocaleEnum.id, displayName: \"Bahasa Indonesia\" }, // Indonesian\n { localCode: LocaleEnum.tr, displayName: \"Türkçe\" }, // Turkish\n { localCode: LocaleEnum.it, displayName: \"Italiano\" }, // Italian\n { localCode: LocaleEnum.pt, displayName: \"Português\" }, // Portuguese\n { localCode: LocaleEnum.uk, displayName: \"Українська\" }, // Ukrainian\n { localCode: LocaleEnum.pl, displayName: \"Polski\" }, // Polish\n { localCode: LocaleEnum.nl, displayName: \"Nederlands\" }, // Dutch\n];\nexport const defaultLng = LocaleEnum.en;\nexport const defaultNS = \"translation\";\n\nexport const i18nLocalStorageKey = \"orderly_i18nLng\";\n\n// preferred-language\nexport const i18nCookieKey = \"orderly_i18nLng\";\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
var e=(a=>(a.en="en",a.zh="zh",a.ja="ja",a.es="es",a.ko="ko",a.vi="vi",a.de="de",a.fr="fr",a.ru="ru",a.id="id",a.tr="tr",a.it="it",a.pt="pt",a.uk="uk",a.pl="pl",a.nl="nl",a))(e||{}),l=[{localCode:"en",displayName:"English"},{localCode:"zh",displayName:"\u4E2D\u6587"},{localCode:"ja",displayName:"\u65E5\u672C\u8A9E"},{localCode:"es",displayName:"Espa\xF1ol"},{localCode:"ko",displayName:"\uD55C\uAD6D\uC5B4"},{localCode:"vi",displayName:"Ti\u1EBFng Vi\u1EC7t"},{localCode:"de",displayName:"Deutsch"},{localCode:"fr",displayName:"Fran\xE7ais"},{localCode:"ru",displayName:"\u0420\u0443\u0441\u0441\u043A\u0438\u0439"},{localCode:"id",displayName:"Bahasa Indonesia"},{localCode:"tr",displayName:"T\xFCrk\xE7e"},{localCode:"it",displayName:"Italiano"},{localCode:"pt",displayName:"Portugu\xEAs"},{localCode:"uk",displayName:"\u0423\u043A\u0440\u0430\u0457\u043D\u0441\u044C\u043A\u0430"},{localCode:"pl",displayName:"Polski"},{localCode:"nl",displayName:"Nederlands"}],o="en",d="translation",i="orderly_i18nLng",s="orderly_i18nLng";
|
|
2
|
+
|
|
3
|
+
export { e as LocaleEnum, l as defaultLanguages, o as defaultLng, d as defaultNS, s as i18nCookieKey, i as i18nLocalStorageKey };
|
|
4
|
+
//# sourceMappingURL=out.js.map
|
|
5
|
+
//# sourceMappingURL=constant.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/constant.ts"],"names":["LocaleEnum","defaultLanguages","defaultLng","defaultNS","i18nLocalStorageKey","i18nCookieKey"],"mappings":"AAEO,IAAKA,OAEVA,EAAA,GAAK,KAELA,EAAA,GAAK,KAELA,EAAA,GAAK,KAELA,EAAA,GAAK,KAELA,EAAA,GAAK,KAELA,EAAA,GAAK,KAELA,EAAA,GAAK,KAELA,EAAA,GAAK,KAELA,EAAA,GAAK,KAELA,EAAA,GAAK,KAELA,EAAA,GAAK,KAELA,EAAA,GAAK,KAELA,EAAA,GAAK,KAELA,EAAA,GAAK,KAELA,EAAA,GAAK,KAELA,EAAA,GAAK,KAhCKA,OAAA,IAmCCC,EAA+B,CAC1C,CAAE,UAAW,KAAe,YAAa,SAAU,EACnD,CAAE,UAAW,KAAe,YAAa,cAAK,EAC9C,CAAE,UAAW,KAAe,YAAa,oBAAM,EAC/C,CAAE,UAAW,KAAe,YAAa,YAAU,EACnD,CAAE,UAAW,KAAe,YAAa,oBAAM,EAC/C,CAAE,UAAW,KAAe,YAAa,sBAAa,EACtD,CAAE,UAAW,KAAe,YAAa,SAAU,EACnD,CAAE,UAAW,KAAe,YAAa,aAAW,EACpD,CAAE,UAAW,KAAe,YAAa,4CAAU,EACnD,CAAE,UAAW,KAAe,YAAa,kBAAmB,EAC5D,CAAE,UAAW,KAAe,YAAa,cAAS,EAClD,CAAE,UAAW,KAAe,YAAa,UAAW,EACpD,CAAE,UAAW,KAAe,YAAa,cAAY,EACrD,CAAE,UAAW,KAAe,YAAa,8DAAa,EACtD,CAAE,UAAW,KAAe,YAAa,QAAS,EAClD,CAAE,UAAW,KAAe,YAAa,YAAa,CACxD,EACaC,EAAa,KACbC,EAAY,cAEZC,EAAsB,kBAGtBC,EAAgB","sourcesContent":["import { Language } from \"./context\";\n\nexport enum LocaleEnum {\n /** English */\n en = \"en\",\n /** Chinese */\n zh = \"zh\",\n /** Japanese */\n ja = \"ja\",\n /** Spanish */\n es = \"es\",\n /** Korean */\n ko = \"ko\",\n /** Vietnamese */\n vi = \"vi\",\n /** German */\n de = \"de\",\n /** French */\n fr = \"fr\",\n /** Russian */\n ru = \"ru\",\n /** Indonesian */\n id = \"id\",\n /** Turkish */\n tr = \"tr\",\n /** Italian */\n it = \"it\",\n /** Portuguese */\n pt = \"pt\",\n /** Ukrainian */\n uk = \"uk\",\n /** Polish */\n pl = \"pl\",\n /** Dutch */\n nl = \"nl\",\n}\n\nexport const defaultLanguages: Language[] = [\n { localCode: LocaleEnum.en, displayName: \"English\" }, // English\n { localCode: LocaleEnum.zh, displayName: \"中文\" }, // Chinese\n { localCode: LocaleEnum.ja, displayName: \"日本語\" }, // Japanese\n { localCode: LocaleEnum.es, displayName: \"Español\" }, // Spanish\n { localCode: LocaleEnum.ko, displayName: \"한국어\" }, // Korean\n { localCode: LocaleEnum.vi, displayName: \"Tiếng Việt\" }, // Vietnamese\n { localCode: LocaleEnum.de, displayName: \"Deutsch\" }, // German\n { localCode: LocaleEnum.fr, displayName: \"Français\" }, // French\n { localCode: LocaleEnum.ru, displayName: \"Русский\" }, // Russian\n { localCode: LocaleEnum.id, displayName: \"Bahasa Indonesia\" }, // Indonesian\n { localCode: LocaleEnum.tr, displayName: \"Türkçe\" }, // Turkish\n { localCode: LocaleEnum.it, displayName: \"Italiano\" }, // Italian\n { localCode: LocaleEnum.pt, displayName: \"Português\" }, // Portuguese\n { localCode: LocaleEnum.uk, displayName: \"Українська\" }, // Ukrainian\n { localCode: LocaleEnum.pl, displayName: \"Polski\" }, // Polish\n { localCode: LocaleEnum.nl, displayName: \"Nederlands\" }, // Dutch\n];\nexport const defaultLng = LocaleEnum.en;\nexport const defaultNS = \"translation\";\n\nexport const i18nLocalStorageKey = \"orderly_i18nLng\";\n\n// preferred-language\nexport const i18nCookieKey = \"orderly_i18nLng\";\n"]}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { L as LocaleCode, R as Resources, a as LocaleContextState } from './types-Bcx1nSla.js';
|
|
2
|
+
export { b as Language, d as LocaleContext, 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 useLocaleContext } from './types-Bcx1nSla.js';
|
|
3
|
+
import * as react_i18next from 'react-i18next';
|
|
4
|
+
import { I18nextProviderProps, FallbackNs, UseTranslationOptions } from 'react-i18next';
|
|
5
|
+
export * from 'react-i18next';
|
|
6
|
+
import * as i18next from 'i18next';
|
|
7
|
+
import { FlatNamespace, KeyPrefix } from 'i18next';
|
|
8
|
+
export { createInstance, default as i18next } from 'i18next';
|
|
9
|
+
import { ReactNode } from 'react';
|
|
10
|
+
import { $Tuple } from 'react-i18next/helpers';
|
|
11
|
+
export { generatePath, getLocalePathFromPathname, parseI18nLang, removeLangPrefix } from './utils.mjs';
|
|
12
|
+
|
|
13
|
+
declare const i18n: i18next.i18n;
|
|
14
|
+
|
|
15
|
+
type BackendOptions = {
|
|
16
|
+
loadPath: (lang: LocaleCode, ns: string) => string | string[];
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
type I18nProviderProps = Partial<I18nextProviderProps>;
|
|
20
|
+
declare const I18nProvider: React.FC<I18nProviderProps>;
|
|
21
|
+
type LocaleProviderProps = {
|
|
22
|
+
children: ReactNode;
|
|
23
|
+
locale?: LocaleCode;
|
|
24
|
+
resource?: Record<string, string>;
|
|
25
|
+
resources?: Resources;
|
|
26
|
+
/**
|
|
27
|
+
* supported languages, you can select supported languages from default languages
|
|
28
|
+
*/
|
|
29
|
+
supportedLanguages?: LocaleCode[];
|
|
30
|
+
/**
|
|
31
|
+
* @deprecated use onLanguageChanged instead, will be removed in next patch version
|
|
32
|
+
*/
|
|
33
|
+
onLocaleChange?: (locale: LocaleCode) => void;
|
|
34
|
+
/** optional conversion function to use to modify the detected language code */
|
|
35
|
+
convertDetectedLanguage?: (lang: string) => LocaleCode;
|
|
36
|
+
backend?: BackendOptions;
|
|
37
|
+
} & Partial<LocaleContextState>;
|
|
38
|
+
declare const LocaleProvider: React.FC<LocaleProviderProps>;
|
|
39
|
+
|
|
40
|
+
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>;
|
|
41
|
+
|
|
42
|
+
declare function useLocaleCode(): LocaleCode;
|
|
43
|
+
|
|
44
|
+
export { I18nProvider, type I18nProviderProps, LocaleCode, LocaleContextState, LocaleProvider, type LocaleProviderProps, Resources, i18n, useLocaleCode, useTranslation };
|