3 #include "resources/config.h" 8 #include <QLibraryInfo> 11 #include <QStringBuilder> 13 #if defined(GUI_QTWIDGETS) 14 # include <QApplication> 17 # include <QStyleFactory> 18 #elif defined(GUI_QTQUICK) 19 # include <QGuiApplication> 23 # include <QCoreApplication> 31 inline void initResources() {
32 Q_INIT_RESOURCE(qtutilsicons);
35 inline void cleanupResources() {
36 Q_CLEANUP_RESOURCE(qtutilsicons);
109 for(
const QString &repoName : repositoryNames) {
110 QTranslator *qtTranslator =
new QTranslator;
111 const QString fileName(repoName % QChar(
'_') % localeName);
113 QCoreApplication::installTranslator(qtTranslator);
114 }
else if(qtTranslator->load(fileName, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) {
115 QCoreApplication::installTranslator(qtTranslator);
116 }
else if(qtTranslator->load(fileName, QStringLiteral(
"../share/qt/translations"))) {
118 QCoreApplication::installTranslator(qtTranslator);
119 }
else if(qtTranslator->load(fileName, QStringLiteral(
":/translations"))) {
120 QCoreApplication::installTranslator(qtTranslator);
123 cerr <<
"Unable to load translation file for Qt repository \"" << repoName.toLocal8Bit().data() <<
"\" and language " << localeName.toLocal8Bit().data() <<
"." << endl;
146 if(QLocale().name() != QLatin1String(
"en_US")) {
167 QTranslator *appTranslator =
new QTranslator;
168 const QString fileName(QStringLiteral(
"%1_%2").arg(applicationName, localeName));
170 QCoreApplication::installTranslator(appTranslator);
171 }
else if(appTranslator->load(fileName, QStringLiteral(
"."))) {
172 QCoreApplication::installTranslator(appTranslator);
173 }
else if(appTranslator->load(fileName, QStringLiteral(
"./translations"))) {
174 QCoreApplication::installTranslator(appTranslator);
175 }
else if(appTranslator->load(fileName, QStringLiteral(APP_INSTALL_PREFIX
"/share/%1/translations").arg(applicationName))) {
176 QCoreApplication::installTranslator(appTranslator);
177 }
else if(appTranslator->load(fileName, QStringLiteral(
"../share/%1/translations").arg(applicationName))) {
178 QCoreApplication::installTranslator(appTranslator);
179 }
else if(appTranslator->load(fileName, QStringLiteral(
":/translations"))) {
180 QCoreApplication::installTranslator(appTranslator);
182 delete appTranslator;
183 cerr <<
"Unable to load translation file for \"" << applicationName.toLocal8Bit().data() <<
"\" and the language \"" << localeName.toLocal8Bit().data() <<
"\"." << endl;
193 for(
const QString &applicationName : applicationNames) {
205 for(
const QString &applicationName : applicationNames) {
217 #if defined(GUI_QTWIDGETS) 223 return qobject_cast<QApplication *>(QCoreApplication::instance()) !=
nullptr;
227 #if defined(GUI_QTWIDGETS) || defined(GUI_QTQUICK) 233 return qobject_cast<QGuiApplication *>(QCoreApplication::instance()) !=
nullptr;
242 return qobject_cast<QCoreApplication *>(QCoreApplication::instance()) !=
nullptr;
256 QString
locateConfigFile(
const QString &applicationName,
const QString &fileName,
const QSettings *settings)
259 if(QFile::exists(fileName)) {
265 path = QFileInfo(settings->fileName()).absoluteDir().absoluteFilePath(fileName);
266 if(QFile::exists(path)) {
273 path = QStringLiteral(
"../etc/") % applicationName % QChar(
'/') % fileName;
274 if(QFile::exists(path)) {
278 path = QStringLiteral(
"../share/") % applicationName % QChar(
'/') % fileName;
279 if(QFile::exists(path)) {
286 path = QStringLiteral(
"/etc/") % applicationName % QChar(
'/') % fileName;
287 if(QFile::exists(path)) {
291 path = QStringLiteral(
"/usr/share/") % applicationName % QChar(
'/') % fileName;
292 if(QFile::exists(path)) {
QT_UTILITIES_EXPORT void cleanup()
Frees the resources used and provided by this library.
QT_UTILITIES_EXPORT bool hasCoreApp()
Returns whether a QCoreApplication has been instantiated yet.
Convenience functions to load translations for Qt and the application.
QT_UTILITIES_EXPORT QString locateConfigFile(const QString &applicationName, const QString &fileName, const QSettings *settings=nullptr)
Locates the config file with the specified fileName for the application with the specified applicatio...
QT_UTILITIES_EXPORT QString & additionalTranslationFilePath()
Allows to set an additional search path for translation files.
QT_UTILITIES_EXPORT void init()
Initiates the resources used and provided by this library.
Convenience functions to check whether a QCoreApplication/QGuiApplication/QApplication singleton has ...
QT_UTILITIES_EXPORT void loadApplicationTranslationFile(const QString &applicationName)
Loads and installs the appropriate application translation file for the current locale.
Provides convenience functions for handling config files.
void loadQtTranslationFile(initializer_list< QString > repositoryNames, const QString &localeName)
Loads and installs the appropriate Qt translation file for the specified locale.