-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathQtGettext.cpp
More file actions
87 lines (58 loc) · 2.15 KB
/
QtGettext.cpp
File metadata and controls
87 lines (58 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <QDir>
#include "QtGettext.h"
QtGettext* QtGettext::instance_ = NULL;
QtGettext* QtGettext::instance() {
if (instance_) return instance_;
instance_ = new QtGettext();
return instance_;
}
void QtGettext::destroyInstance() {
if (instance_) delete instance_;
instance_ = NULL;
}
QtGettext::QtGettext() {
gotAvailableLocales_ = false;
}
QtGettext::~QtGettext() {
}
QStringList QtGettext::availableLocales() const {
if (gotAvailableLocales_) return availableLocales_;
QDir dir(catalogueLocation());
availableLocales_ = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
gotAvailableLocales_ = true;
return availableLocales_;
}
QString QtGettext::charset() const {
const char* temp = moParser_.charset();
if (!temp) return "";
return QString::fromAscii(temp);
}
QString QtGettext::moFilePath() const {
return QString::fromAscii(LauGettext::moFilePath().c_str());
}
QString QtGettext::getTranslation(const QString& originalString) const {
GettextMessage* message = LauGettext::getTranslation(originalString.toAscii(), originalString.length());
if (!message) return originalString;
QString chars =charset();
if (charset() == "utf-8") {
return QString::fromUtf8(message->string);
} else if (charset() == "utf-16") {
const ushort* temp = (const ushort*)message->string;
return QString::fromUtf16(temp, message->length);
} else if (charset().indexOf("latin-1") >= 0) {
return QString::fromLatin1(message->string);
} else if (charset().indexOf("ucs-4") >= 0) {
const uint* temp = (const uint*)message->string;
return QString::fromUcs4(temp, message->length);
}
return QString::fromUtf8(message->string);
}
void QtGettext::setCatalogueName(const QString& name) {
LauGettext::setCatalogueName(name.toAscii().data()); // name.toStdString());
}
void QtGettext::setCatalogueLocation(const QString& location) {
LauGettext::setCatalogueLocation(location.toAscii().data()); // toStdString());
}
void QtGettext::setLocale(const QString& localeCode) {
LauGettext::setLocale(localeCode.toAscii().data()); // toStdString());
}