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);

请帮助我们完善必备文件

我们非常欢迎您发送宝贵的反馈意见

请告诉我们什么主题需要更好的解释或如何才能更好的对其诠释。

分享这篇文章: Twitter | Facebook | LinkedIn | Email