当前位置: 首页>>代码示例>>C++>>正文


C++ QTranslator::translate方法代码示例

本文整理汇总了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;
}
开发者ID:nayanapriyankara,项目名称:itest,代码行数:25,代码来源:env_vars.cpp

示例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 );
}
开发者ID:dendy,项目名称:grim,代码行数:59,代码来源:languagemanager.cpp

示例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);
    }
}
开发者ID:alorence,项目名称:tym,代码行数:53,代码来源:langmanager.cpp

示例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);
}
开发者ID:divyang4481,项目名称:photivo,代码行数:15,代码来源:ptChoice.cpp

示例5: languageName

QString LanguageChooser::languageName(const QString &qmFile)
{
    QTranslator translator;
    translator.load(qmFile);

    return translator.translate("MainWindow", "English");
}
开发者ID:SchleunigerAG,项目名称:WinEC7_Qt5.3.1_Fixes,代码行数:7,代码来源:languagechooser.cpp

示例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);
    }
}
开发者ID:BackupTheBerlios,项目名称:qtfin-svn,代码行数:32,代码来源:mainwindow.cpp

示例7: languageName

QString GeneralSettingsPage::languageName(const QString &qmFile)
{
    QTranslator translator;
    translator.load(translationPrefix + "_" + qmFile + ".qm", translationPath);
    
    return translator.translate("GeneralSettingsPage", "English");
}
开发者ID:sugitime,项目名称:Cockatrice,代码行数:7,代码来源:dlg_settings.cpp

示例8: languageName

QString MainWindow::languageName(const QString &qmFile)
{
    QTranslator translator;
    translator.load(qmFile);
    QString lan = translator.translate("MainWindow","English");
    return lan;
}
开发者ID:lzjqsdd,项目名称:WifiAssist,代码行数:7,代码来源:mainwindow.cpp

示例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;
}
开发者ID:ivuk,项目名称:keepassz,代码行数:46,代码来源:tools.cpp

示例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() );
}
开发者ID:CecilHarvey,项目名称:BlueDJGames,代码行数:8,代码来源:main.cpp

示例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;
 }
开发者ID:LastRitter,项目名称:vbox-haiku,代码行数:9,代码来源:UIGlobalSettingsLanguage.cpp

示例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);
}
开发者ID:jimmy-jia,项目名称:Cockatrice,代码行数:10,代码来源:oraclewizard.cpp

示例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() );
}
开发者ID:CecilHarvey,项目名称:BlueDJGames,代码行数:10,代码来源:main.cpp

示例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);
}
开发者ID:KOPOJI,项目名称:codes_new,代码行数:15,代码来源:applicationhelper.cpp

示例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();
} 
开发者ID:develnk,项目名称:qxtweb-qt5,代码行数:19,代码来源:main.cpp


注:本文中的QTranslator::translate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。