@vocab/cli 1.0.1 → 1.2.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/CHANGELOG.md +31 -0
- package/README.md +149 -1
- package/dist/vocab-cli.cjs.dev.js +6 -1
- package/dist/vocab-cli.cjs.prod.js +6 -1
- package/dist/vocab-cli.esm.js +6 -1
- package/package.json +3 -3
- package/src/index.ts +9 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# @vocab/cli
|
|
2
2
|
|
|
3
|
+
## 1.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`66ed22c`](https://github.com/seek-oss/vocab/commit/66ed22cac6f89018d5fd69fd6f6408e090e1a382) [#93](https://github.com/seek-oss/vocab/pull/93) Thanks [@askoufis](https://github.com/askoufis)! - Add an optional `delete-unused-keys` flag to the `push` command. If set to `true`, unused keys will be deleted from Phrase after translations are pushed.
|
|
8
|
+
|
|
9
|
+
**EXAMPLE USAGE**:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
vocab push --delete-unused-keys
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [[`66ed22c`](https://github.com/seek-oss/vocab/commit/66ed22cac6f89018d5fd69fd6f6408e090e1a382), [`159d559`](https://github.com/seek-oss/vocab/commit/159d559c87c66c3e91c707fb45a1f67ebec07b4d)]:
|
|
18
|
+
- @vocab/phrase@1.1.0
|
|
19
|
+
|
|
20
|
+
## 1.1.0
|
|
21
|
+
|
|
22
|
+
### Minor Changes
|
|
23
|
+
|
|
24
|
+
- [`87333d7`](https://github.com/seek-oss/vocab/commit/87333d79c4a883b07d7d8f2c272b16e2243c49bd) [#80](https://github.com/seek-oss/vocab/pull/80) Thanks [@askoufis](https://github.com/askoufis)! - Enable the creation of generated languages via the `generatedLanguages` config.
|
|
25
|
+
See [the docs] for more information and examples.
|
|
26
|
+
|
|
27
|
+
[the docs]: https://github.com/seek-oss/vocab#generated-languages
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- Updated dependencies [[`87333d7`](https://github.com/seek-oss/vocab/commit/87333d79c4a883b07d7d8f2c272b16e2243c49bd)]:
|
|
32
|
+
- @vocab/core@1.1.0
|
|
33
|
+
|
|
3
34
|
## 1.0.1
|
|
4
35
|
|
|
5
36
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -184,6 +184,14 @@ Configuration can either be passed into the Node API directly or be gathered fro
|
|
|
184
184
|
**vocab.config.js**
|
|
185
185
|
|
|
186
186
|
```js
|
|
187
|
+
function capitalize(element) {
|
|
188
|
+
return element.toUpperCase();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function pad(message) {
|
|
192
|
+
return '[' + message + ']';
|
|
193
|
+
}
|
|
194
|
+
|
|
187
195
|
module.exports = {
|
|
188
196
|
devLanguage: 'en',
|
|
189
197
|
languages: [
|
|
@@ -192,11 +200,25 @@ module.exports = {
|
|
|
192
200
|
{ name: 'en-US', extends: 'en' },
|
|
193
201
|
{ name: 'fr-FR' }
|
|
194
202
|
],
|
|
203
|
+
/**
|
|
204
|
+
* An array of languages to generate based off translations for existing languages
|
|
205
|
+
* Default: []
|
|
206
|
+
*/
|
|
207
|
+
generatedLanguages: [
|
|
208
|
+
{
|
|
209
|
+
name: 'generatedLangauge',
|
|
210
|
+
extends: 'en',
|
|
211
|
+
generator: {
|
|
212
|
+
transformElement: capitalize,
|
|
213
|
+
transformMessage: pad
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
],
|
|
195
217
|
/**
|
|
196
218
|
* The root directory to compile and validate translations
|
|
197
219
|
* Default: Current working directory
|
|
198
220
|
*/
|
|
199
|
-
projectRoot: './example/'
|
|
221
|
+
projectRoot: './example/',
|
|
200
222
|
/**
|
|
201
223
|
* A custom suffix to name vocab translation directories
|
|
202
224
|
* Default: '.vocab'
|
|
@@ -209,6 +231,131 @@ module.exports = {
|
|
|
209
231
|
};
|
|
210
232
|
```
|
|
211
233
|
|
|
234
|
+
## Generated languages
|
|
235
|
+
|
|
236
|
+
Vocab supports the creation of generated languages via the `generatedLanguages` config.
|
|
237
|
+
|
|
238
|
+
Generated languages are created by running a message `generator` over every translation message in an existing translation.
|
|
239
|
+
A `generator` may contain a `transformElement` function, a `transformMessage` function, or both.
|
|
240
|
+
Both of these functions accept a single string parameter and return a string.
|
|
241
|
+
|
|
242
|
+
`transformElement` is applied to string literal values contained within `MessageFormatElement`s.
|
|
243
|
+
A `MessageFormatElement` is an object representing a node in the AST of a compiled translation message.
|
|
244
|
+
Simply put, any text that would end up being translated by a translator, i.e. anything that is not part of the [ICU Message syntax], will be passed to `transformElement`.
|
|
245
|
+
An example of a use case for this function would be adding [diacritics] to every letter in order to stress your UI from a vertical line-height perspective.
|
|
246
|
+
|
|
247
|
+
`transformMessage` receives the entire translation message _after_ `transformElement` has been applied to its individual elements.
|
|
248
|
+
An example of a use case for this function would be adding padding text to the start/end of your messages in order to easily identify which text in your app has not been extracted into a `translations.json` file.
|
|
249
|
+
|
|
250
|
+
By default, a generated language's messages will be based off the `devLanguage`'s messages, but this can be overridden by providing an `extends` value that references another language.
|
|
251
|
+
|
|
252
|
+
**vocab.config.js**
|
|
253
|
+
|
|
254
|
+
```js
|
|
255
|
+
function capitalize(message) {
|
|
256
|
+
return message.toUpperCase();
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function pad(message) {
|
|
260
|
+
return '[' + message + ']';
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
module.exports = {
|
|
264
|
+
devLanguage: 'en',
|
|
265
|
+
languages: [{ name: 'en' }, { name: 'fr' }],
|
|
266
|
+
generatedLanguages: [
|
|
267
|
+
{
|
|
268
|
+
name: 'generatedLanguage',
|
|
269
|
+
extends: 'en',
|
|
270
|
+
generator: {
|
|
271
|
+
transformElement: capitalize,
|
|
272
|
+
transformMessage: pad
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
]
|
|
276
|
+
};
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
Generated languages are consumed the same way as regular languages.
|
|
280
|
+
Any Vocab API that accepts a `language` parameter will work with a generated language as well as a regular language.
|
|
281
|
+
|
|
282
|
+
**App.tsx**
|
|
283
|
+
|
|
284
|
+
```tsx
|
|
285
|
+
const App = () => (
|
|
286
|
+
<VocabProvider language="generatedLanguage">
|
|
287
|
+
...
|
|
288
|
+
</VocabProvider>
|
|
289
|
+
);
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
[icu message syntax]: https://formatjs.io/docs/intl-messageformat/#message-syntax
|
|
293
|
+
[diacritics]: https://en.wikipedia.org/wiki/Diacritic
|
|
294
|
+
|
|
295
|
+
## Pseudo-localization
|
|
296
|
+
|
|
297
|
+
The `@vocab/pseudo-localize` package exports low-level functions that can be used for pseudo-localization of translation messages.
|
|
298
|
+
|
|
299
|
+
```ts
|
|
300
|
+
import {
|
|
301
|
+
extendVowels,
|
|
302
|
+
padString,
|
|
303
|
+
pseudoLocalize,
|
|
304
|
+
substituteCharacters
|
|
305
|
+
} from '@vocab/pseudo-localize';
|
|
306
|
+
|
|
307
|
+
const message = 'Hello';
|
|
308
|
+
|
|
309
|
+
// [Hello]
|
|
310
|
+
const paddedMessage = padString(message);
|
|
311
|
+
|
|
312
|
+
// Ḩẽƚƚö
|
|
313
|
+
const substitutedMessage = substituteCharacters(message);
|
|
314
|
+
|
|
315
|
+
// Heelloo
|
|
316
|
+
const extendedMessage = extendVowels(message);
|
|
317
|
+
|
|
318
|
+
// Extend the message and then substitute characters
|
|
319
|
+
// Ḩẽẽƚƚöö
|
|
320
|
+
const pseudoLocalizedMessage = pseudoLocalize(message);
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
Pseudo-localization is a transformation that can be applied to a translation message.
|
|
324
|
+
Vocab's implementation of this transformation contains the following elements:
|
|
325
|
+
|
|
326
|
+
- _Start and end markers (`padString`):_ All strings are encapsulated in `[` and `]`. If a developer doesn’t see these characters they know the string has been clipped by an inflexible UI element.
|
|
327
|
+
- _Transformation of ASCII characters to extended character equivalents (`substituteCharacters`):_ Stresses the UI from a vertical line-height perspective, tests font and encoding support, and weeds out strings that haven’t been externalized correctly (they will not have the pseudo-localization applied to them).
|
|
328
|
+
- _Padding text (`extendVowels`):_ Simulates translation-induced expansion. Vocab's implementation of this involves repeating vowels (and `y`) to simulate a 40% expansion in the message's length.
|
|
329
|
+
|
|
330
|
+
This Netflix technology [blog post][blog post] inspired Vocab's implementation of this
|
|
331
|
+
functionality.
|
|
332
|
+
|
|
333
|
+
### Generating a pseudo-localized language using Vocab
|
|
334
|
+
|
|
335
|
+
Vocab can generate a pseudo-localized language via the [`generatedLanguages` config][generated languages config], either via the webpack plugin or your `vocab.config.js` file.
|
|
336
|
+
`@vocab/pseudo-localize` exports a `generator` that can be used directly in your config.
|
|
337
|
+
|
|
338
|
+
**vocab.config.js**
|
|
339
|
+
|
|
340
|
+
```js
|
|
341
|
+
const { generator } = require('@vocab/pseudo-localize');
|
|
342
|
+
|
|
343
|
+
module.exports = {
|
|
344
|
+
devLanguage: 'en',
|
|
345
|
+
languages: [{ name: 'en' }, { name: 'fr' }],
|
|
346
|
+
generatedLanguages: [
|
|
347
|
+
{
|
|
348
|
+
name: 'pseudo',
|
|
349
|
+
extends: 'en',
|
|
350
|
+
generator
|
|
351
|
+
}
|
|
352
|
+
]
|
|
353
|
+
};
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
[blog post]: https://netflixtechblog.com/pseudo-localization-netflix-12fff76fbcbe
|
|
357
|
+
[generated languages config]: #generated-languages
|
|
358
|
+
|
|
212
359
|
## Use without React
|
|
213
360
|
|
|
214
361
|
If you need to use Vocab outside of React, you can access the returned Vocab file directly. You'll then be responsible for when to load translations and how to update on translation load.
|
|
@@ -285,6 +432,7 @@ Vocab can be used to synchronize your translations with translations from a remo
|
|
|
285
432
|
|
|
286
433
|
```bash
|
|
287
434
|
$ vocab push --branch my-branch
|
|
435
|
+
$ vocab push --branch my-branch --delete-unused-keys
|
|
288
436
|
$ vocab pull --branch my-branch
|
|
289
437
|
```
|
|
290
438
|
|
|
@@ -32,7 +32,12 @@ yargs__default['default'](process.argv.slice(2)).scriptName('vocab').option('con
|
|
|
32
32
|
}).command({
|
|
33
33
|
command: 'push',
|
|
34
34
|
builder: () => yargs__default['default'].options({
|
|
35
|
-
branch: branchDefinition
|
|
35
|
+
branch: branchDefinition,
|
|
36
|
+
'delete-unused-keys': {
|
|
37
|
+
type: 'boolean',
|
|
38
|
+
describe: 'Whether or not to delete unused keys after pushing',
|
|
39
|
+
default: false
|
|
40
|
+
}
|
|
36
41
|
}),
|
|
37
42
|
handler: async options => {
|
|
38
43
|
await phrase.push(options, config);
|
|
@@ -32,7 +32,12 @@ yargs__default['default'](process.argv.slice(2)).scriptName('vocab').option('con
|
|
|
32
32
|
}).command({
|
|
33
33
|
command: 'push',
|
|
34
34
|
builder: () => yargs__default['default'].options({
|
|
35
|
-
branch: branchDefinition
|
|
35
|
+
branch: branchDefinition,
|
|
36
|
+
'delete-unused-keys': {
|
|
37
|
+
type: 'boolean',
|
|
38
|
+
describe: 'Whether or not to delete unused keys after pushing',
|
|
39
|
+
default: false
|
|
40
|
+
}
|
|
36
41
|
}),
|
|
37
42
|
handler: async options => {
|
|
38
43
|
await phrase.push(options, config);
|
package/dist/vocab-cli.esm.js
CHANGED
|
@@ -25,7 +25,12 @@ yargs(process.argv.slice(2)).scriptName('vocab').option('config', {
|
|
|
25
25
|
}).command({
|
|
26
26
|
command: 'push',
|
|
27
27
|
builder: () => yargs.options({
|
|
28
|
-
branch: branchDefinition
|
|
28
|
+
branch: branchDefinition,
|
|
29
|
+
'delete-unused-keys': {
|
|
30
|
+
type: 'boolean',
|
|
31
|
+
describe: 'Whether or not to delete unused keys after pushing',
|
|
32
|
+
default: false
|
|
33
|
+
}
|
|
29
34
|
}),
|
|
30
35
|
handler: async options => {
|
|
31
36
|
await push(options, config);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vocab/cli",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"main": "dist/vocab-cli.cjs.js",
|
|
5
5
|
"module": "dist/vocab-cli.esm.js",
|
|
6
6
|
"bin": {
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@types/env-ci": "^3.1.0",
|
|
13
|
-
"@vocab/core": "^1.0
|
|
14
|
-
"@vocab/phrase": "^1.
|
|
13
|
+
"@vocab/core": "^1.1.0",
|
|
14
|
+
"@vocab/phrase": "^1.1.0",
|
|
15
15
|
"env-ci": "^5.0.2",
|
|
16
16
|
"fast-glob": "^3.2.4",
|
|
17
17
|
"form-data": "^3.0.0",
|
package/src/index.ts
CHANGED
|
@@ -29,7 +29,15 @@ yargs(process.argv.slice(2))
|
|
|
29
29
|
})
|
|
30
30
|
.command({
|
|
31
31
|
command: 'push',
|
|
32
|
-
builder: () =>
|
|
32
|
+
builder: () =>
|
|
33
|
+
yargs.options({
|
|
34
|
+
branch: branchDefinition,
|
|
35
|
+
'delete-unused-keys': {
|
|
36
|
+
type: 'boolean',
|
|
37
|
+
describe: 'Whether or not to delete unused keys after pushing',
|
|
38
|
+
default: false,
|
|
39
|
+
},
|
|
40
|
+
}),
|
|
33
41
|
handler: async (options) => {
|
|
34
42
|
await push(options, config!);
|
|
35
43
|
},
|