diff --git a/ReactNativeClient/lib/locale.js b/ReactNativeClient/lib/locale.js index 5f6e5b9cf..475137430 100644 --- a/ReactNativeClient/lib/locale.js +++ b/ReactNativeClient/lib/locale.js @@ -179,6 +179,7 @@ codeToCountry_["GB"] = "UK"; codeToCountry_["US"] = "US"; let supportedLocales_ = null; +let localeStats_ = null; let loadedLocales_ = {}; @@ -190,6 +191,11 @@ function defaultLocale() { return defaultLocale_; } +function localeStats() { + if (!localeStats_) localeStats_ = require('../locales/index.js').stats; + return localeStats_; +} + function supportedLocales() { if (!supportedLocales_) supportedLocales_ = require('../locales/index.js').locales; @@ -201,12 +207,19 @@ function supportedLocales() { return output; } -function supportedLocalesToLanguages() { +function supportedLocalesToLanguages(options = null) { + if (!options) options = {}; + const stats = localeStats(); const locales = supportedLocales(); let output = {}; for (let i = 0; i < locales.length; i++) { const locale = locales[i]; output[locale] = countryDisplayName(locale); + + const stat = stats[locale]; + if (options.includeStats && stat) { + output[locale] += ' (' + stat.percentDone + '%)'; + } } return output; } diff --git a/ReactNativeClient/lib/models/Setting.js b/ReactNativeClient/lib/models/Setting.js index af901797e..7e6bd04ec 100644 --- a/ReactNativeClient/lib/models/Setting.js +++ b/ReactNativeClient/lib/models/Setting.js @@ -79,7 +79,7 @@ class Setting extends BaseModel { 'activeFolderId': { value: '', type: Setting.TYPE_STRING, public: false }, 'firstStart': { value: true, type: Setting.TYPE_BOOL, public: false }, 'locale': { value: defaultLocale(), type: Setting.TYPE_STRING, isEnum: true, public: true, label: () => _('Language'), options: () => { - return ObjectUtils.sortByValue(supportedLocalesToLanguages()); + return ObjectUtils.sortByValue(supportedLocalesToLanguages({ includeStats: true })); }}, 'dateFormat': { value: Setting.DATE_FORMAT_1, type: Setting.TYPE_STRING, isEnum: true, public: true, label: () => _('Date format'), options: () => { let options = {} diff --git a/Tools/build-translation.js b/Tools/build-translation.js index 5fc66f271..e02fc7b35 100644 --- a/Tools/build-translation.js +++ b/Tools/build-translation.js @@ -37,12 +37,16 @@ function serializeTranslation(translation) { if (!translations.hasOwnProperty(n)) continue; if (n == '') continue; const t = translations[n]; + let translated = ''; if (t.comments && t.comments.flag && t.comments.flag.indexOf('fuzzy') >= 0) { - output[n] = t['msgid']; - } else { - output[n] = t['msgstr'][0]; + // Don't include fuzzy translations + } else { + translated = t['msgstr'][0]; } + + if (translated) output[n] = translated; } + return JSON.stringify(output); } @@ -99,14 +103,26 @@ async function mergePotToPo(potFilePath, poFilePath) { await removePoHeaderDate(poFilePath); } -function buildIndex(locales) { +function buildIndex(locales, stats) { let output = []; output.push('var locales = {};'); + output.push('var stats = {};'); + for (let i = 0; i < locales.length; i++) { const locale = locales[i]; output.push("locales['" + locale + "'] = require('./" + locale + ".json');"); } - output.push('module.exports = { locales: locales };'); + + for (let i = 0; i < stats.length; i++) { + const stat = Object.assign({}, stats[i]); + const locale = stat.locale; + delete stat.locale; + delete stat.translatorName; + delete stat.languageName; + output.push("stats['" + locale + "'] = " + JSON.stringify(stat) + ";"); + } + + output.push('module.exports = { locales: locales, stats: stats };'); return output.join("\n"); } @@ -256,7 +272,7 @@ async function main() { stats.sort((a, b) => a.languageName < b.languageName ? -1 : +1); - saveToFile(jsonLocalesDir + '/index.js', buildIndex(locales)); + saveToFile(jsonLocalesDir + '/index.js', buildIndex(locales, stats)); const rnJsonLocaleDir = rnDir + '/locales'; await execCommand('rsync -a "' + jsonLocalesDir + '/" "' + rnJsonLocaleDir + '"');