mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-11 18:24:43 +02:00
All: Resolves #1459: Make translation files smaller by not including untranslated strings. Also add percentage translated to config screen.
This commit is contained in:
parent
39ba021a79
commit
200ba2775f
@ -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;
|
||||
}
|
||||
|
@ -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 = {}
|
||||
|
@ -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 + '"');
|
||||
|
Loading…
Reference in New Issue
Block a user