diff --git a/exec/load/gettext.js b/exec/load/gettext.js index dbd7401f80be07eb7c7d5976cf12d223baf033b9..7c7cb3b9cd6e18a4c394332e82408783cbc199b4 100644 --- a/exec/load/gettext.js +++ b/exec/load/gettext.js @@ -1,30 +1,35 @@ // 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;