handlebars-i18n-cli 2.0.0 → 2.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 +18 -214
- package/README_programmatic.md +195 -0
- package/package.json +1 -1
- package/de.json +0 -72
- package/en.json +0 -5
- package/fi.json +0 -5
- package/my.json +0 -23
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ for [handlebars-i18n](https://github.com/fwalzel/handlebars-i18n.git) and other
|
|
|
8
8
|
* automatic translation of i18next JSON via [DeepL’s](https://www.deepl.com/en/pro-api/) free API
|
|
9
9
|
|
|
10
10
|
[](https://opensource.org/licenses/MIT)
|
|
11
|
-

|
|
12
12
|
[](https://github.com/fwalzel/handlebars-i18n-cli/actions/workflows/node.js.yml/badge.svg)
|
|
13
13
|
[](https://coveralls.io/github/fwalzel/handlebars-i18n-cli?branch=main)
|
|
14
14
|
[](https://snyk.io/test/github/fwalzel/handlebars-i18n-cli/badge.svg)
|
|
@@ -22,13 +22,11 @@ npm link handlebars-i18n-cli
|
|
|
22
22
|
|
|
23
23
|
If you do not link the package, you may run into the error `bash: i18n-collect: command not found`.
|
|
24
24
|
|
|
25
|
-
<p> </p>
|
|
26
|
-
|
|
27
25
|
## General Use
|
|
28
26
|
|
|
29
|
-
### 1. Language Key Extraction
|
|
27
|
+
### 1. Language Key Extraction: _i18n-collect_
|
|
30
28
|
|
|
31
|
-
|
|
29
|
+
#### Syntax:
|
|
32
30
|
|
|
33
31
|
```
|
|
34
32
|
i18n-collect <source> <target> <options...>
|
|
@@ -82,14 +80,16 @@ From a very simple template like this …
|
|
|
82
80
|
}
|
|
83
81
|
```
|
|
84
82
|
|
|
85
|
-
### 2. Automatic Translation via DeepL API
|
|
83
|
+
### 2. Automatic Translation via DeepL API: _i18n-deepl_
|
|
86
84
|
|
|
87
|
-
|
|
85
|
+
#### Syntax:
|
|
88
86
|
|
|
89
87
|
```
|
|
90
88
|
i18n-deepl translate <source> <target> <targetLang> <options...>
|
|
91
89
|
```
|
|
92
90
|
|
|
91
|
+
#### Example:
|
|
92
|
+
|
|
93
93
|
``` shell
|
|
94
94
|
i18n-deepl translate en.json fi.json fi
|
|
95
95
|
```
|
|
@@ -149,7 +149,13 @@ For one JSON file per language:
|
|
|
149
149
|
i18n-collect examples/templates/*.html examples/generated/translations.json --separateLngFiles --lng de,fr,en
|
|
150
150
|
```
|
|
151
151
|
|
|
152
|
-
##
|
|
152
|
+
## Programmatical Use
|
|
153
|
+
|
|
154
|
+
You can use `handlebars-i18n-cli` in a programmatical way too. For import and integration of the Javascript Functions see
|
|
155
|
+
[handlebars-i18n-cli Programmatical Use](README_programmatic.md).
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
## Detailed Description for Command _i18n-collect_
|
|
153
159
|
|
|
154
160
|
`<source>`
|
|
155
161
|
|
|
@@ -248,8 +254,7 @@ i18n-collect my-project/template.html my-project/translation.json --lng de,en,fr
|
|
|
248
254
|
```
|
|
249
255
|
|
|
250
256
|
Will generate three json files: **translation.de.json**, **translation.en.json**, and **translation.fn.json** each
|
|
251
|
-
holding
|
|
252
|
-
only the translation for their respective language. By default all translations are written to a single json file.
|
|
257
|
+
holding only the translation for their respective language. By default all translations are written to a single json file.
|
|
253
258
|
|
|
254
259
|
---
|
|
255
260
|
|
|
@@ -257,8 +262,7 @@ only the translation for their respective language. By default all translations
|
|
|
257
262
|
|
|
258
263
|
If you are not using handlebars-i18n for translations but a custom handlebars helper, you might be able to use
|
|
259
264
|
i18n-collect as well.Say your translation function has the name *t* instead of handlebars-i18n’s *__* (double
|
|
260
|
-
underscore)
|
|
261
|
-
and your template usage would look like
|
|
265
|
+
underscore) and your template usage would look like
|
|
262
266
|
|
|
263
267
|
```html
|
|
264
268
|
{{t myKeyNameToTranslation}}
|
|
@@ -290,7 +294,7 @@ handlebars-i18n-cli would look for *translation.de.json*, *translation.en.json*,
|
|
|
290
294
|
them. A language file that does not exist yet will be generated.
|
|
291
295
|
|
|
292
296
|
|
|
293
|
-
##
|
|
297
|
+
## Detailed Description for _i18n-deepl_ Commands
|
|
294
298
|
|
|
295
299
|
i18n-deepl is a command-line tool to translate i18next JSON files using the DeepL API. Below is a detailed guide to its
|
|
296
300
|
commands and usage. To use this tool, you need a valid DeepL API key. Set this key using the setAuth command or provide
|
|
@@ -383,213 +387,13 @@ i18n-deepl translate <source> <target> <targetLang> [options]
|
|
|
383
387
|
i18n-deepl translate ./source.json ./output.json fr --source-lang en --log
|
|
384
388
|
```
|
|
385
389
|
|
|
390
|
+
|
|
386
391
|
#### Output
|
|
387
392
|
|
|
388
393
|
```
|
|
389
394
|
Translation complete. See ./output.json for your results.
|
|
390
395
|
```
|
|
391
396
|
|
|
392
|
-
---
|
|
393
|
-
|
|
394
|
-
<p> </p>
|
|
395
|
-
|
|
396
|
-
## Programmatical Use
|
|
397
|
-
|
|
398
|
-
You can use the functions of `handlebars-i18n-cli` in a programatical way too, and make them part of your continuous integration.
|
|
399
|
-
|
|
400
|
-
---
|
|
401
|
-
|
|
402
|
-
### Specification for `i18nCollect` Function
|
|
403
|
-
|
|
404
|
-
#### Function Signature
|
|
405
|
-
|
|
406
|
-
```typescript
|
|
407
|
-
export function i18nCollect(
|
|
408
|
-
source: string,
|
|
409
|
-
target: string,
|
|
410
|
-
options?: opts
|
|
411
|
-
): Promise<true | void>;
|
|
412
|
-
```
|
|
413
|
-
|
|
414
|
-
#### Description
|
|
415
|
-
|
|
416
|
-
This function scans the source location for internationalization keys, processes them according to the provided options,
|
|
417
|
-
and writes them to the specified target location. It supports features like sorting keys alphabetically, updating
|
|
418
|
-
existing keys, and generating separate files for each language.
|
|
419
|
-
|
|
420
|
-
#### Parameters
|
|
421
|
-
|
|
422
|
-
**Positional Arguments**
|
|
423
|
-
|
|
424
|
-
| **Name** | **Type** | **Description** | **Example** |
|
|
425
|
-
|-----------|---------------|-----------------------------------------|---------------------------|
|
|
426
|
-
| `source` | `string` | Path to the source files. | `./src/template.html` |
|
|
427
|
-
| `target` | `string` | Path to the target files or directory. | `./src/translations.json` |
|
|
428
|
-
|
|
429
|
-
**Optional `options` Object Properties**
|
|
430
|
-
|
|
431
|
-
| **Name** | **Type** | **Description** | **Example** |
|
|
432
|
-
|--------------------|-----------------|-------------------------------------------------------------------|-----------------------|
|
|
433
|
-
| `alphabetical` | `boolean` | If `true`, sorts keys alphabetically. | `true` |
|
|
434
|
-
| `dryRun` | `boolean` | If `true`, performs a simulation without modifying files. | `false` |
|
|
435
|
-
| `lng` | `Array<string>`| List of language codes to process. | `["en", "de", "fr"]` |
|
|
436
|
-
| `log` | `boolean` | If `true`, enables detailed logging to the console. | `true` |
|
|
437
|
-
| `separateLngFiles` | `boolean` | If `true`, creates separate files for each language. | `true` |
|
|
438
|
-
| `translFunc` | `string` | Specifies a custom translation function name to look for in code. | `"t"` |
|
|
439
|
-
| `update` | `boolean` | If `true`, updates existing translation keys in the target file. | `true` |
|
|
440
|
-
|
|
441
|
-
#### Returns
|
|
442
|
-
|
|
443
|
-
Returns a Promise that resolves to: `true`: Indicates successful completion of the operation.
|
|
444
|
-
`void`: Indicates the function performed no action.
|
|
445
|
-
|
|
446
|
-
**Basic Usage**
|
|
447
|
-
|
|
448
|
-
```javascript
|
|
449
|
-
import {i18nCollect} from 'handlebars-i18n-cli';
|
|
450
|
-
await i18nCollect('./src/template.html', './src/translations.json');
|
|
451
|
-
```
|
|
452
|
-
|
|
453
|
-
**With Parameters**
|
|
454
|
-
|
|
455
|
-
```javascript
|
|
456
|
-
await i18nCollect('./src/template.html', './src/translations.json', {
|
|
457
|
-
alphabetical: true,
|
|
458
|
-
dryRun: false,
|
|
459
|
-
lng: ['en', 'de', 'fr'],
|
|
460
|
-
log: true,
|
|
461
|
-
separateLngFiles: true,
|
|
462
|
-
translFunc: 't',
|
|
463
|
-
update: true,
|
|
464
|
-
});
|
|
465
|
-
```
|
|
466
|
-
---
|
|
467
|
-
|
|
468
|
-
### Specification for DeepL Utility Functions
|
|
469
|
-
|
|
470
|
-
This module provides a set of functions to interact with the DeepL API for authentication, language retrieval, text translation, and JSON file translation.
|
|
471
|
-
|
|
472
|
-
### Function `setAuthKey`
|
|
473
|
-
|
|
474
|
-
Writes the DeepL authentication key to a .env file.
|
|
475
|
-
|
|
476
|
-
#### Function Signature
|
|
477
|
-
|
|
478
|
-
```typescript
|
|
479
|
-
export function setAuthKey(key: string, path?: string): Promise<boolean>;
|
|
480
|
-
```
|
|
481
|
-
|
|
482
|
-
#### Parameters
|
|
483
|
-
|
|
484
|
-
| **Name** | **Type** | **Description** | **Example** |
|
|
485
|
-
|-------------------|-----------|--------------------------------------------------------|-----------------|
|
|
486
|
-
| `key` | `string` | Your DeepL API authentication key. | `"abcd1234xyz"` |
|
|
487
|
-
| `path` (optional) | `string` | The path where the `.env` file should go. Default: `./` | `"abcd1234xyz"` |
|
|
488
|
-
|
|
489
|
-
#### Returns
|
|
490
|
-
|
|
491
|
-
`Promise<boolean>`: Resolves to `true` if the key was successfully written; otherwise, `false`.
|
|
492
|
-
|
|
493
|
-
```javascript
|
|
494
|
-
import {setAuthKey} from 'handlebars-i18n-cli';
|
|
495
|
-
await setAuthKey('abcd1234xyz');
|
|
496
|
-
```
|
|
497
|
-
|
|
498
|
-
Fetch the authKey with `const key = process.env.DEEPL_AUTH;`.
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
### Function `getSupportedLanguages`
|
|
502
|
-
|
|
503
|
-
Fetches the list of languages supported by the DeepL API.
|
|
504
|
-
|
|
505
|
-
#### Function Signature
|
|
506
|
-
|
|
507
|
-
```typescript
|
|
508
|
-
export function getSupportedLanguages(authKey: string): Promise<any>;
|
|
509
|
-
```
|
|
510
|
-
|
|
511
|
-
#### Parameters
|
|
512
|
-
|
|
513
|
-
| **Name** | **Type** | **Description** | **Example** |
|
|
514
|
-
|------------|-----------|--------------------------------------------------|-----------------|
|
|
515
|
-
| `authKey` | `string` | Your DeepL API authentication key. | `"abcd1234xyz"` |
|
|
516
|
-
|
|
517
|
-
#### Returns
|
|
518
|
-
|
|
519
|
-
`Promise<any>`: Resolves with an object containing the supported languages.
|
|
520
|
-
|
|
521
|
-
#### Usage Example
|
|
522
|
-
|
|
523
|
-
```javascript
|
|
524
|
-
import {getSupportedLanguages} from 'handlebars-i18n-cli';
|
|
525
|
-
let languages = await getSupportedLanguages('abcd1234xyz');
|
|
526
|
-
```
|
|
527
|
-
|
|
528
|
-
### Function `translateToJSON`
|
|
529
|
-
|
|
530
|
-
Reads a JSON file, translates its content using the DeepL API, and writes the result as a JSON file.
|
|
531
|
-
|
|
532
|
-
#### Function Signature
|
|
533
|
-
|
|
534
|
-
```typescript
|
|
535
|
-
export function translateToJSON(
|
|
536
|
-
authKey: string,
|
|
537
|
-
JsonSrc: string,
|
|
538
|
-
JsonTarget: string,
|
|
539
|
-
sourceLang: string,
|
|
540
|
-
targetLang: string,
|
|
541
|
-
deeplOpts?: object,
|
|
542
|
-
sourceNested?: string,
|
|
543
|
-
log?: boolean,
|
|
544
|
-
dryRun?: boolean
|
|
545
|
-
): Promise<boolean>;
|
|
546
|
-
|
|
547
|
-
```
|
|
548
|
-
|
|
549
|
-
#### Parameters
|
|
550
|
-
|
|
551
|
-
| **Name** | **Type** | **Description** | **Example** |
|
|
552
|
-
|-----------------|------------------|------------------------------------------------------------------|------------------------------|
|
|
553
|
-
| `authKey` | `string` | Your DeepL API authentication key. | `"abcd1234xyz"` |
|
|
554
|
-
| `JsonSrc` | `string` | Path to the source JSON file. | `"./source.json"` |
|
|
555
|
-
| `JsonTarget` | `string` | Path to the target JSON file. | `"./target.json"` |
|
|
556
|
-
| `sourceLang` | `string` | The source language code. Use `""` for auto-detection. | `"en"` |
|
|
557
|
-
| `targetLang` | `string` | The target language code. | `"de"` |
|
|
558
|
-
| `deeplOpts` | `object` (optional)| Additional DeepL API options (e.g., formality). | `{formality: "formal"}` |
|
|
559
|
-
| `sourceNested` | `string` (optional)| Nested object key to process within the JSON file. | `"translations"` |
|
|
560
|
-
| `log` | `boolean` (optional)| If `true`, enables logging of the process. | `true` |
|
|
561
|
-
| `dryRun` | `boolean` (optional)| If `true`, performs a simulation without modifying the file. | `false` |
|
|
562
|
-
|
|
563
|
-
#### Returns
|
|
564
|
-
|
|
565
|
-
`Promise<boolean>`: Resolves to `true` if the operation succeeds; otherwise, `false`.
|
|
566
|
-
|
|
567
|
-
#### Usage Example
|
|
568
|
-
|
|
569
|
-
```javascript
|
|
570
|
-
import {translateToJSON} from 'handlebars-i18n-cli';
|
|
571
|
-
|
|
572
|
-
const authKey = "abcd1234xyz"; // Your DeepL API key
|
|
573
|
-
const sourceFile = "./translations/source.json"; // Path to the source JSON file
|
|
574
|
-
const targetFile = "./translations/translated.json"; // Path to the target JSON file
|
|
575
|
-
const sourceLang = "en"; // Source language
|
|
576
|
-
const targetLang = "de"; // Target language
|
|
577
|
-
const deepLOptions = { formality: "formal" }; // Optional DeepL API options
|
|
578
|
-
|
|
579
|
-
const res = await translateToJSON(
|
|
580
|
-
authKey,
|
|
581
|
-
sourceFile,
|
|
582
|
-
targetFile,
|
|
583
|
-
sourceLang,
|
|
584
|
-
targetLang,
|
|
585
|
-
deepLOptions,
|
|
586
|
-
"data.translations", // Key for nested translations, we expect source key "en" to be here
|
|
587
|
-
true, // Enable logging
|
|
588
|
-
false // Not a dry run, so it will modify/create the target file
|
|
589
|
-
);
|
|
590
|
-
```
|
|
591
|
-
|
|
592
|
-
---
|
|
593
397
|
|
|
594
398
|
## Run tests
|
|
595
399
|
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# handlebars-i18n-cli Programmatical Use
|
|
2
|
+
|
|
3
|
+
You can use the functions of `handlebars-i18n-cli` in a programatical way, i.e. to make them part of your continuous integration.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Specification for Function _i18nCollect_
|
|
8
|
+
|
|
9
|
+
#### Function Signature
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
export function i18nCollect(
|
|
13
|
+
source: string,
|
|
14
|
+
target: string,
|
|
15
|
+
options?: opts
|
|
16
|
+
): Promise<true | void>;
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
#### Description
|
|
20
|
+
|
|
21
|
+
This function scans the source location for internationalization keys, processes them according to the provided options,
|
|
22
|
+
and writes them to the specified target location. It supports features like sorting keys alphabetically, updating
|
|
23
|
+
existing keys, and generating separate files for each language.
|
|
24
|
+
|
|
25
|
+
#### Parameters
|
|
26
|
+
|
|
27
|
+
**Positional Arguments**
|
|
28
|
+
|
|
29
|
+
| **Name** | **Type** | **Description** | **Example** |
|
|
30
|
+
|-----------|---------------|-----------------------------------------|---------------------------|
|
|
31
|
+
| `source` | `string` | Path to the source files. | `./src/template.html` |
|
|
32
|
+
| `target` | `string` | Path to the target files or directory. | `./src/translations.json` |
|
|
33
|
+
|
|
34
|
+
**Optional `options` Object Properties**
|
|
35
|
+
|
|
36
|
+
| **Name** | **Type** | **Description** | **Example** |
|
|
37
|
+
|--------------------|-----------------|-------------------------------------------------------------------|-----------------------|
|
|
38
|
+
| `alphabetical` | `boolean` | If `true`, sorts keys alphabetically. | `true` |
|
|
39
|
+
| `dryRun` | `boolean` | If `true`, performs a simulation without modifying files. | `false` |
|
|
40
|
+
| `lng` | `Array<string>`| List of language codes to process. | `["en", "de", "fr"]` |
|
|
41
|
+
| `log` | `boolean` | If `true`, enables detailed logging to the console. | `true` |
|
|
42
|
+
| `separateLngFiles` | `boolean` | If `true`, creates separate files for each language. | `true` |
|
|
43
|
+
| `translFunc` | `string` | Specifies a custom translation function name to look for in code. | `"t"` |
|
|
44
|
+
| `update` | `boolean` | If `true`, updates existing translation keys in the target file. | `true` |
|
|
45
|
+
|
|
46
|
+
#### Returns
|
|
47
|
+
|
|
48
|
+
Returns a Promise that resolves to: `true`: Indicates successful completion of the operation.
|
|
49
|
+
`void`: Indicates the function performed no action.
|
|
50
|
+
|
|
51
|
+
**Basic Usage**
|
|
52
|
+
|
|
53
|
+
```javascript
|
|
54
|
+
import {i18nCollect} from 'handlebars-i18n-cli';
|
|
55
|
+
await i18nCollect('./src/template.html', './src/translations.json');
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**With Parameters**
|
|
59
|
+
|
|
60
|
+
```javascript
|
|
61
|
+
await i18nCollect('./src/template.html', './src/translations.json', {
|
|
62
|
+
alphabetical: true,
|
|
63
|
+
dryRun: false,
|
|
64
|
+
lng: ['en', 'de', 'fr'],
|
|
65
|
+
log: true,
|
|
66
|
+
separateLngFiles: true,
|
|
67
|
+
translFunc: 't',
|
|
68
|
+
update: true,
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Specification for DeepL Utility Functions
|
|
74
|
+
|
|
75
|
+
This module provides a set of functions to interact with the DeepL API for authentication, language retrieval, text translation, and JSON file translation.
|
|
76
|
+
|
|
77
|
+
### Function `setAuthKey`
|
|
78
|
+
|
|
79
|
+
Writes the DeepL authentication key to a .env file.
|
|
80
|
+
|
|
81
|
+
#### Function Signature
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
export function setAuthKey(key: string, path?: string): Promise<boolean>;
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
#### Parameters
|
|
88
|
+
|
|
89
|
+
| **Name** | **Type** | **Description** | **Example** |
|
|
90
|
+
|-------------------|-----------|--------------------------------------------------------|-----------------|
|
|
91
|
+
| `key` | `string` | Your DeepL API authentication key. | `"abcd1234xyz"` |
|
|
92
|
+
| `path` (optional) | `string` | The path where the `.env` file should go. Default: `./` | `"abcd1234xyz"` |
|
|
93
|
+
|
|
94
|
+
#### Returns
|
|
95
|
+
|
|
96
|
+
`Promise<boolean>`: Resolves to `true` if the key was successfully written; otherwise, `false`.
|
|
97
|
+
|
|
98
|
+
```javascript
|
|
99
|
+
import {setAuthKey} from 'handlebars-i18n-cli';
|
|
100
|
+
await setAuthKey('abcd1234xyz');
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Fetch the authKey with `const key = process.env.DEEPL_AUTH;`.
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
### Function `getSupportedLanguages`
|
|
107
|
+
|
|
108
|
+
Fetches the list of languages supported by the DeepL API.
|
|
109
|
+
|
|
110
|
+
#### Function Signature
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
export function getSupportedLanguages(authKey: string): Promise<any>;
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
#### Parameters
|
|
117
|
+
|
|
118
|
+
| **Name** | **Type** | **Description** | **Example** |
|
|
119
|
+
|------------|-----------|--------------------------------------------------|-----------------|
|
|
120
|
+
| `authKey` | `string` | Your DeepL API authentication key. | `"abcd1234xyz"` |
|
|
121
|
+
|
|
122
|
+
#### Returns
|
|
123
|
+
|
|
124
|
+
`Promise<any>`: Resolves with an object containing the supported languages.
|
|
125
|
+
|
|
126
|
+
#### Usage Example
|
|
127
|
+
|
|
128
|
+
```javascript
|
|
129
|
+
import {getSupportedLanguages} from 'handlebars-i18n-cli';
|
|
130
|
+
let languages = await getSupportedLanguages('abcd1234xyz');
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Function `translateToJSON`
|
|
134
|
+
|
|
135
|
+
Reads a JSON file, translates its content using the DeepL API, and writes the result as a JSON file.
|
|
136
|
+
|
|
137
|
+
#### Function Signature
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
export function translateToJSON(
|
|
141
|
+
authKey: string,
|
|
142
|
+
JsonSrc: string,
|
|
143
|
+
JsonTarget: string,
|
|
144
|
+
sourceLang: string,
|
|
145
|
+
targetLang: string,
|
|
146
|
+
deeplOpts?: object,
|
|
147
|
+
sourceNested?: string,
|
|
148
|
+
log?: boolean,
|
|
149
|
+
dryRun?: boolean
|
|
150
|
+
): Promise<boolean>;
|
|
151
|
+
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
#### Parameters
|
|
155
|
+
|
|
156
|
+
| **Name** | **Type** | **Description** | **Example** |
|
|
157
|
+
|-----------------|------------------|------------------------------------------------------------------|------------------------------|
|
|
158
|
+
| `authKey` | `string` | Your DeepL API authentication key. | `"abcd1234xyz"` |
|
|
159
|
+
| `JsonSrc` | `string` | Path to the source JSON file. | `"./source.json"` |
|
|
160
|
+
| `JsonTarget` | `string` | Path to the target JSON file. | `"./target.json"` |
|
|
161
|
+
| `sourceLang` | `string` | The source language code. Use `""` for auto-detection. | `"en"` |
|
|
162
|
+
| `targetLang` | `string` | The target language code. | `"de"` |
|
|
163
|
+
| `deeplOpts` | `object` (optional)| Additional DeepL API options (e.g., formality). | `{formality: "formal"}` |
|
|
164
|
+
| `sourceNested` | `string` (optional)| Nested object key to process within the JSON file. | `"translations"` |
|
|
165
|
+
| `log` | `boolean` (optional)| If `true`, enables logging of the process. | `true` |
|
|
166
|
+
| `dryRun` | `boolean` (optional)| If `true`, performs a simulation without modifying the file. | `false` |
|
|
167
|
+
|
|
168
|
+
#### Returns
|
|
169
|
+
|
|
170
|
+
`Promise<boolean>`: Resolves to `true` if the operation succeeds; otherwise, `false`.
|
|
171
|
+
|
|
172
|
+
#### Usage Example
|
|
173
|
+
|
|
174
|
+
```javascript
|
|
175
|
+
import {translateToJSON} from 'handlebars-i18n-cli';
|
|
176
|
+
|
|
177
|
+
const authKey = "abcd1234xyz"; // Your DeepL API key
|
|
178
|
+
const sourceFile = "./translations/source.json"; // Path to the source JSON file
|
|
179
|
+
const targetFile = "./translations/translated.json"; // Path to the target JSON file
|
|
180
|
+
const sourceLang = "en"; // Source language
|
|
181
|
+
const targetLang = "de"; // Target language
|
|
182
|
+
const deepLOptions = { formality: "formal" }; // Optional DeepL API options
|
|
183
|
+
|
|
184
|
+
const res = await translateToJSON(
|
|
185
|
+
authKey,
|
|
186
|
+
sourceFile,
|
|
187
|
+
targetFile,
|
|
188
|
+
sourceLang,
|
|
189
|
+
targetLang,
|
|
190
|
+
deepLOptions,
|
|
191
|
+
"data.translations", // Key for nested translations, we expect source key "en" to be here
|
|
192
|
+
true, // Enable logging
|
|
193
|
+
false // Not a dry run, so it will modify/create the target file
|
|
194
|
+
);
|
|
195
|
+
```
|
package/package.json
CHANGED
package/de.json
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"de": {
|
|
3
|
-
"Invoice": "Facture",
|
|
4
|
-
"Invoicepre": "Prepayment",
|
|
5
|
-
"Invoice_final": "The invoice finale",
|
|
6
|
-
"Intro_statement": "Based on our {{refLetterId}} offer, we will invoice you for the following items sent on {{date of dispatch}}:",
|
|
7
|
-
"Intro_statement_pre": "We hereby confirm that we have received your order request in accordance with our offer {{refLetterId}}.",
|
|
8
|
-
"Info_EU": "This is an intra-Community supply exempt from tax under Articles 4(1b) and 6a of the VAT Act.",
|
|
9
|
-
"Info_World": "This is a tax-free export transaction.",
|
|
10
|
-
"The_date_of_performance": "The date of performance of the service corresponds to the date of invoicing.",
|
|
11
|
-
"Transfer_statement": "Please transfer the invoice amount within {{paymentTerms}} days with reference {{letterId}} to the following account :",
|
|
12
|
-
"Transfer_statement_pre": "Transfer the total amount of the deposit to the following account using the reference number {{letterId}}:",
|
|
13
|
-
"Confirmation_statement_pre": "Once we have received this deposit, we will confirm your order and start manufacturing the products you have ordered.",
|
|
14
|
-
"Thank_statement": "We thank you warmly for your confidence and hope to receive further orders from you in the future. Please do not hesitate to contact us <a href=\"{{telHref}}\" class=\"black\">{{phone}}</a> if you need any further information.",
|
|
15
|
-
"General_Sale_and_Delivery_Terms": "This service is provided solely in accordance with our general terms and conditions of sale and delivery as set out on <a href=\"http://{{webAgb}}\" class=\"orange\"> {{webAgb}} </a>.",
|
|
16
|
-
"Net_pre": "Amount of deposit (net)",
|
|
17
|
-
"Total_pre": "Total amount of payments",
|
|
18
|
-
"Net_final": "Deposit received",
|
|
19
|
-
"Total_final": "Total stock",
|
|
20
|
-
"VAT_final": "VAT on the deposit received",
|
|
21
|
-
"Proforma": "Facture pro forma",
|
|
22
|
-
"Comercial": "Commercial invoice",
|
|
23
|
-
"EORI_no": "EORI-number"
|
|
24
|
-
},
|
|
25
|
-
"en-US": {
|
|
26
|
-
"a": "b",
|
|
27
|
-
"Invoice": "Facture",
|
|
28
|
-
"Invoicepre": "Prepayment",
|
|
29
|
-
"Invoice_final": "The invoice finale",
|
|
30
|
-
"Intro_statement": "Based on our {{refLetterId}} offer, we will invoice you for the following items sent on {{date of dispatch}}:",
|
|
31
|
-
"Intro_statement_pre": "We hereby confirm that we have received your order request in accordance with our offer {{refLetterId}}.",
|
|
32
|
-
"Info_EU": "This is an intra-Community supply exempt from tax under Articles 4(1b) and 6a of the VAT Act.",
|
|
33
|
-
"Info_World": "This is a tax-free export transaction.",
|
|
34
|
-
"The_date_of_performance": "The date of performance of the service corresponds to the date of invoicing.",
|
|
35
|
-
"Transfer_statement": "Please transfer the invoice amount within {{paymentTerms}} days with reference {{letterId}} to the following account :",
|
|
36
|
-
"Transfer_statement_pre": "Transfer the total amount of the deposit to the following account using the reference number {{letterId}}:",
|
|
37
|
-
"Confirmation_statement_pre": "Once we have received this deposit, we will confirm your order and start manufacturing the products you have ordered.",
|
|
38
|
-
"Thank_statement": "We thank you warmly for your confidence and hope to receive further orders from you in the future. Please do not hesitate to contact us <a href=\"{{telHref}}\" class=\"black\">{{phone}}</a> if you need any further information.",
|
|
39
|
-
"General_Sale_and_Delivery_Terms": "This service is provided solely in accordance with our general terms and conditions of sale and delivery as set out on <a href=\"http://{{webAgb}}\" class=\"orange\"> {{webAgb}} </a>.",
|
|
40
|
-
"Net_pre": "Amount of deposit (net)",
|
|
41
|
-
"Total_pre": "Total amount of payments",
|
|
42
|
-
"Net_final": "Deposit received",
|
|
43
|
-
"Total_final": "Total stock",
|
|
44
|
-
"VAT_final": "VAT on the deposit received",
|
|
45
|
-
"Proforma": "Facture pro forma",
|
|
46
|
-
"Comercial": "Commercial invoice",
|
|
47
|
-
"EORI_no": "EORI-number"
|
|
48
|
-
},
|
|
49
|
-
"fi": {
|
|
50
|
-
"Invoice": "Facture",
|
|
51
|
-
"Invoicepre": "Ennakkolasku",
|
|
52
|
-
"Invoice_final": "Faktuurin finaali",
|
|
53
|
-
"Intro_statement": "Tarjouksemme {{refLetterId}} perusteella laskutamme sinua seuraavista eristä {{lähetyspäivänä}} lähetetyistä tavaroista:",
|
|
54
|
-
"Intro_statement_pre": "Vahvistamme täten, että olemme vastaanottaneet tilauspyyntösi tarjouksemme mukaisesti {{refLetterId}}.",
|
|
55
|
-
"Info_EU": "Kyseessä on arvonlisäverolain 4 §:n 1 b kohdan ja 6 a §:n mukainen veroton yhteisön sisäinen luovutus.",
|
|
56
|
-
"Info_World": "Tämä on verovapaa vientitoimitus.",
|
|
57
|
-
"The_date_of_performance": "Palvelun suorituspäivä vastaa laskutuspäivää.",
|
|
58
|
-
"Transfer_statement": "Pyydämme teitä siirtämään laskun summan {{paymentTerms}}-päivien kuluessa viitteellä {{letterId}} seuraavalle tilille :",
|
|
59
|
-
"Transfer_statement_pre": "Siirrä talletuksen kokonaissumma seuraavalle tilille viitenumeroa {{letterId}} käyttäen:",
|
|
60
|
-
"Confirmation_statement_pre": "Kun olemme saaneet tämän talletuksen, vahvistamme tilauksesi ja aloitamme tilattujen tuotteiden valmistuksen.",
|
|
61
|
-
"Thank_statement": "Kiitämme teitä lämpimästi luottamuksestanne ja toivomme voivamme ottaa teiltä vastaan uusia tilauksia tulevaisuudessa. Älä epäröi ottaa meihin yhteyttä <a href=\"{{telHref}}\" class=\"black\">{{puhelin}}</a>, jos tarvitset lisätietoja.",
|
|
62
|
-
"General_Sale_and_Delivery_Terms": "Tämä palvelu on tarjottu yksinomaan <a href=\"http://{{webAgb}}\" class=\"orange\"> {{webAgb}} </a> -sivustolla olevien yleisten myynti- ja toimitusehtojemme mukaisesti.",
|
|
63
|
-
"Net_pre": "Talletuksen määrä (netto)",
|
|
64
|
-
"Total_pre": "Maksujen kokonaismäärä",
|
|
65
|
-
"Net_final": "Saatu talletus",
|
|
66
|
-
"Total_final": "Kokonaiskanta",
|
|
67
|
-
"VAT_final": "saadun talletuksen arvonlisävero",
|
|
68
|
-
"Proforma": "Facture pro forma",
|
|
69
|
-
"Comercial": "Kauppalasku",
|
|
70
|
-
"EORI_no": "EORI-numero"
|
|
71
|
-
}
|
|
72
|
-
}
|
package/en.json
DELETED
package/fi.json
DELETED
package/my.json
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"Invoice": "Fattore",
|
|
3
|
-
"Invoicepre": "Pagamento anticipato",
|
|
4
|
-
"Invoice_final": "Il finale della fattura",
|
|
5
|
-
"Intro_statement": "In base alla nostra offerta {{refLetterId}}, vi fattureremo i seguenti articoli inviati il {{data di spedizione}}:",
|
|
6
|
-
"Intro_statement_pre": "Con la presente vi confermiamo di aver ricevuto la vostra richiesta d'ordine in conformità con la nostra offerta {{refLetterId}}.",
|
|
7
|
-
"Info_EU": "Si tratta di una cessione intracomunitaria esente da imposta ai sensi dell'articolo 4, paragrafo 1b, e dell'articolo 6a della legge sull'IVA.",
|
|
8
|
-
"Info_World": "Si tratta di una transazione di esportazione esente da imposte.",
|
|
9
|
-
"The_date_of_performance": "La data di esecuzione del servizio corrisponde alla data di fatturazione.",
|
|
10
|
-
"Transfer_statement": "Si prega di trasferire l'importo della fattura entro {{Termini di pagamento}} giorni con riferimento {{letteraId}} al seguente conto:",
|
|
11
|
-
"Transfer_statement_pre": "Trasferire l'importo totale del deposito sul seguente conto utilizzando il numero di riferimento {{letterId}}:",
|
|
12
|
-
"Confirmation_statement_pre": "Una volta ricevuto il deposito, confermeremo l'ordine e inizieremo a produrre i prodotti ordinati.",
|
|
13
|
-
"Thank_statement": "Vi ringraziamo calorosamente per la vostra fiducia e speriamo di ricevere altri ordini da parte vostra in futuro. Non esitate a contattarci <a href=\"{{telHref}}\" class=\"black\">{{phone}}</a> se avete bisogno di ulteriori informazioni.",
|
|
14
|
-
"General_Sale_and_Delivery_Terms": "Questo servizio è fornito esclusivamente in conformità con i nostri termini e condizioni generali di vendita e consegna, come indicato su <a href=\"http://{{webAgb}}\" class=\"orange\"> {{webAgb}} </a>.",
|
|
15
|
-
"Net_pre": "Importo del deposito (netto)",
|
|
16
|
-
"Total_pre": "Importo totale dei pagamenti",
|
|
17
|
-
"Net_final": "Deposito ricevuto",
|
|
18
|
-
"Total_final": "Totale azioni",
|
|
19
|
-
"VAT_final": "IVA sulla caparra ricevuta",
|
|
20
|
-
"Proforma": "Fattura pro forma",
|
|
21
|
-
"Comercial": "Attività commerciale",
|
|
22
|
-
"EORI_no": "Numero EORI"
|
|
23
|
-
}
|