2
// Name: Provide simple translation option for scripts
3
// License: Public Domain
4
// Author: Matthew Gates
5
// Description: Simple translation functions for scripts.
6
// set translations with the setTr function, then use tr(string)
7
// everywhere in your script where you want to get a translated
8
// string. The current application language is taken from the
9
// Application Language setting. See core.setAppLanguage and
10
// core.getAppLanguage for details.
13
// declare a global variable to store saved state
14
var translationStrings = new Array();
16
// call this function with some string ID
19
lang = core.getAppLanguage();
20
// core.debug("tr: getting " + lang + " translation for " + str);
21
if (translationStrings[lang]==undefined)
23
// core.debug("tr: no lang array");
26
else if (translationStrings[lang][str]==undefined)
28
// core.debug("tr: no phrase array");
33
// core.debug("tr: got it");
34
return translationStrings[lang][str];
38
function setTr(lang, original, translation)
40
// core.debug("setTr: " + lang + ", " + original + ", " + translation);
41
if (translationStrings[lang]==undefined)
43
// core.debug("setTr: making new lang array");
44
translationStrings[lang] = new Array();
47
translationStrings[lang][original] = translation;
53
core.debug("We have the following translations:");
54
for (lang in translationStrings)
56
core.debug("Language: " + lang);
57
strings = translationStrings[lang];
58
for (phrase in strings)
60
core.debug(" - " + phrase + " -> " + strings[phrase]);