~xalioth/stellarium/fix-fonts-gltex-fab

« back to all changes in this revision

Viewing changes to scripts/translation.inc

  • Committer: matthewg42
  • Date: 2010-04-14 18:34:13 UTC
  • Revision ID: vcs-imports@canonical.com-20100414183413-p2vkiyhdkbvvp3ml
translation example script

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
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.
 
11
//
 
12
 
 
13
// declare a global variable to store saved state
 
14
var translationStrings = new Array();
 
15
 
 
16
// call this function with some string ID
 
17
function tr(str)
 
18
{
 
19
        lang = core.getAppLanguage();
 
20
        // core.debug("tr: getting " + lang + " translation for " + str);
 
21
        if (translationStrings[lang]==undefined) 
 
22
        {       
 
23
                // core.debug("tr: no lang array");
 
24
                return str; 
 
25
        }
 
26
        else if (translationStrings[lang][str]==undefined) 
 
27
        { 
 
28
                // core.debug("tr: no phrase array");
 
29
                return str; 
 
30
        }
 
31
        else 
 
32
        { 
 
33
                // core.debug("tr: got it");
 
34
                return translationStrings[lang][str]; 
 
35
        }
 
36
}
 
37
 
 
38
function setTr(lang, original, translation)
 
39
{
 
40
        // core.debug("setTr: " + lang + ", " + original + ", " + translation);
 
41
        if (translationStrings[lang]==undefined)
 
42
        {
 
43
                // core.debug("setTr: making new lang array");
 
44
                translationStrings[lang] = new Array();
 
45
        }
 
46
 
 
47
        translationStrings[lang][original] = translation;
 
48
 
 
49
}
 
50
 
 
51
function dumpTr() 
 
52
{
 
53
        core.debug("We have the following translations:");
 
54
        for (lang in translationStrings)
 
55
        {
 
56
                core.debug("Language: " + lang);
 
57
                strings = translationStrings[lang];
 
58
                for (phrase in strings)
 
59
                {
 
60
                        core.debug(" - " + phrase + " -> " + strings[phrase]);
 
61
                }
 
62
        }
 
63
 
 
64
}
 
65