From 2832cb62fcf82f439d1d36f6fa0b6d8d32b8fb9c Mon Sep 17 00:00:00 2001 From: Kirill Kubryakov Date: Sun, 19 Mar 2023 07:31:36 +0200 Subject: [PATCH] fix: do not show log message when defaultValue returns undefined because in this case no translation key is added (#246) 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