本文整理汇总了C++中QTranslator::translate方法的典型用法代码示例。如果您正苦于以下问题:C++ QTranslator::translate方法的具体用法?C++ QTranslator::translate怎么用?C++ QTranslator::translate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTranslator
的用法示例。
在下文中一共展示了QTranslator::translate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: varinit
void MainWindow::varinit()
{
// GLOBAL
// iTestServer version
ver = "1.4.2"; f_ver = 1.42;
// iTest ITDB file version
itdb_ver = "1.4"; f_itdb_ver = 1.4;
// iTest ITOS file version
itos_ver = "1.4.2"; f_itos_ver = 1.42;
// URLs
itest_url = "itest.sourceforge.net";
docs_url = tr("http://itest.sourceforge.net/documentation/%1/en/").arg("1.4");
// i18n
QTranslator translator; translator.load(":/i18n/iTest-i18n.qm");
itest_i18n.insert("English", "English");
itest_i18n.insert(translator.translate("LanguageNames", "Slovak"), "Slovak");
itest_i18n.insert(translator.translate("LanguageNames", "Russian"), "Russian");
itest_i18n.insert(translator.translate("LanguageNames", "Turkish"), "Turkish");
itest_i18n.insert(translator.translate("LanguageNames", "Portuguese"), "Portuguese");
itest_i18n.insert(translator.translate("LanguageNames", "Spanish"), "Spanish");
itest_i18n.insert(translator.translate("LanguageNames", "Italian"), "Italian");
itest_i18n.insert(translator.translate("LanguageNames", "Latvian"), "Latvian");
// CURRENT_DB
current_db_open = false;
}
示例2: langDir
LanguageManager::LanguageManager()
{
// lookup qm files under the :/lang dir
QDir langDir( QmDirPath );
for ( QListIterator<QFileInfo> it( langDir.entryInfoList(
QStringList() << QmTemplate.arg( QmInfoPrefix ), QDir::Files | QDir::CaseSensitive ) ); it.hasNext(); )
{
const QFileInfo qmFileInfo = it.next();
QString moduleName;
QString suffix;
if ( !_splitFileName( qmFileInfo.completeBaseName(), &moduleName, &suffix ) )
continue;
Q_ASSERT( moduleName == QmInfoPrefix );
Q_ASSERT( !languageInfoForName_.contains( suffix ) );
QTranslator * infoTranslator = new QTranslator( this );
if ( !infoTranslator->load( qmFileInfo.filePath() ) )
{
delete infoTranslator;
continue;
}
LanguageInfo languageInfo;
languageInfo.isNull = false;
languageInfo.name = suffix;
languageInfo.englishName = infoTranslator->translate( "LanguageManager", LanguageNameInEnglish );
languageInfo.nativeName = infoTranslator->translate( "LanguageManager", LanguageNameInNative );
languageInfoForName_[ languageInfo.name ] = languageInfo;
names_ << languageInfo.name;
}
QString defaultName;
const QLocale currentLocale;
if ( languageInfoForName_.contains( currentLocale.name() ) )
{
defaultName = currentLocale.name();
}
else
{
const QString localeLangName = currentLocale.name().left( currentLocale.name().indexOf( QLatin1Char( '_' ) ) );
if ( languageInfoForName_.contains( localeLangName ) )
{
defaultName = localeLangName;
}
else
{
if ( languageInfoForName_.contains( DefaultLanguageName ) )
defaultName = DefaultLanguageName;
}
}
if ( !defaultName.isNull() )
setCurrentName( defaultName );
}
示例3: QObject
LangManager::LangManager(QObject *parent) :
QObject(parent)
{
//: Fill this with your language (ex: English, Deutch, Français, etc)
tr("__LANG__");
//: Fill this with the country your language is for (United-States, France, etc.)
tr("__COUNTRY__");
QStringList searchDirs;
#ifdef Q_OS_MAC
searchDirs << qApp->applicationDirPath() + "/../Resources/lang"
<< qApp->applicationDirPath() + "/../../../../resources";
#else
searchDirs << qApp->applicationDirPath() + "/lang"
<< qApp->applicationDirPath() + "/../resources";
#endif
QDir searchDir;
searchDir.setFilter(QDir::Files);
searchDir.setNameFilters(QStringList() << "*.qm");
QFileInfoList files;
for(QString dir : searchDirs) {
searchDir.setPath(dir);
files = searchDir.entryInfoList();
if(files.count()) {
LOG_INFO(QString("%1 translations found in the directory %2")
.arg(files.count())
.arg(searchDir.absolutePath()));
break;
}
}
// Insert default translation. By doing this here, we ensure the LanguageEvent will
// correctly be posted when switching from any language to default.
_langMap.insert(TYM_DEFAULT_LANGUAGE, "English (United States)");
_translatorMap.insert(TYM_DEFAULT_LANGUAGE, new QTranslator(this));
for(QFileInfo f : files) {
QString key = f.baseName();
QTranslator* transl = new QTranslator(this);
transl->load(f.fileName(), f.absolutePath());
_translatorMap.insert(key, transl);
QString langName = transl->translate("LangManager", "__LANG__")
+ " (" + transl->translate("LangManager", "__COUNTRY__") + ")";
if(langName == " ()") {
langName = key;
}
_langMap.insert(key, langName);
}
}
示例4: AddOrReplaceItem
// Keeps Data unique, i.e. replace if exist.
// NOTE: This function is only used by ptSettings, i.e. oldschool
void ptChoice::AddOrReplaceItem(const QString Text,const QVariant Data) {
for (int i=0; i<m_ComboBox->count(); i++) {
if (Data == m_ComboBox->itemData(i)) {
QString Temp = appTranslator.translate("QObject",Text.toLocal8Bit().data());
if (Temp == "") Temp = Text;
m_ComboBox->setItemText(i,Temp);
return;
}
}
QString Temp = appTranslator.translate("QObject",Text.toLocal8Bit().data());
if (Temp == "") Temp = Text;
m_ComboBox->addItem(Temp,Data);
}
示例5: languageName
QString LanguageChooser::languageName(const QString &qmFile)
{
QTranslator translator;
translator.load(qmFile);
return translator.translate("MainWindow", "English");
}
示例6: createLanguageMenu
void MainWindow::createLanguageMenu()
{
_menuLanguage = new QMenu(_menuBar);
_actionGroupLanguage = new QActionGroup(this);
connect(_actionGroupLanguage, SIGNAL(triggered(QAction*)),
this, SLOT(switchLanguage(QAction*)));
QDir dir(_qmPath);
QStringList fileNames =
dir.entryList(QStringList("monofin_*.qm"));
for (int i=0; i<fileNames.size(); ++i) {
QString locale = fileNames[i];
locale.remove(0, locale.indexOf('_')+1);
locale.truncate(locale.indexOf('.'));
QTranslator translator;
translator.load(fileNames[i], _qmPath);
QString language = translator.translate("MainWindow", "English");
QAction *action = new QAction(tr("&%1 %2")
.arg(i+1).arg(language), this);
action->setCheckable(true);
action->setData(locale);
_menuLanguage->addAction(action);
_actionGroupLanguage->addAction(action);
if (language == _currentLanguage)
action->setChecked(true);
}
}
示例7: languageName
QString GeneralSettingsPage::languageName(const QString &qmFile)
{
QTranslator translator;
translator.load(translationPrefix + "_" + qmFile + ".qm", translationPath);
return translator.translate("GeneralSettingsPage", "English");
}
示例8: languageName
QString MainWindow::languageName(const QString &qmFile)
{
QTranslator translator;
translator.load(qmFile);
QString lan = translator.translate("MainWindow","English");
return lan;
}
示例9: filename
QList<Translation> getAllTranslations(){
QTranslator tmpTranslator;
QList<Translation> translations;
QSet<QString> names;
QStringList paths = QStringList() << DataDir+"/i18n/" << HomeDir;
QRegExp filename("keepassx-([^_]{2}_[^\\.]{2}|[^\\.]{2})\\.qm");
for (int i=0;i<paths.size();i++){
QDir dir(paths[i]);
QStringList TrFiles=dir.entryList(QStringList()<<"*.qm",QDir::Files);
for (int j=0;j<TrFiles.size();j++){
if (filename.exactMatch(TrFiles[j]) && TrFiles[j]!="keepassx-xx_XX.qm" &&
tmpTranslator.load(TrFiles[j],paths[i]) && !names.contains(filename.cap(1)))
{
Translation t;
t.nameCode = filename.cap(1);
t.nameLong = tmpTranslator.translate("Translation", "$LANGUAGE_NAME", "Insert your language name in the format: English (United States)");
t.author = tmpTranslator.translate("Translation", "$TRANSLATION_AUTHOR");
QLocale l(t.nameCode);
t.nameEnglish = QLocale::languageToString(l.language());
if (t.nameCode.size()==5){
QString country = QLocale::countryToString(l.country());
int size = country.size();
for (int k=1; k<size; k++){
if (country[k].isUpper()){
country.insert(k, " ");
k += 2;
size++;
}
}
t.nameEnglish.append(" (").append(country).append(")");
}
if (t.nameLong.isEmpty())
t.nameLong = t.nameEnglish;
translations << t;
names << t.nameCode;
}
}
}
qSort(translations.begin(), translations.end());
return translations;
}
示例10: GetTranslatedGameName
extern "C" MY_EXPORT QString GetTranslatedGameName()
{
QString locale = FindSupportedLocaleName();
QTranslator translator;
translator.load( QString(":/%1Res").arg(gameName) + "/lang/" + gameName + "_" + locale );
return translator.translate( "NiuNiuController", gameName.toAscii() );
}
示例11: tratra
QString tratra(const QTranslator &translator, const char *pCtxt,
const char *pSrc, const char *pCmnt)
{
QString strMsg = translator.translate(pCtxt, pSrc, pCmnt);
/* Return the source text if no translation is found: */
if (strMsg.isEmpty())
strMsg = QString(pSrc);
return strMsg;
}
示例12: languageName
QString IntroPage::languageName(const QString &qmFile)
{
if(qmFile == DEFAULT_LANG_CODE)
return DEFAULT_LANG_NAME;
QTranslator translator;
translator.load(translationPrefix + "_" + qmFile + ".qm", translationPath);
return translator.translate("IntroPage", DEFAULT_LANG_NAME);
}
示例13: GetTranslatedGameName
extern "C" MY_EXPORT QString GetTranslatedGameName()
{
QString locale = GetSettingLocaleName();
if ( locale == "auto" )
locale = QLocale::system().name();
QTranslator translator;
translator.load( QString(":/%1Res").arg(gameName) + "/lang/" + gameName + "_" + locale );
return translator.translate( "GBMJController", gameName.toAscii() );
}
示例14: tr
QString ApplicationHelper::tr(const char *sourceText, const char *disambiguation, int n)
{
static IncludeController ic;
static QTranslator translator;
const QString path = ic.getRequest().header().path();
int pos = path.indexOf('/') + 1;
QString language = path.mid(pos, path.indexOf('/', pos) - 1);
if(!translator.load(language, "./translations/"))
return sourceText;
return translator.translate("H", sourceText, disambiguation, n);
}
示例15: main
int main(int argc, char* argv[])
{
// Q_INIT_RESOURCE(flags);
QApplication app(argc, argv);
QTranslator trans;
bool ok = trans.load(":/qxt_"+QLocale::system().name());
if (!ok)
qDebug() << "Loading translation failed.";
qDebug() << trans.translate("Country", "Germany");
app.installTranslator(&trans);
TestDialog* w = new TestDialog();
w->show();
app.exec();
}