Fix top-to-bottom layout x-coord calculation
[lxde/liblxqt.git] / lxqttranslator.cpp
CommitLineData
949dba2f
AS
1#include "lxqttranslator.h"
2#include <QTranslator>
3#include <QLocale>
4#include <QDebug>
5#include <QCoreApplication>
6#include <QLibraryInfo>
7#include <QStringList>
949dba2f
AS
8#include <QFileInfo>
9
e6389bfc 10#include <XdgDirs>
afd3b116 11
949dba2f
AS
12using namespace LxQt;
13
14/************************************************
15
16 ************************************************/
17QStringList *getSearchPaths()
18{
19 static QStringList *searchPath = 0;
20
21 if (searchPath == 0)
22 {
23 searchPath = new QStringList();
24 *searchPath << XdgDirs::dataHome(false) + "/lxqt/translations";
25 *searchPath << XdgDirs::dataDirs("/lxqt/translations");
26 *searchPath << "/usr/local/share/lxqt/translations";
27 *searchPath << "/usr/share/lxqt/translations";
28 }
29
30 return searchPath;
31}
32
33
34/************************************************
35
36 ************************************************/
37QStringList LxQt::Translator::translationSearchPaths()
38{
39 return *(getSearchPaths());
40}
41
42
43/************************************************
44
45 ************************************************/
46void Translator::setTranslationSearchPaths(const QStringList &paths)
47{
48 QStringList *p = getSearchPaths();
49 p->clear();
50 *p << paths;
51}
52
53
54/************************************************
55
56 ************************************************/
57bool translate(const QString &name)
58{
59 QString locale = QLocale::system().name();
60
61 QStringList *paths = getSearchPaths();
62 foreach(QString path, *paths)
63 {
64 QTranslator *appTranslator = new QTranslator(qApp);
65 bool ok = appTranslator->load(name + "_" + locale, path);
66 if (ok)
67 {
68 QCoreApplication::installTranslator(appTranslator);
69 return ok;
70 }
71 }
72 return false;
73}
74
75
76/************************************************
77
78 ************************************************/
79bool Translator::translateApplication(const QString &applicationName)
80{
81 QString locale = QLocale::system().name();
82 QTranslator *qtTranslator = new QTranslator(qApp);
83 qtTranslator->load("qt_" + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
84 qApp->installTranslator(qtTranslator);
85
86
87 if (!applicationName.isEmpty())
88 return translate(applicationName);
89 else
90 return translate(QFileInfo(QCoreApplication::applicationFilePath()).baseName());
91}
92
93
94/************************************************
95
96 ************************************************/
97bool Translator::translateLibrary(const QString &libraryName)
98{
99 static QSet<QString> loadedLibs;
100
101 if (loadedLibs.contains(libraryName))
102 return true;
103
104 loadedLibs.insert(libraryName);
105
106 return translate(libraryName);
107}