2
* This file is part of unity-2d
4
* Copyright 2011 Canonical Ltd.
7
* - Aurélien Gâteau <aurelien.gateau@canonical.com>
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; version 3.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22
#include <unity2dtr.h>
28
#include <QDeclarativeContext>
36
void init(const char* domain, const char* localeDir)
38
setlocale(LC_ALL, "");
39
bindtextdomain(domain, localeDir);
43
void qmlInit(QDeclarativeContext* context)
45
static QmlHelper helper;
46
context->setContextProperty("u2d", &helper);
49
QString QmlHelper::tr(const QString& text, const QString& domain)
51
if (domain.isNull()) {
52
return ::u2dTr(text.toUtf8().constData());
54
return ::u2dTr(text.toUtf8().constData(), domain.toUtf8().constData());
58
QString QmlHelper::tr(const QString& singular, const QString& plural, int n, const QString& domain)
60
if (domain.isNull()) {
61
return ::u2dTr(singular.toUtf8().constData(), plural.toUtf8().constData(), n);
63
return ::u2dTr(singular.toUtf8().constData(), plural.toUtf8().constData(), n, domain.toUtf8().constData());
69
QString u2dTr(const char* text, const char* domain)
71
return QString::fromUtf8(dgettext(domain, text));
74
QString u2dTr(const char* singular, const char* plural, int n, const char* domain)
76
QString text = QString::fromUtf8(dngettext(domain, singular, plural, n));
77
// Note: if `text` is "%%n" (meaning the string on screen should be "%n"
78
// literally), this will fail. I think we don't care for now.
79
text.replace("%n", QString::number(n));
83
#include <unity2dtr.moc>