Example #1
0
void Translator::loadTranslations(const QString &catalog, const QString &path, const QString &overrideLanguage)
{
    const QDir dir(path);
    const QLocale locale;
    QStringList names = locale.uiLanguages();
    if (!overrideLanguage.isEmpty())
        names.prepend(overrideLanguage);

    foreach (const QString &name, names) {
        const QLocale uiLocale(name);
        auto translator = new QTranslator(QCoreApplication::instance());
        if (translator->load(uiLocale, catalog, QStringLiteral("_"), path)) {
            QCoreApplication::instance()->installTranslator(translator);
            return;
        } else {
            delete translator;

            foreach (const QString &name, uiLocale.uiLanguages()) {
                const QString fileName = QString("%1_%2.qm").arg(catalog, name);
                const QString filePath = dir.filePath(fileName);
                if (QFile::exists(filePath)) {
                    return;
                }
            }
        }
    }

    if (locale.language() != QLocale::C && locale.language() != QLocale::English)
        qDebug() << "did not find a translation for" << catalog << "in" << path
                 << "for language" << locale.name();
}
Example #2
0
///////////////////////////////////////////////////////////
// メイン
///////////////////////////////////////////////////////////
int main( int argc, char *argv[] )
{
#ifdef PANDORA
	//VALGRIND実行時用の環境変数
	setenv("DISPLAY", ":0.0", 1);
	//GlibのOSと開発環境のバージョン不一致に対する暫定対応
	//setenv("QT_NO_GLIB", "0", 1);
	//EGLFS対応
	setenv("EGLFS_X11_SIZE", "800x480", 1);
	setenv("EGLFS_X11_FULLSCREEN", "1", 1);
	setenv("QT_QPA_EGLFS_DEPTH", "16", 1);
	setenv("QT_QPA_EGLFS_PHYSICAL_WIDTH", "200", 1);
	setenv("QT_QPA_EGLFS_PHYSICAL_HEIGHT", "150", 1);
#endif

	//X11の場合用
	QCoreApplication::setAttribute(Qt::AA_X11InitThreads);
#if QT_VERSION >= 0x050700
	QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif

	P6VXApp app(argc, argv);

	QCommandLineParser parser;
	QCommandLineOption safeModeOption(QStringList() << "s" << "safemode", "Safe Mode");
	parser.addOption(safeModeOption);
	parser.process(app);
	bool safeMode = parser.isSet(safeModeOption);
	app.enableSafeMode(safeMode);

#ifdef ANDROID
	app.setCustomRomPath(CUSTOMROMPATH);
#endif

	QLocale locale;
    QString lang = locale.uiLanguages()[0];
    QTranslator myappTranslator;

    //表示言語が日本語でない場合は英語リソースを読み込む
	if(lang != "ja-JP" && lang != "ja"){
		qDebug() << "LANG = " << lang;
        myappTranslator.load(":/translation/PC6001VX_en");
        app.installTranslator(&myappTranslator);
	} else {
#ifdef ANDROID
		app.setFont(QFont("MotoyaLMaru"));
#endif
	}

	//イベントループが始まったらp6vxapp::startup()を実行
    QMetaObject::invokeMethod(&app, "startup", Qt::QueuedConnection);

    //イベントループを開始
	return app.exec();
}
Example #3
0
void LanguagesWidget::localeChanged(QLocale locale)
{
    languagesList->clear();
    foreach (const QString &lang, locale.uiLanguages()) {
        QListWidgetItem *item = new QListWidgetItem(lang, languagesList);
        QLocale l(lang);
        if (l.language() != QLocale::C) {
            QString language = QLocale::languageToString(l.language());
            QString country = QLocale::countryToString(l.country());
            QString tooltip = QString(QLatin1String("%1: %2/%3")).arg(l.name(), language, country);
            item->setToolTip(tooltip);
        }
    }
}
Example #4
0
static QString find_translation(const QLocale & locale,
                                const QString & filename,
                                const QString & prefix,
                                const QString & directory,
                                const QString & suffix)
{
    QString path;
    if (QFileInfo(filename).isRelative()) {
        path = directory;
        if (!path.isEmpty() && !path.endsWith(QLatin1Char('/')))
            path += QLatin1Char('/');
    }

    QFileInfo fi;
    QString realname;
    QStringList fuzzyLocales;

    // see http://www.unicode.org/reports/tr35/#LanguageMatching for inspiration

    QStringList languages = locale.uiLanguages();
#if defined(Q_OS_UNIX)
    for (int i = languages.size()-1; i >= 0; --i) {
        QString lang = languages.at(i);
        QString lowerLang = lang.toLower();
        if (lang != lowerLang)
            languages.insert(i+1, lowerLang);
    }
#endif

    // try explicit locales names first
    foreach (QString localeName, languages) {
        localeName.replace(QLatin1Char('-'), QLatin1Char('_'));

        realname = path + filename + prefix + localeName + (suffix.isNull() ? QLatin1String(".qm") : suffix);
        fi.setFile(realname);
        if (fi.isReadable() && fi.isFile())
            return realname;

        realname = path + filename + prefix + localeName;
        fi.setFile(realname);
        if (fi.isReadable() && fi.isFile())
            return realname;

        fuzzyLocales.append(localeName);
    }
Example #5
0
QV4::ReturnedValue QQmlLocaleData::method_get_uiLanguages(QV4::CallContext *ctx)
{
    QV4::Scope scope(ctx);
    QLocale *locale = getThisLocale(ctx);
    if (!locale)
        return QV4::Encode::undefined();

    QStringList langs = locale->uiLanguages();
    QV4::ScopedArrayObject result(scope, ctx->d()->engine->newArrayObject());
    result->arrayReserve(langs.size());
    QV4::ScopedValue v(scope);
    for (int i = 0; i < langs.size(); ++i)
        result->arrayPut(i, (v = ctx->d()->engine->newString(langs.at(i))));

    result->setArrayLengthUnchecked(langs.size());

    return result.asReturnedValue();
}
Example #6
0
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);
}
Example #7
0
QString uiLanguage(QLocale *callerLoc)
{
	QSettings s;
	s.beginGroup("Language");

	if (!s.value("UseSystemLanguage", true).toBool()) {
		loc = QLocale(s.value("UiLanguage", QLocale().uiLanguages().first()).toString());
	} else {
		loc = QLocale(QLocale().uiLanguages().first());
	}

	QString uiLang = loc.uiLanguages().first();
	s.endGroup();

	// there's a stupid Qt bug on MacOS where uiLanguages doesn't give us the country info
	if (!uiLang.contains('-') && uiLang != loc.bcp47Name()) {
		QLocale loc2(loc.bcp47Name());
		loc = loc2;
		uiLang = loc2.uiLanguages().first();
	}
	if (callerLoc)
		*callerLoc = loc;

	// the short format is fine
	// the long format uses long weekday and month names, so replace those with the short ones
	// for time we don't want the time zone designator and don't want leading zeroes on the hours
	shortDateFormat = loc.dateFormat(QLocale::ShortFormat);
	dateFormat = loc.dateFormat(QLocale::LongFormat);
	dateFormat.replace("dddd,", "ddd").replace("dddd", "ddd").replace("MMMM", "MMM");
	// special hack for Swedish as our switching from long weekday names to short weekday names
	// messes things up there
	dateFormat.replace("'en' 'den' d:'e'", " d");
	timeFormat = loc.timeFormat();
	timeFormat.replace("(t)", "").replace(" t", "").replace("t", "").replace("hh", "h").replace("HH", "H").replace("'kl'.", "");
	timeFormat.replace(".ss", "").replace(":ss", "").replace("ss", "");
	return uiLang;
}
Example #8
0
QString uiLanguage(QLocale *callerLoc)
{
	QSettings s;
	s.beginGroup("Language");
	QLocale loc;

	if (!s.value("UseSystemLanguage", true).toBool()) {
		loc = QLocale(s.value("UiLanguage", QLocale().uiLanguages().first()).toString());
	}

	QString uiLang = loc.uiLanguages().first();
	s.endGroup();

	// there's a stupid Qt bug on MacOS where uiLanguages doesn't give us the country info
	if (!uiLang.contains('-') && uiLang != loc.bcp47Name()) {
		QLocale loc2(loc.bcp47Name());
		loc = loc2;
		uiLang = loc2.uiLanguages().first();
	}
	if (callerLoc)
		*callerLoc = loc;

	return uiLang;
}
Example #9
0
void init_ui(int *argcp, char ***argvp)
{
	QVariant v;

	application = new QApplication(*argcp, *argvp);

	// tell Qt to use system proxies
	// note: on Linux, "system" == "environment variables"
	QNetworkProxyFactory::setUseSystemConfiguration(true);

#if QT_VERSION < 0x050000
	// ask QString in Qt 4 to interpret all char* as UTF-8,
	// like Qt 5 does.
	// 106 is "UTF-8", this is faster than lookup by name
	// [http://www.iana.org/assignments/character-sets/character-sets.xml]
	QTextCodec::setCodecForCStrings(QTextCodec::codecForMib(106));
#endif
	QCoreApplication::setOrganizationName("Subsurface");
	QCoreApplication::setOrganizationDomain("subsurface.hohndel.org");
	QCoreApplication::setApplicationName("Subsurface");
	xslt_path = strdup(getSubsurfaceDataPath("xslt").toAscii().data());

	QLocale loc;
	QString uiLang = loc.uiLanguages().first();
	// there's a stupid Qt bug on MacOS where uiLanguages doesn't give us the country info
	if (!uiLang.contains('-') && uiLang != loc.bcp47Name()) {
		QLocale loc2(loc.bcp47Name());
		loc = loc2;
		uiLang = loc2.uiLanguages().first();
	}

	// we don't have translations for English - if we don't check for this
	// Qt will proceed to load the second language in preference order - not what we want
	// on Linux this tends to be en-US, but on the Mac it's just en
	if (!uiLang.startsWith("en")) {
		qtTranslator = new QTranslator;
		if (qtTranslator->load(loc,"qt", "_", QLibraryInfo::location(QLibraryInfo::TranslationsPath))) {
			application->installTranslator(qtTranslator);
		} else {
			qDebug() << "can't find Qt localization for locale" << uiLang <<
				    "searching in" << QLibraryInfo::location(QLibraryInfo::TranslationsPath);
		}
		ssrfTranslator = new QTranslator;
		if (ssrfTranslator->load(loc,"subsurface", "_") ||
				ssrfTranslator->load(loc,"subsurface", "_", getSubsurfaceDataPath("translations")) ||
				ssrfTranslator->load(loc,"subsurface", "_", getSubsurfaceDataPath("../translations"))) {
			application->installTranslator(ssrfTranslator);
		} else {
			qDebug() << "can't find Subsurface localization for locale" << uiLang;
		}
	}

	QSettings s;
	s.beginGroup("GeneralSettings");
	prefs.default_filename = getSetting(s, "default_filename");
	s.endGroup();
	s.beginGroup("DiveComputer");
	default_dive_computer_vendor = getSetting(s, "dive_computer_vendor");
	default_dive_computer_product = getSetting(s,"dive_computer_product");
	default_dive_computer_device = getSetting(s, "dive_computer_device");
	s.endGroup();

	window = new MainWindow();
	window->show();
	if (existing_filename && existing_filename[0] != '\0')
		window->setTitle(MWTF_FILENAME);
	else
		window->setTitle(MWTF_DEFAULT);

	return;
}