mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-30 09:36:42 +10:00
Add confirmation prompt for new translation
This commit is contained in:
parent
fecd3ae06e
commit
b565099707
1 changed files with 37 additions and 1 deletions
38
translations
38
translations
|
|
@ -33,6 +33,7 @@ const run = () => {
|
|||
let sourceKeys;
|
||||
let targetKeys;
|
||||
let key;
|
||||
let translation;
|
||||
|
||||
selectLanguage()
|
||||
.then(answers => {
|
||||
|
|
@ -62,7 +63,19 @@ const run = () => {
|
|||
}
|
||||
})
|
||||
.then(answers => {
|
||||
target[key] = answers.value;
|
||||
translation = answers.value;
|
||||
return confirmTranslation(targetLang, key, translation);
|
||||
})
|
||||
.then(answers => {
|
||||
// a bool value if translation addition is confirmed
|
||||
const confirmation = answers.value;
|
||||
|
||||
if (!confirmation) {
|
||||
console.log('Discarding new translation');
|
||||
throw new BreakSignal();
|
||||
}
|
||||
|
||||
target[key] = translation;
|
||||
|
||||
const sorted = sort(target);
|
||||
const data = JSON.stringify(sorted, null, 2);
|
||||
|
|
@ -179,4 +192,27 @@ const addTranslation = (targetLang, key, source) => {
|
|||
]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Prompt for a confirming a new translation with 'y' or 'N'.
|
||||
*
|
||||
* @param {String} targetLang The language that is being translated
|
||||
* @param {String} key Key for the new translation
|
||||
* @param {Object} source Source language translations
|
||||
*
|
||||
* @return a Promise with the answers hash containing a boolean value field
|
||||
*/
|
||||
const confirmTranslation = (targetLang, key, translation) => {
|
||||
return inquirer.prompt([
|
||||
{
|
||||
type: 'input',
|
||||
name: 'value',
|
||||
message: `Do you want to add the ${targetLangName(targetLang)} translation ${chalk.green(
|
||||
translation
|
||||
)} for the key ${chalk.blueBright(key)}? (y/N)`,
|
||||
filter: value => (value === 'y' ? true : value === 'N' ? false : value),
|
||||
validate: value => value === true || value === false,
|
||||
},
|
||||
]);
|
||||
};
|
||||
|
||||
run();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue