@vocab/phrase 1.2.8 → 1.3.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 +35 -3
- package/dist/declarations/src/index.d.ts +2 -2
- package/dist/declarations/src/pull-translations.d.ts +3 -2
- package/dist/declarations/src/push-translations.d.ts +1 -1
- package/dist/vocab-phrase.cjs.d.ts +1 -0
- package/dist/vocab-phrase.cjs.d.ts.map +1 -0
- package/dist/vocab-phrase.cjs.dev.js +13 -7
- package/dist/vocab-phrase.cjs.prod.js +13 -7
- package/dist/vocab-phrase.esm.js +13 -7
- package/package.json +2 -2
- package/dist/declarations/src/csv.d.ts +0 -10
- package/dist/declarations/src/file.d.ts +0 -4
- package/dist/declarations/src/logger.d.ts +0 -3
- package/dist/declarations/src/phrase-api.d.ts +0 -12
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@ $ npm i --save @vocab/core @vocab/react
|
|
|
29
29
|
|
|
30
30
|
### Step 2: Configure Vocab
|
|
31
31
|
|
|
32
|
-
You can configure Vocab directly when calling the API or via a `vocab.config.js` file.
|
|
32
|
+
You can configure Vocab directly when calling the API or via a `vocab.config.js` or `vocab.config.cjs` file.
|
|
33
33
|
|
|
34
34
|
In this example we've configured two languages, English and French, where our initial `translation.json` files will use English.
|
|
35
35
|
|
|
@@ -184,7 +184,7 @@ t('my key with component', {
|
|
|
184
184
|
|
|
185
185
|
## Configuration
|
|
186
186
|
|
|
187
|
-
Configuration can either be passed into the Node API directly or be gathered from the nearest _vocab.config.js_ file.
|
|
187
|
+
Configuration can either be passed into the Node API directly or be gathered from the nearest _vocab.config.js_ or _vocab.config.cjs_ file.
|
|
188
188
|
|
|
189
189
|
**vocab.config.js**
|
|
190
190
|
|
|
@@ -341,7 +341,7 @@ functionality.
|
|
|
341
341
|
|
|
342
342
|
### Generating a pseudo-localized language using Vocab
|
|
343
343
|
|
|
344
|
-
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.
|
|
344
|
+
Vocab can generate a pseudo-localized language via the [`generatedLanguages` config][generated languages config], either via the webpack plugin or your `vocab.config.js` or `vocab.config.cjs` file.
|
|
345
345
|
`@vocab/pseudo-localize` exports a `generator` that can be used directly in your config.
|
|
346
346
|
|
|
347
347
|
**vocab.config.js**
|
|
@@ -506,6 +506,38 @@ Tags on keys in other languages will be ignored.
|
|
|
506
506
|
[tags]: https://support.phrase.com/hc/en-us/articles/5822598372252-Tags-Strings-
|
|
507
507
|
[configuration]: #Configuration
|
|
508
508
|
|
|
509
|
+
#### Global key
|
|
510
|
+
|
|
511
|
+
`vocab push` and `vocab pull` can support global keys mapping. When you want certain translations to use a specific/custom key in Phrase, add the `globalKey` to the structure.
|
|
512
|
+
|
|
513
|
+
```jsonc
|
|
514
|
+
// translations.json
|
|
515
|
+
{
|
|
516
|
+
"Hello": {
|
|
517
|
+
"message": "Hello",
|
|
518
|
+
"globalKey": "hello"
|
|
519
|
+
},
|
|
520
|
+
"Goodbye": {
|
|
521
|
+
"message": "Goodbye",
|
|
522
|
+
"globalKey": "app.goodbye.label"
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
```
|
|
526
|
+
|
|
527
|
+
In the above example,
|
|
528
|
+
|
|
529
|
+
- `vocab push` will push the `hello` and `app.goodbye.label` keys to Phrase.
|
|
530
|
+
- `vocab pull` will pull translations from Phrase and map them to the `hello` and `app.goodbye.label` keys.
|
|
531
|
+
|
|
532
|
+
##### Error on no translation for global key
|
|
533
|
+
|
|
534
|
+
By default, `vocab pull` will not error if a translation is missing in Phrase for a translation with a global key.
|
|
535
|
+
If you want to throw an error in this situation, pass the `--error-on-no-global-key-translation` flag:
|
|
536
|
+
|
|
537
|
+
```sh
|
|
538
|
+
vocab pull --error-on-no-global-key-translation
|
|
539
|
+
```
|
|
540
|
+
|
|
509
541
|
## Troubleshooting
|
|
510
542
|
|
|
511
543
|
### Problem: Passed locale is being ignored or using en-US instead
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { pull } from
|
|
2
|
-
export { push } from
|
|
1
|
+
export { pull } from "./pull-translations.js";
|
|
2
|
+
export { push } from "./push-translations.js";
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type UserConfig } from '@vocab/core';
|
|
2
2
|
interface PullOptions {
|
|
3
3
|
branch?: string;
|
|
4
4
|
deleteUnusedKeys?: boolean;
|
|
5
|
+
errorOnNoGlobalKeyTranslation?: boolean;
|
|
5
6
|
}
|
|
6
|
-
export declare function pull({ branch }: PullOptions, config: UserConfig): Promise<void>;
|
|
7
|
+
export declare function pull({ branch, errorOnNoGlobalKeyTranslation }: PullOptions, config: UserConfig): Promise<void>;
|
|
7
8
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vocab-phrase.cjs.d.ts","sourceRoot":"","sources":["./declarations/src/index.d.ts"],"names":[],"mappings":"AAAA"}
|
|
@@ -42,8 +42,8 @@ function translationsToCsv(translations, devLanguage) {
|
|
|
42
42
|
const devLanguageRow = [...sharedData, message];
|
|
43
43
|
csvFilesByLanguage[devLanguage].push(devLanguageRow);
|
|
44
44
|
altLanguages.map(language => {
|
|
45
|
-
var _translations$languag
|
|
46
|
-
const altTranslationMessage = (_translations$languag = translations[language]) === null || _translations$languag === void 0
|
|
45
|
+
var _translations$languag;
|
|
46
|
+
const altTranslationMessage = (_translations$languag = translations[language]) === null || _translations$languag === void 0 || (_translations$languag = _translations$languag[key]) === null || _translations$languag === void 0 ? void 0 : _translations$languag.message;
|
|
47
47
|
if (altTranslationMessage) {
|
|
48
48
|
csvFilesByLanguage[language].push([...sharedData, altTranslationMessage]);
|
|
49
49
|
}
|
|
@@ -224,7 +224,8 @@ async function ensureBranch(branch) {
|
|
|
224
224
|
}
|
|
225
225
|
|
|
226
226
|
async function pull({
|
|
227
|
-
branch = 'local-development'
|
|
227
|
+
branch = 'local-development',
|
|
228
|
+
errorOnNoGlobalKeyTranslation
|
|
228
229
|
}, config) {
|
|
229
230
|
trace(`Pulling translations from branch ${branch}`);
|
|
230
231
|
await ensureBranch(branch);
|
|
@@ -251,9 +252,10 @@ async function pull({
|
|
|
251
252
|
};
|
|
252
253
|
const localKeys = Object.keys(defaultValues);
|
|
253
254
|
for (const key of localKeys) {
|
|
255
|
+
var _defaultValues$key$gl;
|
|
254
256
|
defaultValues[key] = {
|
|
255
257
|
...defaultValues[key],
|
|
256
|
-
...allPhraseTranslations[config.devLanguage][core.getUniqueKey(key, loadedTranslation.namespace)]
|
|
258
|
+
...allPhraseTranslations[config.devLanguage][(_defaultValues$key$gl = defaultValues[key].globalKey) !== null && _defaultValues$key$gl !== void 0 ? _defaultValues$key$gl : core.getUniqueKey(key, loadedTranslation.namespace)]
|
|
257
259
|
};
|
|
258
260
|
}
|
|
259
261
|
|
|
@@ -269,11 +271,14 @@ async function pull({
|
|
|
269
271
|
};
|
|
270
272
|
const phraseAltTranslations = allPhraseTranslations[alternativeLanguage];
|
|
271
273
|
for (const key of localKeys) {
|
|
272
|
-
var _phraseAltTranslation;
|
|
273
|
-
const phraseKey = core.getUniqueKey(key, loadedTranslation.namespace);
|
|
274
|
+
var _defaultValues$key$gl2, _phraseAltTranslation;
|
|
275
|
+
const phraseKey = (_defaultValues$key$gl2 = defaultValues[key].globalKey) !== null && _defaultValues$key$gl2 !== void 0 ? _defaultValues$key$gl2 : core.getUniqueKey(key, loadedTranslation.namespace);
|
|
274
276
|
const phraseTranslationMessage = (_phraseAltTranslation = phraseAltTranslations[phraseKey]) === null || _phraseAltTranslation === void 0 ? void 0 : _phraseAltTranslation.message;
|
|
275
277
|
if (!phraseTranslationMessage) {
|
|
276
278
|
trace(`Missing translation. No translation for key ${key} in phrase as ${phraseKey} in language ${alternativeLanguage}.`);
|
|
279
|
+
if (errorOnNoGlobalKeyTranslation && defaultValues[key].globalKey) {
|
|
280
|
+
throw new Error(`Missing translation for global key ${key} in language ${alternativeLanguage}`);
|
|
281
|
+
}
|
|
277
282
|
continue;
|
|
278
283
|
}
|
|
279
284
|
altTranslations[key] = {
|
|
@@ -324,7 +329,6 @@ async function push({
|
|
|
324
329
|
}
|
|
325
330
|
} = loadedTranslation;
|
|
326
331
|
for (const localKey of Object.keys(localTranslations)) {
|
|
327
|
-
const phraseKey = core.getUniqueKey(localKey, loadedTranslation.namespace);
|
|
328
332
|
const {
|
|
329
333
|
tags = [],
|
|
330
334
|
...localTranslation
|
|
@@ -332,6 +336,8 @@ async function push({
|
|
|
332
336
|
if (language === config.devLanguage) {
|
|
333
337
|
localTranslation.tags = [...tags, ...sharedTags];
|
|
334
338
|
}
|
|
339
|
+
const globalKey = loadedTranslation.languages[config.devLanguage][localKey].globalKey;
|
|
340
|
+
const phraseKey = globalKey !== null && globalKey !== void 0 ? globalKey : core.getUniqueKey(localKey, loadedTranslation.namespace);
|
|
335
341
|
phraseTranslations[language][phraseKey] = localTranslation;
|
|
336
342
|
}
|
|
337
343
|
}
|
|
@@ -42,8 +42,8 @@ function translationsToCsv(translations, devLanguage) {
|
|
|
42
42
|
const devLanguageRow = [...sharedData, message];
|
|
43
43
|
csvFilesByLanguage[devLanguage].push(devLanguageRow);
|
|
44
44
|
altLanguages.map(language => {
|
|
45
|
-
var _translations$languag
|
|
46
|
-
const altTranslationMessage = (_translations$languag = translations[language]) === null || _translations$languag === void 0
|
|
45
|
+
var _translations$languag;
|
|
46
|
+
const altTranslationMessage = (_translations$languag = translations[language]) === null || _translations$languag === void 0 || (_translations$languag = _translations$languag[key]) === null || _translations$languag === void 0 ? void 0 : _translations$languag.message;
|
|
47
47
|
if (altTranslationMessage) {
|
|
48
48
|
csvFilesByLanguage[language].push([...sharedData, altTranslationMessage]);
|
|
49
49
|
}
|
|
@@ -224,7 +224,8 @@ async function ensureBranch(branch) {
|
|
|
224
224
|
}
|
|
225
225
|
|
|
226
226
|
async function pull({
|
|
227
|
-
branch = 'local-development'
|
|
227
|
+
branch = 'local-development',
|
|
228
|
+
errorOnNoGlobalKeyTranslation
|
|
228
229
|
}, config) {
|
|
229
230
|
trace(`Pulling translations from branch ${branch}`);
|
|
230
231
|
await ensureBranch(branch);
|
|
@@ -251,9 +252,10 @@ async function pull({
|
|
|
251
252
|
};
|
|
252
253
|
const localKeys = Object.keys(defaultValues);
|
|
253
254
|
for (const key of localKeys) {
|
|
255
|
+
var _defaultValues$key$gl;
|
|
254
256
|
defaultValues[key] = {
|
|
255
257
|
...defaultValues[key],
|
|
256
|
-
...allPhraseTranslations[config.devLanguage][core.getUniqueKey(key, loadedTranslation.namespace)]
|
|
258
|
+
...allPhraseTranslations[config.devLanguage][(_defaultValues$key$gl = defaultValues[key].globalKey) !== null && _defaultValues$key$gl !== void 0 ? _defaultValues$key$gl : core.getUniqueKey(key, loadedTranslation.namespace)]
|
|
257
259
|
};
|
|
258
260
|
}
|
|
259
261
|
|
|
@@ -269,11 +271,14 @@ async function pull({
|
|
|
269
271
|
};
|
|
270
272
|
const phraseAltTranslations = allPhraseTranslations[alternativeLanguage];
|
|
271
273
|
for (const key of localKeys) {
|
|
272
|
-
var _phraseAltTranslation;
|
|
273
|
-
const phraseKey = core.getUniqueKey(key, loadedTranslation.namespace);
|
|
274
|
+
var _defaultValues$key$gl2, _phraseAltTranslation;
|
|
275
|
+
const phraseKey = (_defaultValues$key$gl2 = defaultValues[key].globalKey) !== null && _defaultValues$key$gl2 !== void 0 ? _defaultValues$key$gl2 : core.getUniqueKey(key, loadedTranslation.namespace);
|
|
274
276
|
const phraseTranslationMessage = (_phraseAltTranslation = phraseAltTranslations[phraseKey]) === null || _phraseAltTranslation === void 0 ? void 0 : _phraseAltTranslation.message;
|
|
275
277
|
if (!phraseTranslationMessage) {
|
|
276
278
|
trace(`Missing translation. No translation for key ${key} in phrase as ${phraseKey} in language ${alternativeLanguage}.`);
|
|
279
|
+
if (errorOnNoGlobalKeyTranslation && defaultValues[key].globalKey) {
|
|
280
|
+
throw new Error(`Missing translation for global key ${key} in language ${alternativeLanguage}`);
|
|
281
|
+
}
|
|
277
282
|
continue;
|
|
278
283
|
}
|
|
279
284
|
altTranslations[key] = {
|
|
@@ -324,7 +329,6 @@ async function push({
|
|
|
324
329
|
}
|
|
325
330
|
} = loadedTranslation;
|
|
326
331
|
for (const localKey of Object.keys(localTranslations)) {
|
|
327
|
-
const phraseKey = core.getUniqueKey(localKey, loadedTranslation.namespace);
|
|
328
332
|
const {
|
|
329
333
|
tags = [],
|
|
330
334
|
...localTranslation
|
|
@@ -332,6 +336,8 @@ async function push({
|
|
|
332
336
|
if (language === config.devLanguage) {
|
|
333
337
|
localTranslation.tags = [...tags, ...sharedTags];
|
|
334
338
|
}
|
|
339
|
+
const globalKey = loadedTranslation.languages[config.devLanguage][localKey].globalKey;
|
|
340
|
+
const phraseKey = globalKey !== null && globalKey !== void 0 ? globalKey : core.getUniqueKey(localKey, loadedTranslation.namespace);
|
|
335
341
|
phraseTranslations[language][phraseKey] = localTranslation;
|
|
336
342
|
}
|
|
337
343
|
}
|
package/dist/vocab-phrase.esm.js
CHANGED
|
@@ -30,8 +30,8 @@ function translationsToCsv(translations, devLanguage) {
|
|
|
30
30
|
const devLanguageRow = [...sharedData, message];
|
|
31
31
|
csvFilesByLanguage[devLanguage].push(devLanguageRow);
|
|
32
32
|
altLanguages.map(language => {
|
|
33
|
-
var _translations$languag
|
|
34
|
-
const altTranslationMessage = (_translations$languag = translations[language]) === null || _translations$languag === void 0
|
|
33
|
+
var _translations$languag;
|
|
34
|
+
const altTranslationMessage = (_translations$languag = translations[language]) === null || _translations$languag === void 0 || (_translations$languag = _translations$languag[key]) === null || _translations$languag === void 0 ? void 0 : _translations$languag.message;
|
|
35
35
|
if (altTranslationMessage) {
|
|
36
36
|
csvFilesByLanguage[language].push([...sharedData, altTranslationMessage]);
|
|
37
37
|
}
|
|
@@ -212,7 +212,8 @@ async function ensureBranch(branch) {
|
|
|
212
212
|
}
|
|
213
213
|
|
|
214
214
|
async function pull({
|
|
215
|
-
branch = 'local-development'
|
|
215
|
+
branch = 'local-development',
|
|
216
|
+
errorOnNoGlobalKeyTranslation
|
|
216
217
|
}, config) {
|
|
217
218
|
trace(`Pulling translations from branch ${branch}`);
|
|
218
219
|
await ensureBranch(branch);
|
|
@@ -239,9 +240,10 @@ async function pull({
|
|
|
239
240
|
};
|
|
240
241
|
const localKeys = Object.keys(defaultValues);
|
|
241
242
|
for (const key of localKeys) {
|
|
243
|
+
var _defaultValues$key$gl;
|
|
242
244
|
defaultValues[key] = {
|
|
243
245
|
...defaultValues[key],
|
|
244
|
-
...allPhraseTranslations[config.devLanguage][getUniqueKey(key, loadedTranslation.namespace)]
|
|
246
|
+
...allPhraseTranslations[config.devLanguage][(_defaultValues$key$gl = defaultValues[key].globalKey) !== null && _defaultValues$key$gl !== void 0 ? _defaultValues$key$gl : getUniqueKey(key, loadedTranslation.namespace)]
|
|
245
247
|
};
|
|
246
248
|
}
|
|
247
249
|
|
|
@@ -257,11 +259,14 @@ async function pull({
|
|
|
257
259
|
};
|
|
258
260
|
const phraseAltTranslations = allPhraseTranslations[alternativeLanguage];
|
|
259
261
|
for (const key of localKeys) {
|
|
260
|
-
var _phraseAltTranslation;
|
|
261
|
-
const phraseKey = getUniqueKey(key, loadedTranslation.namespace);
|
|
262
|
+
var _defaultValues$key$gl2, _phraseAltTranslation;
|
|
263
|
+
const phraseKey = (_defaultValues$key$gl2 = defaultValues[key].globalKey) !== null && _defaultValues$key$gl2 !== void 0 ? _defaultValues$key$gl2 : getUniqueKey(key, loadedTranslation.namespace);
|
|
262
264
|
const phraseTranslationMessage = (_phraseAltTranslation = phraseAltTranslations[phraseKey]) === null || _phraseAltTranslation === void 0 ? void 0 : _phraseAltTranslation.message;
|
|
263
265
|
if (!phraseTranslationMessage) {
|
|
264
266
|
trace(`Missing translation. No translation for key ${key} in phrase as ${phraseKey} in language ${alternativeLanguage}.`);
|
|
267
|
+
if (errorOnNoGlobalKeyTranslation && defaultValues[key].globalKey) {
|
|
268
|
+
throw new Error(`Missing translation for global key ${key} in language ${alternativeLanguage}`);
|
|
269
|
+
}
|
|
265
270
|
continue;
|
|
266
271
|
}
|
|
267
272
|
altTranslations[key] = {
|
|
@@ -312,7 +317,6 @@ async function push({
|
|
|
312
317
|
}
|
|
313
318
|
} = loadedTranslation;
|
|
314
319
|
for (const localKey of Object.keys(localTranslations)) {
|
|
315
|
-
const phraseKey = getUniqueKey(localKey, loadedTranslation.namespace);
|
|
316
320
|
const {
|
|
317
321
|
tags = [],
|
|
318
322
|
...localTranslation
|
|
@@ -320,6 +324,8 @@ async function push({
|
|
|
320
324
|
if (language === config.devLanguage) {
|
|
321
325
|
localTranslation.tags = [...tags, ...sharedTags];
|
|
322
326
|
}
|
|
327
|
+
const globalKey = loadedTranslation.languages[config.devLanguage][localKey].globalKey;
|
|
328
|
+
const phraseKey = globalKey !== null && globalKey !== void 0 ? globalKey : getUniqueKey(localKey, loadedTranslation.namespace);
|
|
323
329
|
phraseTranslations[language][phraseKey] = localTranslation;
|
|
324
330
|
}
|
|
325
331
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vocab/phrase",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"main": "dist/vocab-phrase.cjs.js",
|
|
5
5
|
"module": "dist/vocab-phrase.esm.js",
|
|
6
6
|
"author": "SEEK",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@vocab/core": "^1.
|
|
9
|
+
"@vocab/core": "^1.6.0",
|
|
10
10
|
"chalk": "^4.1.0",
|
|
11
11
|
"csv-stringify": "^6.2.3",
|
|
12
12
|
"debug": "^4.3.1",
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { TranslationsByLanguage } from '@vocab/core';
|
|
2
|
-
export declare function translationsToCsv(translations: TranslationsByLanguage, devLanguage: string): {
|
|
3
|
-
csvFileStrings: {
|
|
4
|
-
[k: string]: string;
|
|
5
|
-
};
|
|
6
|
-
keyIndex: number;
|
|
7
|
-
messageIndex: number;
|
|
8
|
-
commentIndex: number;
|
|
9
|
-
tagColumn: number;
|
|
10
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { TranslationsByLanguage } from '@vocab/core';
|
|
2
|
-
import fetch from 'node-fetch';
|
|
3
|
-
export declare function callPhrase<T = any>(relativePath: string, options?: Parameters<typeof fetch>[1]): Promise<T>;
|
|
4
|
-
export declare function pullAllTranslations(branch: string): Promise<TranslationsByLanguage>;
|
|
5
|
-
export declare function pushTranslations(translationsByLanguage: TranslationsByLanguage, { devLanguage, branch }: {
|
|
6
|
-
devLanguage: string;
|
|
7
|
-
branch: string;
|
|
8
|
-
}): Promise<{
|
|
9
|
-
devLanguageUploadId: string;
|
|
10
|
-
}>;
|
|
11
|
-
export declare function deleteUnusedKeys(uploadId: string, branch: string): Promise<void>;
|
|
12
|
-
export declare function ensureBranch(branch: string): Promise<void>;
|