2018-09-29 15:56:04 +03:00
|
|
|
/*
|
2019-12-08 13:51:32 +03:00
|
|
|
* Copyright (C) 2018-2020 QuasarApp.
|
2018-09-29 15:56:04 +03:00
|
|
|
* Distributed under the lgplv3 software license, see the accompanying
|
|
|
|
* Everyone is permitted to copy and distribute verbatim copies
|
|
|
|
* of this license document, but changing it is not allowed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "locales.h"
|
|
|
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QTranslator>
|
|
|
|
#include <QLocale>
|
|
|
|
|
|
|
|
using namespace QuasarAppUtils;
|
|
|
|
|
2018-12-06 21:30:48 +03:00
|
|
|
|
|
|
|
bool Locales::initLocale(const QString& prefix, const QString &locale, QCoreApplication *app, QTranslator *translator){
|
2018-09-29 15:56:04 +03:00
|
|
|
|
|
|
|
QString defaultLocale = QLocale::system().name();
|
|
|
|
defaultLocale.truncate(defaultLocale.lastIndexOf('_'));
|
|
|
|
|
2018-12-06 21:30:48 +03:00
|
|
|
if(!locale.isEmpty() && translator->load(QString("%0/%1").arg(prefix, locale))) {
|
2018-09-29 15:56:04 +03:00
|
|
|
return app->installTranslator(translator);
|
|
|
|
}
|
|
|
|
|
2018-12-06 21:30:48 +03:00
|
|
|
if(!translator->load(QString("%0/%1").arg(prefix, defaultLocale))) {
|
2018-09-29 15:56:04 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return app->installTranslator(translator);
|
|
|
|
}
|