Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@vocab/phrase

Package Overview
Dependencies
Maintainers
4
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vocab/phrase - npm Package Compare versions

Comparing version 1.2.8 to 1.3.0

3

dist/declarations/src/pull-translations.d.ts

@@ -5,4 +5,5 @@ import type { UserConfig } from '@vocab/core';

deleteUnusedKeys?: boolean;
errorOnNoGlobalKeyTranslation?: boolean;
}
export declare function pull({ branch }: PullOptions, config: UserConfig): Promise<void>;
export declare function pull({ branch, errorOnNoGlobalKeyTranslation }: PullOptions, config: UserConfig): Promise<void>;
export {};

@@ -227,3 +227,4 @@ 'use strict';

async function pull({
branch = 'local-development'
branch = 'local-development',
errorOnNoGlobalKeyTranslation
}, config) {

@@ -255,5 +256,6 @@ trace(`Pulling translations from branch ${branch}`);

for (const key of localKeys) {
var _defaultValues$key$gl;
defaultValues[key] = {
...defaultValues[key],
...allPhraseTranslations[config.devLanguage][core.getUniqueKey(key, loadedTranslation.namespace)]
...allPhraseTranslations[config.devLanguage][(_defaultValues$key$gl = defaultValues[key].globalKey) !== null && _defaultValues$key$gl !== void 0 ? _defaultValues$key$gl : core.getUniqueKey(key, loadedTranslation.namespace)]
};

@@ -274,7 +276,10 @@ }

for (const key of localKeys) {
var _phraseAltTranslation;
const phraseKey = core.getUniqueKey(key, loadedTranslation.namespace);
var _defaultValues$key$gl2, _phraseAltTranslation;
const phraseKey = (_defaultValues$key$gl2 = defaultValues[key].globalKey) !== null && _defaultValues$key$gl2 !== void 0 ? _defaultValues$key$gl2 : core.getUniqueKey(key, loadedTranslation.namespace);
const phraseTranslationMessage = (_phraseAltTranslation = phraseAltTranslations[phraseKey]) === null || _phraseAltTranslation === void 0 ? void 0 : _phraseAltTranslation.message;
if (!phraseTranslationMessage) {
trace(`Missing translation. No translation for key ${key} in phrase as ${phraseKey} in language ${alternativeLanguage}.`);
if (errorOnNoGlobalKeyTranslation && defaultValues[key].globalKey) {
throw new Error(`Missing translation for global key ${key} in language ${alternativeLanguage}`);
}
continue;

@@ -330,3 +335,2 @@ }

for (const localKey of Object.keys(localTranslations)) {
const phraseKey = core.getUniqueKey(localKey, loadedTranslation.namespace);
const {

@@ -339,2 +343,4 @@ tags = [],

}
const globalKey = loadedTranslation.languages[config.devLanguage][localKey].globalKey;
const phraseKey = globalKey !== null && globalKey !== void 0 ? globalKey : core.getUniqueKey(localKey, loadedTranslation.namespace);
phraseTranslations[language][phraseKey] = localTranslation;

@@ -341,0 +347,0 @@ }

@@ -227,3 +227,4 @@ 'use strict';

async function pull({
branch = 'local-development'
branch = 'local-development',
errorOnNoGlobalKeyTranslation
}, config) {

@@ -255,5 +256,6 @@ trace(`Pulling translations from branch ${branch}`);

for (const key of localKeys) {
var _defaultValues$key$gl;
defaultValues[key] = {
...defaultValues[key],
...allPhraseTranslations[config.devLanguage][core.getUniqueKey(key, loadedTranslation.namespace)]
...allPhraseTranslations[config.devLanguage][(_defaultValues$key$gl = defaultValues[key].globalKey) !== null && _defaultValues$key$gl !== void 0 ? _defaultValues$key$gl : core.getUniqueKey(key, loadedTranslation.namespace)]
};

@@ -274,7 +276,10 @@ }

for (const key of localKeys) {
var _phraseAltTranslation;
const phraseKey = core.getUniqueKey(key, loadedTranslation.namespace);
var _defaultValues$key$gl2, _phraseAltTranslation;
const phraseKey = (_defaultValues$key$gl2 = defaultValues[key].globalKey) !== null && _defaultValues$key$gl2 !== void 0 ? _defaultValues$key$gl2 : core.getUniqueKey(key, loadedTranslation.namespace);
const phraseTranslationMessage = (_phraseAltTranslation = phraseAltTranslations[phraseKey]) === null || _phraseAltTranslation === void 0 ? void 0 : _phraseAltTranslation.message;
if (!phraseTranslationMessage) {
trace(`Missing translation. No translation for key ${key} in phrase as ${phraseKey} in language ${alternativeLanguage}.`);
if (errorOnNoGlobalKeyTranslation && defaultValues[key].globalKey) {
throw new Error(`Missing translation for global key ${key} in language ${alternativeLanguage}`);
}
continue;

@@ -330,3 +335,2 @@ }

for (const localKey of Object.keys(localTranslations)) {
const phraseKey = core.getUniqueKey(localKey, loadedTranslation.namespace);
const {

@@ -339,2 +343,4 @@ tags = [],

}
const globalKey = loadedTranslation.languages[config.devLanguage][localKey].globalKey;
const phraseKey = globalKey !== null && globalKey !== void 0 ? globalKey : core.getUniqueKey(localKey, loadedTranslation.namespace);
phraseTranslations[language][phraseKey] = localTranslation;

@@ -341,0 +347,0 @@ }

@@ -215,3 +215,4 @@ import { promises } from 'fs';

async function pull({
branch = 'local-development'
branch = 'local-development',
errorOnNoGlobalKeyTranslation
}, config) {

@@ -243,5 +244,6 @@ trace(`Pulling translations from branch ${branch}`);

for (const key of localKeys) {
var _defaultValues$key$gl;
defaultValues[key] = {
...defaultValues[key],
...allPhraseTranslations[config.devLanguage][getUniqueKey(key, loadedTranslation.namespace)]
...allPhraseTranslations[config.devLanguage][(_defaultValues$key$gl = defaultValues[key].globalKey) !== null && _defaultValues$key$gl !== void 0 ? _defaultValues$key$gl : getUniqueKey(key, loadedTranslation.namespace)]
};

@@ -262,7 +264,10 @@ }

for (const key of localKeys) {
var _phraseAltTranslation;
const phraseKey = getUniqueKey(key, loadedTranslation.namespace);
var _defaultValues$key$gl2, _phraseAltTranslation;
const phraseKey = (_defaultValues$key$gl2 = defaultValues[key].globalKey) !== null && _defaultValues$key$gl2 !== void 0 ? _defaultValues$key$gl2 : getUniqueKey(key, loadedTranslation.namespace);
const phraseTranslationMessage = (_phraseAltTranslation = phraseAltTranslations[phraseKey]) === null || _phraseAltTranslation === void 0 ? void 0 : _phraseAltTranslation.message;
if (!phraseTranslationMessage) {
trace(`Missing translation. No translation for key ${key} in phrase as ${phraseKey} in language ${alternativeLanguage}.`);
if (errorOnNoGlobalKeyTranslation && defaultValues[key].globalKey) {
throw new Error(`Missing translation for global key ${key} in language ${alternativeLanguage}`);
}
continue;

@@ -318,3 +323,2 @@ }

for (const localKey of Object.keys(localTranslations)) {
const phraseKey = getUniqueKey(localKey, loadedTranslation.namespace);
const {

@@ -327,2 +331,4 @@ tags = [],

}
const globalKey = loadedTranslation.languages[config.devLanguage][localKey].globalKey;
const phraseKey = globalKey !== null && globalKey !== void 0 ? globalKey : getUniqueKey(localKey, loadedTranslation.namespace);
phraseTranslations[language][phraseKey] = localTranslation;

@@ -329,0 +335,0 @@ }

{
"name": "@vocab/phrase",
"version": "1.2.8",
"version": "1.3.0",
"main": "dist/vocab-phrase.cjs.js",

@@ -9,3 +9,3 @@ "module": "dist/vocab-phrase.esm.js",

"dependencies": {
"@vocab/core": "^1.4.0",
"@vocab/core": "^1.5.0",
"chalk": "^4.1.0",

@@ -12,0 +12,0 @@ "csv-stringify": "^6.2.3",

@@ -509,2 +509,34 @@ # Vocab

#### Global key
`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.
```jsonc
// translations.json
{
"Hello": {
"message": "Hello",
"globalKey": "hello"
},
"Goodbye": {
"message": "Goodbye",
"globalKey": "app.goodbye.label"
}
}
```
In the above example,
- `vocab push` will push the `hello` and `app.goodbye.label` keys to Phrase.
- `vocab pull` will pull translations from Phrase and map them to the `hello` and `app.goodbye.label` keys.
##### Error on no translation for global key
By default, `vocab pull` will not error if a translation is missing in Phrase for a translation with a global key.
If you want to throw an error in this situation, pass the `--error-on-no-global-key-translation` flag:
```sh
vocab pull --error-on-no-global-key-translation
```
## Troubleshooting

@@ -511,0 +543,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc