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


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

本文整理汇总了C++中QTranslator::isEmpty方法的典型用法代码示例。如果您正苦于以下问题:C++ QTranslator::isEmpty方法的具体用法?C++ QTranslator::isEmpty怎么用?C++ QTranslator::isEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QTranslator的用法示例。


在下文中一共展示了QTranslator::isEmpty方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: setupTranslations

void Application::setupTranslations()
{
    QStringList uiLanguages;
    // uiLanguages crashes on Windows with 4.8.0 release builds
    #if (QT_VERSION >= 0x040801) || (QT_VERSION >= 0x040800 && !defined(Q_OS_WIN))
        uiLanguages = QLocale::system().uiLanguages();
    #else
        // older versions need to fall back to the systems locale
        uiLanguages << QLocale::system().name();
    #endif

    QString enforcedLocale = Theme::instance()->enforcedLocale();
    if (!enforcedLocale.isEmpty())
        uiLanguages.prepend(enforcedLocale);

    QTranslator *translator = new QTranslator(this);
    QTranslator *qtTranslator = new QTranslator(this);
    QTranslator *qtkeychainTranslator = new QTranslator(this);

    foreach(QString lang, uiLanguages) {
        lang.replace(QLatin1Char('-'), QLatin1Char('_')); // work around QTBUG-25973
        lang = substLang(lang);
        const QString trPath = applicationTrPath();
        const QString trFile = QLatin1String("client_") + lang;
        if (translator->load(trFile, trPath) ||
            lang.startsWith(QLatin1String("en"))) {
            // Permissive approach: Qt and keychain translations
            // may be missing, but Qt translations must be there in order
            // for us to accept the language. Otherwise, we try with the next.
            // "en" is an exeption as it is the default language and may not
            // have a translation file provided.
            qDebug() << Q_FUNC_INFO << "Using" << lang << "translation";
            setProperty("ui_lang", lang);
            const QString qtTrPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
            const QString qtTrFile = QLatin1String("qt_") + lang;
            const QString qtBaseTrFile = QLatin1String("qtbase_") + lang;
            if (!qtTranslator->load(qtTrFile, qtTrPath)) {
                if (!qtTranslator->load(qtTrFile, trPath)) {
                    qtTranslator->load(qtBaseTrFile, trPath);
                }
            }
            const QString qtkeychainTrFile = QLatin1String("qtkeychain_") + lang;
            if (!qtkeychainTranslator->load(qtkeychainTrFile, qtTrPath)) {
                qtkeychainTranslator->load(qtkeychainTrFile, trPath);
            }
            if (!translator->isEmpty())
                installTranslator(translator);
            if (!qtTranslator->isEmpty())
                installTranslator(qtTranslator);
            if (!qtkeychainTranslator->isEmpty())
                installTranslator(qtkeychainTranslator);
            break;
        }
        if (property("ui_lang").isNull())
            setProperty("ui_lang", "C");
    }
开发者ID:Buckeye,项目名称:client,代码行数:56,代码来源:application.cpp

示例2: main

int main( int argc, char **argv )
{
	QApplication app( argc, argv );

	QTranslator QtTranslation;
	QTranslator AppTranslation;

	QString QtTranslationPath=QLibraryInfo::location(QLibraryInfo::TranslationsPath);
	QString AppTranslationPath=QtTranslationPath;

	QtTranslation.load(QString("qt_%1").arg(QLocale::system().name()),QtTranslationPath);
	AppTranslation.load(QString("%1_%2").arg(app.applicationName()).arg(QLocale::system().name()),AppTranslationPath);

	if((!AppTranslation.isEmpty()) && (!QtTranslation.isEmpty()))
	{
		app.installTranslator(&QtTranslation);
		app.installTranslator(&AppTranslation);
	}

	FrmMainWindow MainWindow;
	MainWindow.show();
	return app.exec();
}
开发者ID:QGeocache,项目名称:QGeocache,代码行数:23,代码来源:Main.cpp

示例3: installQtTranslator

    void installQtTranslator(const QString &locale)
    {
        QTranslator *translator = new QTranslator(QCoreApplication::instance());

    #ifdef Q_OS_WIN
        translator->load(QString("%1/locale/qt_%2").arg(QCoreApplication::applicationDirPath()).arg(locale));
    #else
        translator->load("qt_" + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
    #endif

        if(!translator->isEmpty())
            QCoreApplication::installTranslator(translator);
        else
            delete translator;
    }
开发者ID:sakazuki,项目名称:actiona,代码行数:15,代码来源:languages.cpp

示例4: installTranslator

    void installTranslator(const QString &componentName, const QString &locale)
    {
        QTranslator *translator = new QTranslator(QCoreApplication::instance());
        if(!translator->load(QString("%1/locale/%2_%3").arg(QCoreApplication::applicationDirPath()).arg(componentName).arg(locale)))
        {
            if(!translator->load(QString("%1/locale/%2_%3").arg(QDir::currentPath()).arg(componentName).arg(locale)))
            {
    #ifndef Q_OS_WIN
                translator->load(QString("%1/share/actiona/locale/%2_%3").arg(ACT_PREFIX).arg(componentName).arg(locale));
    #endif
            }
        }

        if(!translator->isEmpty())
            QCoreApplication::installTranslator(translator);
        else
            delete translator;
    }
开发者ID:sakazuki,项目名称:actiona,代码行数:18,代码来源:languages.cpp

示例5: initTranslations

void initTranslations(const QLocale &locale)
{
	QStringList preferredLangs = locale.uiLanguages();
	if(preferredLangs.size()==0)
		return;

	// uiLanguages sometimes returns more languages than
	// than the user has actually selected, so we just pick
	// the first one.
	QString preferredLang = preferredLangs.at(0);

	// On Windows, the locale name is sometimes in the form "fi-FI"
	// rather than "fi_FI" that Qt expects.
	preferredLang.replace('-', '_');

	// Special case: if english is preferred language, no translations are needed.
	if(preferredLang == "en")
		return;

	// Qt's own translations
	QTranslator *qtTranslator = new QTranslator;
	qtTranslator->load("qt_" + preferredLang, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
	qApp->installTranslator(qtTranslator);

	// Our translations
	QTranslator *myTranslator = new QTranslator;

	for(const QString &datapath : DrawpileApp::dataPaths()) {
		if(myTranslator->load("drawpile_" + preferredLang,  datapath + "/i18n"))
			break;
	}

	if(myTranslator->isEmpty())
		delete myTranslator;
	else
		qApp->installTranslator(myTranslator);
}
开发者ID:ahb0327,项目名称:Drawpile,代码行数:37,代码来源:main.cpp

示例6: main

int main( int argc, char *argv[] )
{
  QLocale::setDefault( QLocale( "C" ) );
  std::locale::global( std::locale( "C" ) );
  setlocale( LC_ALL, "C" );

  dbc::init();
  module_t::init();
  unique_gear::register_hotfixes();
  unique_gear::register_special_effects();

  hotfix::apply();

  QApplication a( argc, argv );

  QCoreApplication::setApplicationName( "SimulationCraft" );
  QCoreApplication::setApplicationVersion( SC_VERSION );
  QCoreApplication::setOrganizationDomain( "http://www.simulationcraft.org/" );
  QCoreApplication::setOrganizationName( "SimulationCraft" );
  QSettings::setDefaultFormat( QSettings::IniFormat ); // Avoid Registry entries on Windows

  QNetworkProxyFactory::setUseSystemConfiguration( true );

  // Localization
  QTranslator qtTranslator;
  qtTranslator.load( "qt_" + QLocale::system().name(),
    QLibraryInfo::location( QLibraryInfo::TranslationsPath ) );
  a.installTranslator( &qtTranslator );

  QString lang;
  QSettings settings;
  lang = settings.value( "options/gui_localization", "auto" ).toString();
  qDebug() << "[Localization]: Seleced gui language: " << lang;
  if ( lang == "auto" )
  {
    lang = QLocale::system().name().split('_').at(1).toLower();
    qDebug() << "[Localization]: QLocale system language: " << lang;
  }
  QTranslator myappTranslator;
  if ( !lang.isEmpty() && !lang.startsWith( "en" ) )
  {
    QString path_to_locale = SC_PATHS::getDataPath() + "/locale";

    QString qm_file = QString( "sc_" ) + lang;
    qDebug() << "[Localization]: Trying to load local file from: " << path_to_locale << "/" << qm_file << ".qm";
    myappTranslator.load( qm_file, path_to_locale );
    qDebug() << "[Localization]: Loaded translator isEmpty(): " << myappTranslator.isEmpty();
  }
  else
  {
    qDebug() << "[Localization]: No specific translator chosen, using English.";
  }
  a.installTranslator( &myappTranslator );

  QString iconlocation = QStandardPaths::locate( QStandardPaths::DataLocation,
                                                 QString( "icon" ),
                                                 QStandardPaths::LocateDirectory );
  QDir::addSearchPath( "icon", iconlocation );

  SC_MainWindow w;

  parse_additional_args( w, a.arguments() );

  return a.exec();
}
开发者ID:JamesWR,项目名称:simc,代码行数:65,代码来源:main.cpp

示例7: setCurrentLanguage

/* \brief To set the current language
\param newLanguage Should be short name code found into informations.xml of language file */
void LanguagesManager::setCurrentLanguage(const QString &newLanguage)
{
	ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start: "+newLanguage);
	//protection for re-set the same language
	if(currentLanguage==newLanguage)
		return;
	//store the language
	plugins->setLanguage(newLanguage);
	//unload the old language
	if(currentLanguage!="en")
	{
		int indexTranslator=0;
		while(indexTranslator<installedTranslator.size())
		{
			QCoreApplication::removeTranslator(installedTranslator[indexTranslator]);
			delete installedTranslator[indexTranslator];
			indexTranslator++;
		}
		installedTranslator.clear();
	}
	if(newLanguage=="en")
	{
		currentLanguage="en";
		emit newLanguageLoaded(currentLanguage);
	}
	else
	{
		int index=0;
		while(index<LanguagesAvailableList.size())
		{
			if(LanguagesAvailableList.at(index).mainShortName==newLanguage)
			{
				//load the new language
				if(newLanguage!="en")
				{
					QTranslator *temp;
					QStringList fileToLoad;
					//load the language main
					fileToLoad<<LanguagesAvailableList.at(index).path+"translation.qm";
					//load the language plugin
					QList<PluginsAvailable> listLoadedPlugins=plugins->getPlugins();
					int indexPluginIndex=0;
					while(indexPluginIndex<listLoadedPlugins.size())
					{
						if(listLoadedPlugins.at(indexPluginIndex).category!=PluginType_Languages)
						{
							QString tempPath=listLoadedPlugins.at(indexPluginIndex).path+"Languages"+QDir::separator()+LanguagesAvailableList.at(index).mainShortName+QDir::separator()+"translation.qm";
							if(QFile::exists(tempPath))
								fileToLoad<<tempPath;
						}
						indexPluginIndex++;
					}
					int indexTranslationFile=0;
					while(indexTranslationFile<fileToLoad.size())
					{
						ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"Translation to load: "+fileToLoad.at(indexTranslationFile));
						temp=new QTranslator();
						if(!temp->load(fileToLoad.at(indexTranslationFile)) || temp->isEmpty())
						{
							delete temp;
							ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"Unable to load the translation file: "+fileToLoad.at(indexTranslationFile));
						}
						else
						{
							QCoreApplication::installTranslator(temp);
							installedTranslator<<temp;
						}
						indexTranslationFile++;
					}
					temp=new QTranslator();
					if(temp->load(QString("qt_")+newLanguage, QLibraryInfo::location(QLibraryInfo::TranslationsPath)) && !temp->isEmpty())
					{
						QCoreApplication::installTranslator(temp);
						installedTranslator<<temp;
					}
					else
					{
						if(!temp->load(LanguagesAvailableList.at(index).path+"qt.qm") || temp->isEmpty())
						{
							ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"Unable to load the translation file: qt.qm, into: "+LanguagesAvailableList.at(index).path);
							delete temp;
						}
						else
						{
							QCoreApplication::installTranslator(temp);
							installedTranslator<<temp;
						}
					}
				}
				currentLanguage=newLanguage;
				ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"emit newLanguageLoaded()");
				emit newLanguageLoaded(currentLanguage);
				return;
			}
			index++;
		}
		ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"unable to found language: "+newLanguage+", LanguagesAvailableList.size(): "+QString::number(LanguagesAvailableList.size()));
	}
//.........这里部分代码省略.........
开发者ID:dolanor,项目名称:Ultracopier,代码行数:101,代码来源:LanguagesManager.cpp

示例8: QNetworkConfigurationManager

Application::Application(int &argc, char **argv) :
    SharedTools::QtSingleApplication(argc, argv),
    _tray(0),
#if QT_VERSION >= 0x040700
    _networkMgr(new QNetworkConfigurationManager(this)),
#endif
    _sslErrorDialog(0),
    _contextMenu(0),
    _theme(Theme::instance()),
    _updateDetector(0),
    _logBrowser(0),
    _showLogWindow(false),
    _logFlush(false),
    _helpOnly(false),
    _fileItemDialog(0)
{
    setApplicationName( _theme->appName() );
    setWindowIcon( _theme->applicationIcon() );

    parseOptions(arguments());
    setupLogBrowser();
    //no need to waste time;
    if ( _helpOnly ) return;

    QString locale = Theme::instance()->enforcedLocale();
    if (locale.isEmpty()) locale = QLocale::system().name();

    QTranslator *qtTranslator = new QTranslator(this);
#if defined(Q_OS_MAC)
    qtTranslator->load(QLatin1String("qt_") + locale, applicationDirPath()+QLatin1String("/../translations") ); // path defaults to app dir.
#elif defined(Q_OS_WIN32)
    qtTranslator->load(QLatin1String("qt_") + locale, applicationDirPath());
#endif
    if (qtTranslator->isEmpty()) {
        qtTranslator->load(QLatin1String("qt_") + QLocale::system().name(),
                           QLibraryInfo::location(QLibraryInfo::TranslationsPath));
    }
    installTranslator(qtTranslator);

    QTranslator *mirallTranslator = new QTranslator(this);

#ifdef Q_OS_LINUX
    // FIXME - proper path!
    mirallTranslator->load(QLatin1String("mirall_") + locale, QLatin1String("/usr/share/mirall/i18n/"));
#endif
#ifdef Q_OS_MAC
    mirallTranslator->load(QLatin1String("mirall_") + locale, applicationDirPath()+QLatin1String("/../translations") ); // path defaults to app dir.
#endif
#ifdef Q_OS_WIN32
    mirallTranslator->load(QLatin1String("mirall_") + locale, applicationDirPath());
#endif

    installTranslator(mirallTranslator);

    connect( this, SIGNAL(messageReceived(QString)), SLOT(slotParseOptions(QString)));
    connect( Logger::instance(), SIGNAL(guiLog(QString,QString)),
             this, SLOT(slotShowTrayMessage(QString,QString)));
    // create folder manager for sync folder management
    _folderMan = new FolderMan(this);
    connect( _folderMan, SIGNAL(folderSyncStateChange(QString)),
             this,SLOT(slotSyncStateChange(QString)));

    /* use a signal mapper to map the open requests to the alias names */
    _folderOpenActionMapper = new QSignalMapper(this);
    connect(_folderOpenActionMapper, SIGNAL(mapped(const QString &)),
            this, SLOT(slotFolderOpenAction(const QString &)));

    setQuitOnLastWindowClosed(false);

    _folderWizard = new FolderWizard;

    _owncloudSetupWizard = new OwncloudSetupWizard( _folderMan, _theme, this );
    connect( _owncloudSetupWizard, SIGNAL(ownCloudWizardDone(int)),
             this, SLOT(slotownCloudWizardDone(int)));

    _statusDialog = new StatusDialog( _theme );
    connect( _statusDialog, SIGNAL(addASync()), this, SLOT(slotAddFolder()) );

    connect( _statusDialog, SIGNAL(removeFolderAlias( const QString&)),
             SLOT(slotRemoveFolder(const QString&)));

    connect( _statusDialog, SIGNAL(openLogBrowser()), this, SLOT(slotOpenLogBrowser()));

    connect( _statusDialog, SIGNAL(enableFolderAlias(QString,bool)),
             SLOT(slotEnableFolder(QString,bool)));
    connect( _statusDialog, SIGNAL(infoFolderAlias(const QString&)),
             SLOT(slotInfoFolder( const QString&)));
    connect( _statusDialog, SIGNAL(openFolderAlias(const QString&)),
             SLOT(slotFolderOpenAction(QString)));

#if 0
#if QT_VERSION >= 0x040700
    qDebug() << "* Network is" << (_networkMgr->isOnline() ? "online" : "offline");
    foreach (const QNetworkConfiguration& netCfg, _networkMgr->allConfigurations(QNetworkConfiguration::Active)) {
        //qDebug() << "Network:" << netCfg.identifier();
    }
#endif
#endif
    setupActions();
    setupSystemTray();
//.........这里部分代码省略.........
开发者ID:mjkent,项目名称:mirall,代码行数:101,代码来源:application.cpp


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