feat(i18n) Custom i18n strings (#4000)

* Custom i18n strings (and some code formatting)

* Documentation for per-instance l10n overwrites
This commit is contained in:
Daniel Krol 2020-05-19 08:21:31 -04:00 committed by GitHub
parent 170f471299
commit 61c7bb9699
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 54 additions and 6 deletions

View file

@ -29,9 +29,9 @@ exports.socketio = function (hook_name, args, cb) {
return console.log(err);
}
//if showSettingsInAdminPage is set to false, then return NOT_ALLOWED in the result
// if showSettingsInAdminPage is set to false, then return NOT_ALLOWED in the result
if(settings.showSettingsInAdminPage === false) {
socket.emit("settings", {results:'NOT_ALLOWED'});
socket.emit("settings", {results: 'NOT_ALLOWED'});
}
else {
socket.emit("settings", {results: data});

View file

@ -6,6 +6,7 @@ var languages = require('languages4translatewiki')
, plugins = require('ep_etherpad-lite/static/js/pluginfw/plugins.js').plugins
, semver = require('semver')
, existsSync = require('../utils/path_exists')
, settings = require('../utils/Settings');
;
@ -43,7 +44,7 @@ function getAllLocales() {
//add plugins languages (if any)
for(var pluginName in plugins) extractLangs(path.join(npm.root, pluginName, 'locales'));
// Build a locale index (merge all locale data)
// Build a locale index (merge all locale data other than user-supplied overrides)
var locales = {}
_.each (locales2paths, function(files, langcode) {
locales[langcode]={};
@ -54,6 +55,22 @@ function getAllLocales() {
});
});
// Add custom strings from settings.json
// Since this is user-supplied, we'll do some extra sanity checks
const wrongFormatErr = Error(
"customLocaleStrings in wrong format. See documentation " +
"for Customization for Administrators, under Localization.")
if (settings.customLocaleStrings) {
if (typeof settings.customLocaleStrings !== "object") throw wrongFormatErr
_.each(settings.customLocaleStrings, function(overrides, langcode) {
if (typeof overrides !== "object") throw wrongFormatErr
_.each(overrides, function(localeString, key) {
if (typeof localeString !== "string") throw wrongFormatErr
locales[langcode][key] = localeString
})
})
}
return locales;
}