forked from Stellarium/stellarium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5df90f
commit 9db1df8
Showing
3 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// Name: Example of translations | ||
// License: Public Domain | ||
// Author: Matthew Gates | ||
// Description: Illustration of using translation.inc | ||
// | ||
|
||
include ("../translation.inc"); | ||
|
||
setTr("de", "Hello world", "Hallo Welt"); | ||
setTr("de", "Knife", "das Messer"); | ||
|
||
dumpTr(); | ||
|
||
messages = new Array("Hello world", "Bananas are marsupials", "Knife", "Pra-Bob"); | ||
|
||
originalLanguage = core.getAppLanguage(); | ||
|
||
core.setAppLanguage("de"); | ||
for(i=0; i<messages.length; i++) | ||
{ | ||
core.debug("\"" + messages[i] + "\" in " + core.getAppLanguage() + " is \"" + tr(messages[i]) + "\""); | ||
} | ||
|
||
core.setAppLanguage(originalLanguage); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// | ||
// Name: Provide simple translation option for scripts | ||
// License: Public Domain | ||
// Author: Matthew Gates | ||
// Description: Simple translation functions for scripts. | ||
// set translations with the setTr function, then use tr(string) | ||
// everywhere in your script where you want to get a translated | ||
// string. The current application language is taken from the | ||
// Application Language setting. See core.setAppLanguage and | ||
// core.getAppLanguage for details. | ||
// | ||
|
||
// declare a global variable to store saved state | ||
var translationStrings = new Array(); | ||
|
||
// call this function with some string ID | ||
function tr(str) | ||
{ | ||
lang = core.getAppLanguage(); | ||
// core.debug("tr: getting " + lang + " translation for " + str); | ||
if (translationStrings[lang]==undefined) | ||
{ | ||
// core.debug("tr: no lang array"); | ||
return str; | ||
} | ||
else if (translationStrings[lang][str]==undefined) | ||
{ | ||
// core.debug("tr: no phrase array"); | ||
return str; | ||
} | ||
else | ||
{ | ||
// core.debug("tr: got it"); | ||
return translationStrings[lang][str]; | ||
} | ||
} | ||
|
||
function setTr(lang, original, translation) | ||
{ | ||
// core.debug("setTr: " + lang + ", " + original + ", " + translation); | ||
if (translationStrings[lang]==undefined) | ||
{ | ||
// core.debug("setTr: making new lang array"); | ||
translationStrings[lang] = new Array(); | ||
} | ||
|
||
translationStrings[lang][original] = translation; | ||
|
||
} | ||
|
||
function dumpTr() | ||
{ | ||
core.debug("We have the following translations:"); | ||
for (lang in translationStrings) | ||
{ | ||
core.debug("Language: " + lang); | ||
strings = translationStrings[lang]; | ||
for (phrase in strings) | ||
{ | ||
core.debug(" - " + phrase + " -> " + strings[phrase]); | ||
} | ||
} | ||
|
||
} | ||
|