diff --git a/scripts/localize.js b/scripts/localize.js index ffb0544cc..547a00d18 100644 --- a/scripts/localize.js +++ b/scripts/localize.js @@ -26,12 +26,12 @@ locales.forEach(locale => { if (locData.hasOwnProperty(snippetName)) { if (locData[snippetName].hash !== snippetHash) { existingData = - existingData.indexOf(' => ' + snippetHash) !== -1 + existingData.indexOf(` => ${snippetHash}`) !== -1 ? existingData : existingData.replace( - locData[snippetName].hash, - locData[snippetName].hash + ' => ' + snippetHash - ); + locData[snippetName].hash, + `${locData[snippetName].hash} => ${snippetHash}` + ); hashChanges.push({ snippetName, oldHash: locData[snippetName].hash.split(' => ')[0], @@ -44,39 +44,20 @@ locales.forEach(locale => { 'comments': [${(snippets[snippet].match(COMMENT_REGEX) || []).map( v => '`' + v.replace(/`/g, '\\`') + '`' )}], - 'hash': '${snippetHash}' -}`); + 'hash': '${snippetHash}'\n}`); } }); if (!fs.existsSync(path.join(LOCALE_PATH, locale + '.js')) || !existingData.length) existingData = `module.exports = { 'locale': { - 'locale': '${locale}' -}};`; + 'locale': '${locale}'\n}};`; fs.writeFileSync( path.join(LOCALE_PATH, locale + '.js'), newData.length ? `${existingData.trim().slice(0, -2)},${newData.join(',')}};` : existingData ); fs.writeFileSync( path.join(LOCALE_PATH, locale + '_log'), - `${new Date()} -Hash changes: ${hashChanges.length} - -${ - hashChanges.length - ? hashChanges - .map( - v => - 'Snippet name:' + - v.snippetName + - '\n Old hash: ' + - v.oldHash + - '\n New hash: ' + - v.newHash + - '\n' - ) - .join('\n') - : '' - }` + `${new Date()}\nHash changes: ${hashChanges.length}\n${ + hashChanges.length ? hashChanges.map(v => `Snippet name: ${v.snippetName}\n Old hash: ${v.oldHash}\n New hash: ${v.newHash}\n`).join('\n'): ''}` ); });