Skip to content

Commit

Permalink
Only include translated items if they exist in the en destination file
Browse files Browse the repository at this point in the history
  • Loading branch information
bbondy committed Sep 4, 2019
1 parent 4dfc702 commit 2baf61d
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions sync-strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const getLangStringsMap = (dir) => {
const filterLangs = (lang) =>
!['index.json', 'en'].includes(lang)

const syncLangStrings = (destDir, sourceLangStringsMap) => {
const syncLangStrings = (destDir, sourceLangStringsMap, destLangStringsMap) => {
fs.readdirSync(destDir)
.filter(filterLangs)
.forEach((lang) => {
Expand All @@ -46,8 +46,12 @@ const syncLangStrings = (destDir, sourceLangStringsMap) => {
}
Object.keys(langMap).forEach((key) => {
if (sourceLangStringsMap[lang][key] || newFile) {
langMap[key].message =
formattingFixer(brandingFixer(sourceLangStringsMap[lang][key]))
// Make sure that the source language contains the string to be translated
// This avoids keeping translations for removed strings
if (destLangStringsMap.en[key]) {
langMap[key].message =
formattingFixer(brandingFixer(sourceLangStringsMap[lang][key]))
}
}
})
const data = JSON.stringify(langMap, null, 2)
Expand Down Expand Up @@ -83,10 +87,11 @@ const syncStrings = (sourceDir, destDir) => {
assertDirExists(destDir)

const sourceLangStringsMap = getLangStringsMap(sourceDir)
const destLangStringsMap = getLangStringsMap(destDir)
const sourceLangs = Object.keys(sourceLangStringsMap)

syncDirs(destDir, sourceLangs)
syncLangStrings(destDir, sourceLangStringsMap)
syncLangStrings(destDir, sourceLangStringsMap, destLangStringsMap)

console.log(`Syncing from sourceDir: ${sourceDir} to destDir: ${destDir}`)

Expand Down

0 comments on commit 2baf61d

Please sign in to comment.