File indexing completed on 2024-12-22 03:46:49
0001 /* 0002 This file is part of the KTextTemplate library 0003 0004 SPDX-FileCopyrightText: 2010 Stephen Kelly <steveire@gmail.com> 0005 0006 SPDX-License-Identifier: LGPL-2.1-or-later 0007 0008 */ 0009 0010 #include "mainwindow.h" 0011 0012 #include <QApplication> 0013 #include <QLibraryInfo> 0014 #include <QTranslator> 0015 0016 #include <KTextTemplate/QtLocalizer> 0017 0018 #include "ktexttemplate_paths.h" 0019 0020 #define TEMPLATE_DIR KTEXTTEMPLATE_TEMPLATE_PATH "/linguist/" 0021 0022 static QSharedPointer<KTextTemplate::AbstractLocalizer> getLocalizer() 0023 { 0024 QSharedPointer<KTextTemplate::QtLocalizer> localizer = QSharedPointer<KTextTemplate::QtLocalizer>(new KTextTemplate::QtLocalizer); 0025 localizer->setAppTranslatorPrefix("contacts_"); 0026 localizer->setAppTranslatorPath(qApp->applicationDirPath()); 0027 0028 QStringList locales = QStringList() << "en_US" 0029 << "en_GB" 0030 << "de_DE" 0031 << "fr_FR"; 0032 if (!locales.contains(QLocale::system().name())) 0033 locales.append(QLocale::system().name()); 0034 for (const QString &localeName : locales) { 0035 QTranslator *qtTranslator = new QTranslator; 0036 qtTranslator->load("qt_" + localeName, QLibraryInfo::location(QLibraryInfo::TranslationsPath)); 0037 qtTranslator->setObjectName("qt_" + localeName); 0038 localizer->installTranslator(qtTranslator, localeName); 0039 0040 QTranslator *myappTranslator = new QTranslator; 0041 myappTranslator->load("contacts_" + localeName + ".qm", qApp->applicationDirPath()); 0042 myappTranslator->setObjectName("contacts_" + localeName); 0043 localizer->installTranslator(myappTranslator, localeName); 0044 } 0045 0046 return localizer.staticCast<KTextTemplate::AbstractLocalizer>(); 0047 } 0048 0049 template<> 0050 void AppMainWindow<KTextTemplate::QtLocalizer>::initLocalizer() 0051 { 0052 m_localizer = getLocalizer(); 0053 } 0054 0055 int main(int argc, char *argv[]) 0056 { 0057 QApplication app(argc, argv); 0058 0059 AppMainWindow<KTextTemplate::QtLocalizer> win(TEMPLATE_DIR); 0060 win.show(); 0061 0062 return app.exec(); 0063 }