~dandrader/ubuntu-ui-toolkit/dontReparentPopup

« back to all changes in this revision

Viewing changes to modules/Ubuntu/Components/plugin/i18n.cpp

  • Committer: Daniel d'Andrada
  • Date: 2014-12-03 14:14:09 UTC
  • mfrom: (1337.2.22 staging)
  • Revision ID: daniel.dandrada@canonical.com-20141203141409-dl4knerbe0qln6wj
merge staging

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
namespace C {
23
23
#include <libintl.h>
 
24
#include <glib.h>
 
25
#include <glib/gi18n.h>
24
26
}
25
27
 
26
28
#include <stdlib.h>
187
189
        return QString::fromUtf8(C::dngettext(domain.toUtf8(), singular.toUtf8(), plural.toUtf8(), n));
188
190
    }
189
191
}
 
192
 
 
193
/*!
 
194
 * \qmlmethod string i18n::ctr(string context, string text)
 
195
 * Translate \a text using gettext and return the translation.
 
196
 * \a context is only visible to the translator and helps disambiguating for very short texts
 
197
 */
 
198
QString UbuntuI18n::ctr(const QString& context, const QString& text)
 
199
{
 
200
    return dctr(QString(), context, text);
 
201
}
 
202
 
 
203
/*!
 
204
 * \qmlmethod string i18n::dctr(string domain, string context, string text)
 
205
 * Translate \a text using gettext. Uses the specified domain \a domain instead of i18n.domain.
 
206
 * \a context is only visible to the translator and helps disambiguating for very short texts
 
207
 */
 
208
QString UbuntuI18n::dctr(const QString& domain, const QString& context, const QString& text)
 
209
{
 
210
    if (domain.isNull()) {
 
211
        return QString::fromUtf8(C::g_dpgettext2(NULL, context.toUtf8(), text.toUtf8()));
 
212
    } else {
 
213
        return QString::fromUtf8(C::g_dpgettext2(domain.toUtf8(), context.toUtf8(), text.toUtf8()));
 
214
    }
 
215
}