Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_prodMode = _prodMode || prodMode;
logger = getLogger(_prodMode);
logger.startSpinner(`${messages.checkMissing} ✨`);
const result = {};
/** An array of the existing translation files in the i18n dir */
const currentFiles = translationFiles || verifyTranslationsDir(i18nPath);
if (!currentFiles) return;
for (const fileName of currentFiles) {
/** extract the lang name from the file */
const { scope, fileLang } = regexs.fileLang(i18nPath).exec(fileName).groups;
const extracted = scope ? keys[scope.slice(0, -1)] : keys.__global;
if (!extracted) continue;
/** Read the current file */
const file = readFile(fileName);
const fileObj = JSON.parse(file);
const diffArr = DeepDiff(fileObj, extracted);
if (diffArr) {
const lang = `${scope || ''}${fileLang}`;
result[lang] = {
missing: [],
extra: []
};
for (const diff of diffArr) {
if (diff.kind === 'N') {
result[lang].missing.push(diff);
if (addMissing) {
applyChange(fileObj, extracted, diff);
}
} else if (!_prodMode && diff.kind === 'D') {
result[lang].extra.push(diff);
}
}