handlebars-i18n-cli 1.0.5 → 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/.github/workflows/coveralls.yml +34 -17
- package/.github/workflows/node.js.yml +2 -2
- package/README.md +191 -55
- package/README_programmatic.md +195 -0
- package/bin/i18n-collect +36 -2
- package/bin/i18n-deepl +71 -0
- package/package.json +27 -16
- package/src/i18n-collect.js +162 -289
- package/src/i18n-deepl.js +304 -0
- package/src/index.js +4 -0
- package/test/handlebars-i18n-cli.test.mjs +472 -0
- package/tsconfig.json +20 -0
- package/types/i18n-collect.d.ts +5 -0
- package/types/i18n-collect.d.ts.map +1 -0
- package/types/i18n-deepl.d.ts +44 -0
- package/types/i18n-deepl.d.ts.map +1 -0
- package/types/index.d.ts +7 -0
- package/types/index.d.ts.map +1 -0
- package/want.md +18 -0
- package/src/deepl-free-api-key.json +0 -3
- package/src/deepl-pro-api-key.json +0 -3
- package/test/handlebars-i18n-cli.test.js +0 -174
- package/test/test-generated/test-12.json +0 -8
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for ./src/i18n-collect.js
|
|
3
|
-
*
|
|
4
|
-
* usage:
|
|
5
|
-
* $ npm test
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
const chai = require('chai');
|
|
9
|
-
chai.use(require('chai-as-promised'));
|
|
10
|
-
|
|
11
|
-
const assert = chai.assert;
|
|
12
|
-
const expect = chai.expect;
|
|
13
|
-
const stdout = require('test-console').stdout;
|
|
14
|
-
const { cli } = require('../src/i18n-collect');
|
|
15
|
-
|
|
16
|
-
describe('handlebars-i18n-cli Tests', () => {
|
|
17
|
-
|
|
18
|
-
const templSimple = 'test/test-assets/simple.html';
|
|
19
|
-
const customSimple = 'test/test-assets/custom-func.html';
|
|
20
|
-
|
|
21
|
-
/****************************************
|
|
22
|
-
* TEST MAIN INTERFACE
|
|
23
|
-
****************************************/
|
|
24
|
-
|
|
25
|
-
it('[1] FUNC: cli shall be a function', () => {
|
|
26
|
-
assert.isFunction(cli);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('[2] ERROR: cli shall error when called without argument', async () => {
|
|
30
|
-
const argv = [null, null];
|
|
31
|
-
expect(cli(argv)).to.be.rejectedWith(Error);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('[3] HELP: cli shall log help when called with argument --help', () => {
|
|
35
|
-
const argv = [null, null, '--help']
|
|
36
|
-
const output = stdout.inspectSync(() => { cli(argv) });
|
|
37
|
-
assert.deepEqual(output, [
|
|
38
|
-
'\u001b[2mUsage:\n',
|
|
39
|
-
'i18n-collect <source> <target> <options...>\n',
|
|
40
|
-
'\n',
|
|
41
|
-
'<source> path to handlebars.js template file(s), glob pattern allowed\n',
|
|
42
|
-
'<target> json file(s) to write result to\n',
|
|
43
|
-
'\n',
|
|
44
|
-
'<options>\n',
|
|
45
|
-
'--alphabetical or -a will order the keys to the translation strings alphabetically in the json\n',
|
|
46
|
-
' default: keys in order of appearance as within the template(s)\n',
|
|
47
|
-
'--dryRun or -dr will log the result(s) but not write out json file(s)\n',
|
|
48
|
-
'--empty or -e will create empty value strings for the translations in the json\n',
|
|
49
|
-
' default: value strings contain current language and key name\n',
|
|
50
|
-
'--lng=en,fr,es,… the languages you want to be generated\n',
|
|
51
|
-
' default: en\n',
|
|
52
|
-
'--log or -l log final results to console\n',
|
|
53
|
-
'--separateLngFiles write each language in a separate json file\n',
|
|
54
|
-
' or -sf default: all languages are written as arrays in one json file\n',
|
|
55
|
-
'--translFunc=customName a custom name of the translation function used in the templates\n',
|
|
56
|
-
' default: __ like handlebars-i18n notation: {{__ keyToTranslate}}\n',
|
|
57
|
-
'--update or -u updates existing json files(s) after changes made in template file(s)\n',
|
|
58
|
-
'\u001b[0m\n' ]
|
|
59
|
-
);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('[4] ERROR: cli shall error when called without a second argument', async () => {
|
|
63
|
-
const argv = [null, null, 'someText']
|
|
64
|
-
expect(cli(argv)).to.be.rejectedWith(Error);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('[5] WARN: cli shall log when a given file does not contain strings for translation',async () => {
|
|
68
|
-
const argv = [null, null, 'test/test-assets/empty.html', 'test/test-generated/empty.json'];
|
|
69
|
-
const inspect = stdout.inspect();
|
|
70
|
-
await cli(argv);
|
|
71
|
-
inspect.restore();
|
|
72
|
-
assert.deepEqual(inspect.output, [
|
|
73
|
-
'Now processing test/test-assets/empty.html\n',
|
|
74
|
-
'No strings for translation found, no files written.\n'
|
|
75
|
-
]);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('[6] LOG: cli shall log myKey and myVar (with additional text) for language "en" when called with argument --log', async () => {
|
|
79
|
-
const fileNo = 6; // we use the no. of the test here
|
|
80
|
-
const argv = [null, null, templSimple, `test/test-generated/test-${fileNo}.json`, '--log'];
|
|
81
|
-
const inspect = stdout.inspect();
|
|
82
|
-
await cli(argv);
|
|
83
|
-
inspect.restore();
|
|
84
|
-
assert.deepEqual(inspect.output, [
|
|
85
|
-
`Now processing ${templSimple}\n`,
|
|
86
|
-
'{\n \"translations\": {\n \"en\": {\n \"myKey\": \"en of myKey with variables {{myVar}}\"\n }\n }\n}\n',
|
|
87
|
-
`\u001b[32mDone and Ready! Your output was written to test/test-generated/test-${fileNo}.json\u001b[0m\n`
|
|
88
|
-
]);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('[7] ALPHABETICAL: cli shall log keys for language "en" in alphabetical order when called with argument --alphabetical and --log', async () => {
|
|
92
|
-
const fileNo = 7;
|
|
93
|
-
const argv = [null, null, 'test/test-assets/multiple.html', `test/test-generated/test-${fileNo}.json`, '--alphabetical', '--log'];
|
|
94
|
-
const inspect = stdout.inspect();
|
|
95
|
-
await cli(argv);
|
|
96
|
-
inspect.restore();
|
|
97
|
-
assert.deepEqual(inspect.output, [
|
|
98
|
-
'Now processing test/test-assets/multiple.html\n',
|
|
99
|
-
'{\n \"translations\": {\n \"en\": {\n \"a\": {\n \"a\": \"en of a.a\",\n \"b\": \"en of a.b\"\n },\n \"b\": \"en of b\"\n }\n }\n}\n',
|
|
100
|
-
`\u001b[32mDone and Ready! Your output was written to test/test-generated/test-${fileNo}.json\u001b[0m\n`
|
|
101
|
-
]);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('[8] EMPTY: cli shall log myKey and myVar (no text) for language "en" when called with argument --empty and --log', async () => {
|
|
105
|
-
const fileNo = 8;
|
|
106
|
-
const argv = [null, null, templSimple, `test/test-generated/test-${fileNo}.json`, '--empty', '--log'];
|
|
107
|
-
const inspect = stdout.inspect();
|
|
108
|
-
await cli(argv);
|
|
109
|
-
inspect.restore();
|
|
110
|
-
assert.deepEqual(inspect.output, [
|
|
111
|
-
`Now processing ${templSimple}\n`,
|
|
112
|
-
'{\n \"translations\": {\n \"en\": {\n \"myKey\": \"{{myVar}}\"\n }\n }\n}\n',
|
|
113
|
-
`\u001b[32mDone and Ready! Your output was written to test/test-generated/test-${fileNo}.json\u001b[0m\n`
|
|
114
|
-
]);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it('[9] LNG: cli shall log myKey and myVar for language "de", "fr", and "es" when called with arguments --lng=de,fr,es and --log', async () => {
|
|
118
|
-
const fileNo = 9;
|
|
119
|
-
const argv = [null, null, templSimple, `test/test-generated/test-${fileNo}.json`, '--lng=de,fr,es', '--log'];
|
|
120
|
-
const inspect = stdout.inspect();
|
|
121
|
-
await cli(argv);
|
|
122
|
-
inspect.restore();
|
|
123
|
-
assert.deepEqual(inspect.output, [
|
|
124
|
-
`Now processing ${templSimple}\n`,
|
|
125
|
-
'{\n \"translations\": {\n \"de\": {\n \"myKey\": \"de of myKey with variables {{myVar}}\"\n },\n \"fr\": {\n \"myKey\": \"fr of myKey with variables {{myVar}}\"\n },\n \"es\": {\n \"myKey\": \"es of myKey with variables {{myVar}}\"\n }\n }\n}\n',
|
|
126
|
-
`\u001b[32mDone and Ready! Your output was written to test/test-generated/test-${fileNo}.json\u001b[0m\n`
|
|
127
|
-
]);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('[10] SEPARATE FILES: cli shall log for three single files when called with arguments --lng=de,fr,es -sf and --log', async () => {
|
|
131
|
-
const fileNo = 10;
|
|
132
|
-
const argv = [null, null, templSimple, `test/test-generated/test-${fileNo}.json`, '--lng=de,fr,es', '-sf', '--log'];
|
|
133
|
-
const inspect = stdout.inspect();
|
|
134
|
-
await cli(argv);
|
|
135
|
-
inspect.restore();
|
|
136
|
-
assert.deepEqual(inspect.output, [
|
|
137
|
-
`Now processing ${templSimple}\n`,
|
|
138
|
-
"{\n \"de\": {\n \"myKey\": \"de of myKey with variables {{myVar}}\"\n }\n}\n",
|
|
139
|
-
`\u001b[34mWrote language keys for 'de' to test/test-generated/test-${fileNo}.de.json\u001b[0m\n`,
|
|
140
|
-
"{\n \"fr\": {\n \"myKey\": \"fr of myKey with variables {{myVar}}\"\n }\n}\n",
|
|
141
|
-
`\u001b[34mWrote language keys for 'fr' to test/test-generated/test-${fileNo}.fr.json\u001b[0m\n`,
|
|
142
|
-
"{\n \"es\": {\n \"myKey\": \"es of myKey with variables {{myVar}}\"\n }\n}\n",
|
|
143
|
-
`\u001b[34mWrote language keys for 'es' to test/test-generated/test-${fileNo}.es.json\u001b[0m\n`,
|
|
144
|
-
"\u001b[32mYou’re good. All Done.\u001b[0m\n"
|
|
145
|
-
]);
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it('[11] CUSTOM TRANSLATION FUNC: cli shall log myOtherKey when called with arguments --translFunc=_t and --log', async () => {
|
|
149
|
-
const fileNo = 11;
|
|
150
|
-
const argv = [null, null, customSimple, `test/test-generated/test-${fileNo}.json`, '--translFunc=_t', '--log'];
|
|
151
|
-
const inspect = stdout.inspect();
|
|
152
|
-
await cli(argv);
|
|
153
|
-
inspect.restore();
|
|
154
|
-
assert.deepEqual(inspect.output, [
|
|
155
|
-
`Now processing ${customSimple}\n`,
|
|
156
|
-
"{\n \"translations\": {\n \"en\": {\n \"myOtherKey\": \"en of myOtherKey\"\n }\n }\n}\n",
|
|
157
|
-
`\u001b[32mDone and Ready! Your output was written to test/test-generated/test-${fileNo}.json\u001b[0m\n`
|
|
158
|
-
]);
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it('[12] UPDATE: cli shall log for extending existing file when called with arguments --update and --log', async () => {
|
|
162
|
-
const fileNo = 12;
|
|
163
|
-
const argv = [null, null, templSimple, `test/test-generated/test-${fileNo}.json`, '--update', '--log'];
|
|
164
|
-
const inspect = stdout.inspect();
|
|
165
|
-
await cli(argv);
|
|
166
|
-
inspect.restore();
|
|
167
|
-
assert.deepEqual(inspect.output, [
|
|
168
|
-
`Now processing ${templSimple}\n`,
|
|
169
|
-
"{\n \"translations\": {\n \"en\": {\n \"myKey\": \"en of myKey with variables {{myVar}}\",\n \"hasAlreadyAKey\": \"WithSomeValue\"\n }\n }\n}\n",
|
|
170
|
-
`\u001b[32mDone and Ready! Your output was written to test/test-generated/test-${fileNo}.json\u001b[0m\n`
|
|
171
|
-
]);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
});
|