Skip to content
Snippets Groups Projects
Commit ef71a44d authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Add optional friendly-key name argument, pull text from [scriptname.js]

Not all strings make good key names (e.g. those with control characters),
so allow an additional, optional argument to gettext() that allows for
more friendly key names to be used to specify/look-up (some) text strings.

Also, in addition to the global [js] section for these text values, look
(first) in [scriptfilename.js] - this allows more customization on a
per-script basis (e.g. [default.js] can be used to override strings used
in the Synchronet Classic command shell (default.js) but would not effect
if/when those same strings are used in other scripts/shells.
parent 09daa29e
No related branches found
No related tags found
No related merge requests found
// Localized/customized support for JavaScript user-visible text (i.e. strings not contained in text.dat)
// Customized text strings go in the [JS] section of ctrl/text.ini
// Localized (translated to non-default locale) text strings go in the [JS] section of ctrl/text.<lang>.ini
// Customized text strings go in the [scriptfilename.js] or [JS] sections of ctrl/text.ini
// Localized (translated to non-default locale) text strings go in the equivalent sections of ctrl/text.<lang>.ini
// For strings that contain control characters,
// an optional 'key' is typically used/specified to look-up those text strings.
"use strict";
var gettext_cache = {};
function gettext(orig) {
function get_text_from_ini(ini_fname, orig) {
function gettext(orig, key) {
function get_text_from_ini(ini_fname, orig, key){
var f = new File(ini_fname);
if(!f.open("r"))
return undefined;
var text = f.iniGetValue("js", orig);
var text = f.iniGetValue(js.exec_file, key || orig);
if (text === undefined)
text = f.iniGetValue("js", key || orig);
f.close();
return text;
}
if (gettext_cache[orig] !== undefined)
return gettext_cache[orig];
if (gettext_cache[key || orig] !== undefined)
return gettext_cache[key || orig];
var text;
if (user.lang)
text = get_text_from_ini("text." + user.lang + ".ini", orig);
text = get_text_from_ini("text." + user.lang + ".ini", orig, key);
if (text === undefined)
text = get_text_from_ini("text.ini", orig);
text = get_text_from_ini("text.ini", orig, key);
if (text === undefined)
text = orig;
return gettext_cache[orig] = text;
return gettext_cache[key || orig] = text;
}
this;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment