Banana.Translations
The Banana.Translations class is used to access translators.
Translators let you translate strings to languages other than the application's language.
For a description how to internationalise your extension see the page Extension's Translations
// Exemple for function QT_TRANSLATE_NOOP
var myReportTexts = {};
myReportTexts.account_card = QT_TRANSLATE_NOOP("MyReport", "Account card"); // Mark text for translation
// NB: The variable myReportTexts.account_card contains the source code string "Account card"
// You need a Banana.Translator object to translate it in the desired language
// Get translator for the document's language
var documentLanguage = "en"; //default
if (Banana.document) {
documentLanguage = Banana.document.locale.substring(0,2);
}
var docTranslator = Banana.Translations.getTranslator(documentLanguage, "MyReport");
// Translate to the document's language
var myReportTranslatedText = docTranslator.tr(myReportTexts.account_card);
Methods
getTranslator(locale, context)
Returns a translator for the given local and context.
If no translation for the locale is found, the returned translator is not valid (i.e.: translator.valid returns false). A not valid translator returns the text untranslated as it is in the source code.
var myReportTexts = {};
myReportTexts.account_cards = QT_TRANSLATE_NOOP("MyReport", "Account card");
// Translate to Italian
var trIt = Banana.Translations.getTranslator("it", "MyReport");
var textIt = itTr.tr(myReportTexts.account_cards);
translate(context, text, disambiguation, n)
Translate a string in the language of the application in the specified context.
var myReportTexts = {};
myReportTexts.account_cards = QT_TRANSLATE_NOOP("MyReport", "Account card");
// Translate to the application's language
var text = Banana.Translations.translate("MyReport", myReportTexts.account_cards);
Banana.Translations.Translator
The class Banana.Translations.Translator let you translate strings.
Properties
context
Returns the context of the translator.
language
Returns the language of the translator.
valid
Returns true if the translator is valid.
An invalid translator simply returns the text untranslated as written in the source code.
Methods
tr(text [, disambiguation , n])
Translate a string in the language and context of the translator
// Get translator for the document's language
var documentLanguage = "en"; //default
if (Banana.document) {
documentLanguage = Banana.document.locale.substring(0,2);
}
var docTranslator = Banana.Translations.getTranslator(documentLanguage, "MyReport");
// Translate to the document's language
var myReportTranslatedText = docTranslator.tr(myReportTexts.account_card);
translate(context, text [, disambiguation , n])
Translate a string in the language of the translator in the specified context.
// Get translator for the document's language
var documentLanguage = "en"; //default
if (Banana.document) {
documentLanguage = Banana.document.locale.substring(0,2);
}
var docTranslator = Banana.Translations.getTranslator(documentLanguage, "MyReport");
// Translate to the document's language
var myReportTranslatedText = docTranslator.translate("MyReport", myReportTexts.account_card);