From ac0282d92a21e363b5c2b861fe605f6c3a2e6c54 Mon Sep 17 00:00:00 2001 From: Kirill Kubryakov Date: Sat, 18 Mar 2023 16:47:09 +0200 Subject: [PATCH] fix: do not show log message when defaultValue returns undefined because in this case no translation key is added Fixes https://github.com/i18next/i18next-scanner/issues/245 --- src/parser.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/parser.js b/src/parser.js index d706ad8..bc696e0 100644 --- a/src/parser.js +++ b/src/parser.js @@ -1040,7 +1040,9 @@ class Parser { ? defaultValue(lng, ns, key, options) : (options.defaultValue || defaultValue); } - this.log(`Added a new translation key { ${chalk.yellow(JSON.stringify(resKey))}: ${chalk.yellow(JSON.stringify(resLoad[resKey]))} } to ${chalk.yellow(JSON.stringify(this.formatResourceLoadPath(lng, ns)))}`); + if (resLoad[resKey] !== undefined) { + this.log(`Added a new translation key { ${chalk.yellow(JSON.stringify(resKey))}: ${chalk.yellow(JSON.stringify(resLoad[resKey]))} } to ${chalk.yellow(JSON.stringify(this.formatResourceLoadPath(lng, ns)))}`); + } } else if (options.defaultValue && (!options.defaultValue_plural || !resKey.endsWith(`${pluralSeparator}plural`))) { if (!resLoad[resKey]) { // Use `options.defaultValue` if specified