@vocab/core 1.3.1 → 1.5.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/README.md
CHANGED
|
@@ -450,7 +450,7 @@ $ vocab pull --branch my-branch
|
|
|
450
450
|
|
|
451
451
|
When uploading translations, Phrase identifies keys that exist in the Phrase project, but were not
|
|
452
452
|
referenced in the upload. These keys can be deleted from Phrase by providing the
|
|
453
|
-
|
|
453
|
+
`--delete-unused-keys` flag to `vocab push`. E.g.
|
|
454
454
|
|
|
455
455
|
```sh
|
|
456
456
|
$ vocab push --branch my-branch --delete-unused-keys
|
|
@@ -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
|
|
@@ -51,6 +51,7 @@ export type TranslationFile<Language extends LanguageName, FormatFnByKey extends
|
|
|
51
51
|
*/
|
|
52
52
|
load: (language: Language) => Promise<void>;
|
|
53
53
|
};
|
|
54
|
+
export type TranslationKeys<Translations extends TranslationFile<any, ParsedFormatFnByKey>> = keyof Awaited<ReturnType<Translations['getMessages']>>;
|
|
54
55
|
export interface LanguageTarget {
|
|
55
56
|
name: LanguageName;
|
|
56
57
|
extends?: LanguageName;
|
|
@@ -98,6 +99,7 @@ export interface TranslationData {
|
|
|
98
99
|
message: TranslationMessage;
|
|
99
100
|
description?: string;
|
|
100
101
|
tags?: Tags;
|
|
102
|
+
globalKey?: string;
|
|
101
103
|
}
|
|
102
104
|
export type TranslationsByKey<Key extends TranslationKey = string> = Record<Key, TranslationData>;
|
|
103
105
|
export type TranslationFileContents = TranslationsByKey & {
|
|
@@ -433,6 +433,13 @@ async function loadAllTranslations({
|
|
|
433
433
|
throw new Error(`Duplicate keys found. Key with namespace ${loadedTranslation.namespace} and key ${key} was found multiple times.`);
|
|
434
434
|
}
|
|
435
435
|
keys.add(uniqueKey);
|
|
436
|
+
const globalKey = loadedTranslation.languages[config.devLanguage][key].globalKey;
|
|
437
|
+
if (globalKey) {
|
|
438
|
+
if (keys.has(globalKey)) {
|
|
439
|
+
throw new Error(`Duplicate keys found. Key with global key ${globalKey} and key ${key} was found multiple times`);
|
|
440
|
+
}
|
|
441
|
+
keys.add(globalKey);
|
|
442
|
+
}
|
|
436
443
|
}
|
|
437
444
|
}
|
|
438
445
|
return result;
|
|
@@ -433,6 +433,13 @@ async function loadAllTranslations({
|
|
|
433
433
|
throw new Error(`Duplicate keys found. Key with namespace ${loadedTranslation.namespace} and key ${key} was found multiple times.`);
|
|
434
434
|
}
|
|
435
435
|
keys.add(uniqueKey);
|
|
436
|
+
const globalKey = loadedTranslation.languages[config.devLanguage][key].globalKey;
|
|
437
|
+
if (globalKey) {
|
|
438
|
+
if (keys.has(globalKey)) {
|
|
439
|
+
throw new Error(`Duplicate keys found. Key with global key ${globalKey} and key ${key} was found multiple times`);
|
|
440
|
+
}
|
|
441
|
+
keys.add(globalKey);
|
|
442
|
+
}
|
|
436
443
|
}
|
|
437
444
|
}
|
|
438
445
|
return result;
|
package/dist/vocab-core.esm.js
CHANGED
|
@@ -417,6 +417,13 @@ async function loadAllTranslations({
|
|
|
417
417
|
throw new Error(`Duplicate keys found. Key with namespace ${loadedTranslation.namespace} and key ${key} was found multiple times.`);
|
|
418
418
|
}
|
|
419
419
|
keys.add(uniqueKey);
|
|
420
|
+
const globalKey = loadedTranslation.languages[config.devLanguage][key].globalKey;
|
|
421
|
+
if (globalKey) {
|
|
422
|
+
if (keys.has(globalKey)) {
|
|
423
|
+
throw new Error(`Duplicate keys found. Key with global key ${globalKey} and key ${key} was found multiple times`);
|
|
424
|
+
}
|
|
425
|
+
keys.add(globalKey);
|
|
426
|
+
}
|
|
420
427
|
}
|
|
421
428
|
}
|
|
422
429
|
return result;
|