Skip to content

Commit

Permalink
Skip empty and non-existent translations
Browse files Browse the repository at this point in the history
  • Loading branch information
Gideon Thomas committed Mar 3, 2016
1 parent 9310c2e commit b9008ca
Showing 1 changed file with 41 additions and 14 deletions.
55 changes: 41 additions & 14 deletions scripts/properties2js.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,27 +83,54 @@ function localizeBrackets(locale) {
var strings = destLocalizedStrings[locale];
var isNewLocale = !(Object.keys(strings).length);

return mkdirp(path.join(dest, localeDir))
.then(function() {
return properties.readAsync(path.join(src, locale, L10N_PROP_FILE));
})
.then(function(newStrings) {
function combineAndWriteStrings(newStrings) {
if(newStrings) {
Object.assign(strings, newStrings);
}

if(!(Object.keys(strings).length)) {
// Our string file is empty and Brackets does not have any strings
console.log("No strings to write for `", localeDir, "`");
return Promise.resolve();
}

if(isNewLocale) {
destLocales.push(localeDir);
}

Object.assign(strings, newStrings);
var localizedFileContents = templates.render(L10N_TEMPLATE_FILE, { localizedStrings: strings });
var destLocaleDir = path.join(dest, localeDir);

return mkdirp(destLocaleDir)
.then(function() {
return fs.writeFileAsync(path.join(destLocaleDir, L10N_STR_FILE), localizedFileContents);
})
.then(function() {
console.log("Updated l10n file for `", localeDir, "`");
return Promise.resolve();
})
.catch(function(err) {
console.error("Failed to update l10n file for `", localeDir, "`");
return Promise.reject(err);
});
}

return fs.writeFileAsync(path.join(dest, localeDir, L10N_STR_FILE), localizedFileContents);
})
.then(function() {
console.log("Updated l10n file for `", localeDir, "`");
return Promise.resolve();
})
return properties.readAsync(path.join(src, locale, L10N_PROP_FILE))
.then(combineAndWriteStrings)
.catch(function(err) {
console.error("Failed to update l10n file for `", localeDir, "`");
return Promise.reject(err);
if(err.code !== "ENOENT") {
console.error("Failed to update l10n file for `", localeDir, "`");
return Promise.reject(err);
}

if(!isNewLocale) {
// We need to write the strings that brackets provides
return combineAndWriteStrings();
}

// Our string file nor their's have any strings
console.log("No strings to write for `", localeDir, "`");
return Promise.resolve();
});
}

Expand Down

0 comments on commit b9008ca

Please sign in to comment.