handlebars-i18n-cli 1.0.4 → 2.0.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/bin/i18n-collect CHANGED
@@ -1,4 +1,38 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- require = require('esm')(module);
4
- require('../src/i18n-collect').cli(process.argv);
3
+ import {program} from 'commander';
4
+ import {i18nCollect} from "../src/index.js";
5
+ import fs from 'async-file-tried';
6
+
7
+ const [packageJS, err] = await fs.readJson('./package.json');
8
+ if (err) throw (err);
9
+
10
+ program
11
+ .name('i18n-deepl')
12
+ .version(packageJS.version)
13
+ .description(`Automatically extract translation strings from your handlebars templates and generate i18next conform json files from it`)
14
+ .arguments('<source> <target>')
15
+ .option('-a, --alphabetical', 'sort keys alphabetically in the json output')
16
+ .option('-dr, --dryRun', 'perform a dry run without making any changes')
17
+ .option('-e, --empty', 'will create empty value strings for the translations in the json. Default: value strings contain current language and key name')
18
+ .option('--lng <languages>', 'the languages you want to be generated, e.g., de,fr,es. default: en',
19
+ (value) => value.split(','))
20
+ .option('-l, --log', 'enable logging')
21
+ .option('-sf, --separateLngFiles', 'create separate json files for each language')
22
+ .option('--translFunc <function>', 'specify your custom translation function name. Default: __ like handlebars-i18n notation: {{__ keyToTranslate}}')
23
+ .option('-u, --update', 'updates existing json files(s)')
24
+ .action(async (source, target, options) => {
25
+
26
+ if (await i18nCollect(source, target, options)) {
27
+ return (options.separateLngFiles)
28
+ ? console.log('\x1b[32m%s\x1b[0m', 'You’re good. The output was written to separate language files.')
29
+ : console.log('\x1b[32m%s\x1b[0m', `Done and Ready. Your output was written to ${target}`);
30
+ }
31
+ });
32
+
33
+ program.parse(process.argv);
34
+
35
+ // If no arguments are provided, display help
36
+ if (!process.argv.slice(2).length) {
37
+ program.outputHelp();
38
+ }
package/bin/i18n-deepl ADDED
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env node
2
+
3
+ import dotenv from 'dotenv';
4
+
5
+ dotenv.config();
6
+ import {program} from 'commander';
7
+ import {getSupportedLanguages, setAuthKey, translateToJSON} from '../src/index.js';
8
+ import fs from 'async-file-tried';
9
+
10
+ const [packageJS, err] = await fs.readJson('./package.json');
11
+ if (err) throw (err);
12
+
13
+ program
14
+ .name('i18n-deepl')
15
+ .version(packageJS.version)
16
+ .description('Translate i18next JSON files via DeepL API.')
17
+
18
+ program
19
+ .command('languages')
20
+ .description('List DeepL’s supported languages.')
21
+ .option('--auth-key <authKey>', 'The DeepL Auth Key.')
22
+ .action(async (options) => {
23
+ const authKey = options.authKey || process.env.DEEPL_AUTH;
24
+ const languages = await getSupportedLanguages(authKey);
25
+ console.log('DeepL’s Supported Languages:');
26
+ languages.forEach(lang =>
27
+ console.log(`${lang.language} - ${lang.name}`)
28
+ );
29
+ });
30
+
31
+ program
32
+ .command('setAuth authKey')
33
+ .description('Sets the DeepL Auth Key as environmental variable (.env).')
34
+ .action(async (authKey) => {
35
+ await setAuthKey(authKey);
36
+ return console.log('Success. DeepL Auth Key is now set.');
37
+ });
38
+
39
+ program
40
+ .command('translate')
41
+ .description('Translate texts from a JSON file to the target language.')
42
+ .arguments('<source> <target> <targetLang>')
43
+ .option('--auth-key, -ak <authKey>', 'The DeepL Auth Key.')
44
+ .option('--source-lang, -sl <sourceLang>', 'Source language for translation, such as "de".')
45
+ .option('-sn, --source-nested <sourceNested>', 'Send only a sub-entry of the source JSON to DeepL API. ' +
46
+ 'I.E. --source-nested="translations.de]" will route to the nested entry \'translations\' and within it will send the entries of \'de\' to translation.')
47
+ .option('--log, -l', 'Log translation response to console.')
48
+ .option('--dryRun, -dr', 'Perform a dry run and log it without making any changes to actual data.')
49
+ .option('--options, -o <options>', 'DeepL API options, given as object, i.E. --options="{formality: \'less\'}."')
50
+ .action(
51
+ async (source, target, targetLang, options) => {
52
+
53
+ await translateToJSON(options.authKey || process.env.DEEPL_AUTH,
54
+ source,
55
+ target,
56
+ options.sourceLang || null,
57
+ targetLang,
58
+ options.options || {},
59
+ options.sourceNested || null,
60
+ options.L || false,
61
+ options.Dr || false,
62
+ );
63
+ console.log(`Translation complete. See ${target} for your results.`)
64
+ });
65
+
66
+ program.parse(process.argv);
67
+
68
+ // If no arguments are provided, display help
69
+ if (!process.argv.slice(2).length) {
70
+ program.outputHelp();
71
+ }
package/de.json ADDED
@@ -0,0 +1,72 @@
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 ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "header": {
3
+ "greet": "Hello World!"
4
+ }
5
+ }
package/fi.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "header": {
3
+ "greet": "Hei maailma!"
4
+ }
5
+ }
package/my.json ADDED
@@ -0,0 +1,23 @@
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
+ }
package/package.json CHANGED
@@ -1,17 +1,22 @@
1
1
  {
2
2
  "name": "handlebars-i18n-cli",
3
- "version": "1.0.4",
4
- "description": "A CLI tool to support node module handlebars-i18n",
5
- "main": "./src/i18n-collect.js",
3
+ "version": "2.0.0",
4
+ "description": "Extracts translation keys from handlebars templates and forms JSON from it; generates automatic translations via DeepL.",
5
+ "main": "src/index.js",
6
+ "type": "module",
7
+ "types": "types/index.d.ts",
6
8
  "bin": {
7
9
  "@fwalzel/handlebars-i18n-cli": "./bin/i18n-collect",
8
- "i18n-collect": "./bin/i18n-collect"
10
+ "i18n-collect": "./bin/i18n-collect",
11
+ "@fwalzel/i18n-deepl": "./bin/i18n-deepl",
12
+ "i18n-deepl": "./bin/i18n-deepl"
9
13
  },
10
14
  "publishConfig": {
11
15
  "access": "public"
12
16
  },
13
17
  "scripts": {
14
- "test" : "nyc mocha",
18
+ "test": "c8 mocha",
19
+ "test:coverage": "npm run test && c8 report --reporter=text-lcov > coverage/lcov.info",
15
20
  "test:istanbul": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec",
16
21
  "coveralls": "npm test && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage",
17
22
  "i18n-collect": "cd bin && node i18n-collect"
@@ -23,10 +28,10 @@
23
28
  "keywords": [
24
29
  "cli helper",
25
30
  "handlebars-i18n",
26
- "handlebars",
27
- "i18n-next",
31
+ "handlebars translation",
28
32
  "extract translations from i18next templates",
29
- "handlebars-i18next"
33
+ "deepL automatic translation",
34
+ "i18next JSON"
30
35
  ],
31
36
  "author": "Florian Walzel",
32
37
  "license": "MIT",
@@ -35,16 +40,22 @@
35
40
  },
36
41
  "homepage": "https://github.com/fwalzel/handlebars-i18n-cli#readme",
37
42
  "dependencies": {
38
- "esm": "^3.2.25",
39
- "util": "^0.12.5"
43
+ "async-file-tried": "^1.2.1",
44
+ "axios": "^1.7.2",
45
+ "commander": "^12.1.0",
46
+ "deepl-node": "^1.13.0",
47
+ "dotenv": "^16.4.5",
48
+ "glob": "^11.0.0"
40
49
  },
41
50
  "devDependencies": {
42
- "chai": "^4.3.6",
43
- "chai-as-promised": "^7.1.1",
44
- "coveralls": "3.1.1",
45
- "istanbul": "^0.4.5",
51
+ "c8": "^10.1.2",
52
+ "chai": "^5.1.1",
53
+ "chai-as-promised": "^8.0.0",
54
+ "coveralls-next": "^4.2.1",
46
55
  "mocha": "^10.1.0",
47
- "nyc": "^15.1.0",
48
- "test-console": "^2.0.0"
56
+ "sinon": "^18.0.0",
57
+ "sinon-chai": "^4.0.0",
58
+ "test-console": "^2.0.0",
59
+ "typescript": "^5.7.2"
49
60
  }
50
61
  }