本文整理汇总了C++中QCoreApplication::installTranslator方法的典型用法代码示例。如果您正苦于以下问题:C++ QCoreApplication::installTranslator方法的具体用法?C++ QCoreApplication::installTranslator怎么用?C++ QCoreApplication::installTranslator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QCoreApplication
的用法示例。
在下文中一共展示了QCoreApplication::installTranslator方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadTranslations
void loadTranslations( QCoreApplication &app, QTranslator &translator )
{
const QString lang = QLocale::system().name();
QString code;
int index = lang.indexOf ( '_' );
if ( lang == "C" ) {
code = "en";
}
else if ( index != -1 ) {
code = lang.left ( index );
}
else {
index = lang.indexOf ( '@' );
if ( index != -1 )
code = lang.left ( index );
else
code = lang;
}
QString const i18nDir = "/usr/share/marble/translations";
QString const relativeDir = app.applicationDirPath() + "/translations";
foreach( const QString &path, QStringList() << i18nDir << relativeDir << QDir::currentPath() ) {
foreach( const QString &lang, QStringList() << lang << code ) {
QFileInfo translations = QFileInfo( path + "/routing-instructions_" + lang + ".qm" );
if ( translations.exists() && translator.load( translations.absoluteFilePath() ) ) {
app.installTranslator( &translator );
return;
}
}
}
}
示例2: loadTranslations
void qtvplugin_geomarker::loadTranslations()
{
//Trans
QCoreApplication * app = QCoreApplication::instance();
if (app && m_nInstance==1)
{
QString strTransLocalFile =
QCoreApplication::applicationDirPath()+"/" +
m_SLLibName+ "_" +
QLocale::system().name()+".qm";
if (true==pluginTranslator.load(strTransLocalFile ))
{
QTVOSM_DEBUG("Load translationfile")<<"\n\t"<<strTransLocalFile<<" Succeeded.";
app->installTranslator(&pluginTranslator);
ui->retranslateUi(this);
}
else
QTVOSM_WARNING("Load translationfile")<<"\n\t"<<strTransLocalFile<<" Not Found.";
}
}
示例3: setLanguage
void setLanguage(QCoreApplication& qapplication, QWidget* parent)
{
static int cntTranslators=0;
if(cntTranslators>0){
qapplication.removeTranslator(&translator);
cntTranslators=0;
}
//translator stuff
QDir d("/usr/share/fet/translations");
bool translation_loaded=false;
//this is one place (out of 2) in which you need to add a new language
if(FET_LANGUAGE=="ar" || FET_LANGUAGE=="ca" || FET_LANGUAGE=="de" || FET_LANGUAGE=="es"
|| FET_LANGUAGE=="el" || FET_LANGUAGE=="fr" || FET_LANGUAGE=="hu" || FET_LANGUAGE=="mk"
|| FET_LANGUAGE=="ms" || FET_LANGUAGE=="nl" || FET_LANGUAGE=="pl" || FET_LANGUAGE=="ro"
|| FET_LANGUAGE=="tr" || FET_LANGUAGE=="id" || FET_LANGUAGE=="it" || FET_LANGUAGE=="lt"
|| FET_LANGUAGE=="ru" || FET_LANGUAGE=="fa" || FET_LANGUAGE=="uk" || FET_LANGUAGE=="pt_BR"
|| FET_LANGUAGE=="da" || FET_LANGUAGE=="si" || FET_LANGUAGE=="sk" || FET_LANGUAGE=="he"
|| FET_LANGUAGE=="sr" || FET_LANGUAGE=="gl" || FET_LANGUAGE=="vi" || FET_LANGUAGE=="uz"){
translation_loaded=translator.load("fet_"+FET_LANGUAGE, qapplication.applicationDirPath());
if(!translation_loaded){
translation_loaded=translator.load("fet_"+FET_LANGUAGE, qapplication.applicationDirPath()+"/translations");
if(!translation_loaded){
if(d.exists()){
translation_loaded=translator.load("fet_"+FET_LANGUAGE, "/usr/share/fet/translations");
}
}
}
}
else{
if(FET_LANGUAGE!="en_US"){
/*
QMessageBox::warning(parent, QString("FET warning"),
QString("Specified language is incorrect - making it en_US (US English)"));
FET_LANGUAGE="en_US";
*/
}
assert(FET_LANGUAGE=="en_US");
translation_loaded=true;
}
if(!translation_loaded){
/*
QMessageBox::warning(parent, QString("FET warning"),
QString("Translation for specified language not loaded - maybe the translation file is missing - setting the language to en_US (US English)")
+"\n\n"+
QString("FET searched for the translation file %1 in the directory %2, then in the directory %3 and "
"then in the directory %4 (under systems that support such a directory), but could not find it.")
.arg("fet_"+FET_LANGUAGE+".qm")
.arg(QDir::toNativeSeparators(qapplication.applicationDirPath()))
.arg(QDir::toNativeSeparators(qapplication.applicationDirPath()+"/translations"))
.arg("/usr/share/fet/translations")
);
FET_LANGUAGE="en_US";
*/
}
if(FET_LANGUAGE=="ar" || FET_LANGUAGE=="he" || FET_LANGUAGE=="fa" || FET_LANGUAGE=="ur" /* and others? */){
LANGUAGE_STYLE_RIGHT_TO_LEFT=true;
}
else{
LANGUAGE_STYLE_RIGHT_TO_LEFT=false;
}
if(FET_LANGUAGE=="zh_CN"){
LANGUAGE_FOR_HTML="zh-Hans";
}
else if(FET_LANGUAGE=="zh_TW"){
LANGUAGE_FOR_HTML="zh-Hant";
}
else if(FET_LANGUAGE=="en_US"){
LANGUAGE_FOR_HTML=FET_LANGUAGE.left(2);
}
else{
LANGUAGE_FOR_HTML=FET_LANGUAGE;
LANGUAGE_FOR_HTML.replace(QString("_"), QString("-"));
}
assert(cntTranslators==0);
if(FET_LANGUAGE!="en_US"){
qapplication.installTranslator(&translator);
cntTranslators=1;
}
/*
if(LANGUAGE_STYLE_RIGHT_TO_LEFT==true)
qapplication.setLayoutDirection(Qt::RightToLeft);
*/
//retranslate
/*
QList<QWidget*> tlwl=qapplication.topLevelWidgets();
foreach(QWidget* wi, tlwl)
//.........这里部分代码省略.........
示例4: main
int main(int argc, char *argv[])
{
#ifdef WITH_IMAGEMAGICK
Magick::InitializeMagick(*argv);
#endif
QCoreApplication *a = (argc == 1) ? new QApplication(argc, argv) : new QCoreApplication(argc, argv);
if(a)
{
/* we need nice getDataHome */
#if defined(Q_OS_WIN32) || defined(Q_OS_WIN64)
QCoreApplication::setApplicationName("luckygps");
QCoreApplication::setOrganizationName(".");
#endif
QLocale locale = QLocale::system();
QString locale_name = locale.name();
QTranslator translator;
/* Detect if luckyGPS is executed in "local mode" (no installation) */
int local = 0;
QDir dir(QCoreApplication::applicationDirPath());
QFileInfoList fileList = dir.entryInfoList(QStringList("luckygps_*.qm"), QDir::AllEntries | QDir::NoDot | QDir::NoDotDot);
if(fileList.length() > 0)
local = 1;
#if defined(Q_OS_LINUX)
translator.load(QString("luckygps_") + locale_name, "/usr/share/luckygps");
#else
translator.load(QString("luckygps_") + locale_name, getDataHome(local));
#endif
a->installTranslator(&translator);
setlocale(LC_NUMERIC, "C");
if(argc == 1)
{
MainWindow w(0, local);
w.show();
a->exec();
}
#ifdef WITH_ROUTING
else
{
/* check if 1 argument is given */
if(argc > 3)
{
printf("\nUsage: luckygps FILE.osm.pbf [SETTINGS.spp]\n");
}
else
{
QString settingsFile;
if(argc == 2)
settingsFile = ":/data/motorcar.spp";
else
settingsFile = QString(argv[2]);
/* import osm file into routing database */
if(importOsmPbf(a, argv[1], settingsFile, local))
qWarning() << "Import successfully.";
else
qWarning() << "Import failed.";
}
}
#endif
delete a;
}
return true;
}