mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-23 18:53:36 +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";
|
codeToCountry_["US"] = "US";
|
||||||
|
|
||||||
let supportedLocales_ = null;
|
let supportedLocales_ = null;
|
||||||
|
let localeStats_ = null;
|
||||||
|
|
||||||
let loadedLocales_ = {};
|
let loadedLocales_ = {};
|
||||||
|
|
||||||
@ -190,6 +191,11 @@ function defaultLocale() {
|
|||||||
return defaultLocale_;
|
return defaultLocale_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function localeStats() {
|
||||||
|
if (!localeStats_) localeStats_ = require('../locales/index.js').stats;
|
||||||
|
return localeStats_;
|
||||||
|
}
|
||||||
|
|
||||||
function supportedLocales() {
|
function supportedLocales() {
|
||||||
if (!supportedLocales_) supportedLocales_ = require('../locales/index.js').locales;
|
if (!supportedLocales_) supportedLocales_ = require('../locales/index.js').locales;
|
||||||
|
|
||||||
@ -201,12 +207,19 @@ function supportedLocales() {
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
function supportedLocalesToLanguages() {
|
function supportedLocalesToLanguages(options = null) {
|
||||||
|
if (!options) options = {};
|
||||||
|
const stats = localeStats();
|
||||||
const locales = supportedLocales();
|
const locales = supportedLocales();
|
||||||
let output = {};
|
let output = {};
|
||||||
for (let i = 0; i < locales.length; i++) {
|
for (let i = 0; i < locales.length; i++) {
|
||||||
const locale = locales[i];
|
const locale = locales[i];
|
||||||
output[locale] = countryDisplayName(locale);
|
output[locale] = countryDisplayName(locale);
|
||||||
|
|
||||||
|
const stat = stats[locale];
|
||||||
|
if (options.includeStats && stat) {
|
||||||
|
output[locale] += ' (' + stat.percentDone + '%)';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ class Setting extends BaseModel {
|
|||||||
'activeFolderId': { value: '', type: Setting.TYPE_STRING, public: false },
|
'activeFolderId': { value: '', type: Setting.TYPE_STRING, public: false },
|
||||||
'firstStart': { value: true, type: Setting.TYPE_BOOL, 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: () => {
|
'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: () => {
|
'dateFormat': { value: Setting.DATE_FORMAT_1, type: Setting.TYPE_STRING, isEnum: true, public: true, label: () => _('Date format'), options: () => {
|
||||||
let options = {}
|
let options = {}
|
||||||
|
@ -37,12 +37,16 @@ function serializeTranslation(translation) {
|
|||||||
if (!translations.hasOwnProperty(n)) continue;
|
if (!translations.hasOwnProperty(n)) continue;
|
||||||
if (n == '') continue;
|
if (n == '') continue;
|
||||||
const t = translations[n];
|
const t = translations[n];
|
||||||
|
let translated = '';
|
||||||
if (t.comments && t.comments.flag && t.comments.flag.indexOf('fuzzy') >= 0) {
|
if (t.comments && t.comments.flag && t.comments.flag.indexOf('fuzzy') >= 0) {
|
||||||
output[n] = t['msgid'];
|
// Don't include fuzzy translations
|
||||||
} else {
|
} else {
|
||||||
output[n] = t['msgstr'][0];
|
translated = t['msgstr'][0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (translated) output[n] = translated;
|
||||||
}
|
}
|
||||||
|
|
||||||
return JSON.stringify(output);
|
return JSON.stringify(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,14 +103,26 @@ async function mergePotToPo(potFilePath, poFilePath) {
|
|||||||
await removePoHeaderDate(poFilePath);
|
await removePoHeaderDate(poFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildIndex(locales) {
|
function buildIndex(locales, stats) {
|
||||||
let output = [];
|
let output = [];
|
||||||
output.push('var locales = {};');
|
output.push('var locales = {};');
|
||||||
|
output.push('var stats = {};');
|
||||||
|
|
||||||
for (let i = 0; i < locales.length; i++) {
|
for (let i = 0; i < locales.length; i++) {
|
||||||
const locale = locales[i];
|
const locale = locales[i];
|
||||||
output.push("locales['" + locale + "'] = require('./" + locale + ".json');");
|
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");
|
return output.join("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,7 +272,7 @@ async function main() {
|
|||||||
|
|
||||||
stats.sort((a, b) => a.languageName < b.languageName ? -1 : +1);
|
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';
|
const rnJsonLocaleDir = rnDir + '/locales';
|
||||||
await execCommand('rsync -a "' + jsonLocalesDir + '/" "' + rnJsonLocaleDir + '"');
|
await execCommand('rsync -a "' + jsonLocalesDir + '/" "' + rnJsonLocaleDir + '"');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user