25 #include <QtCore/QFile>
26 #include <QMutexLocker>
43 setlocale(LC_ALL,
"");
45 extern Q_CORE_EXPORT
bool qt_locale_initialized;
46 qt_locale_initialized =
true;
55 # define LC_MESSAGES 42
63 class KCatalogStaticData
66 KCatalogStaticData() {}
84 QByteArray systemLanguage;
87 static QByteArray currentLanguage;
89 void setupGettextEnv ();
90 void resetSystemLanguage ();
95 return debug << c.d->language <<
" " << c.d->name <<
" " << c.d->localeDir;
98 QByteArray KCatalogPrivate::currentLanguage;
101 : d( new KCatalogPrivate )
111 d->language = QFile::encodeName( language );
112 d->name = QFile::encodeName( name );
113 d->localeDir = QFile::encodeName( localeDir );
119 KCatalogPrivate::currentLanguage.clear();
125 QByteArray lang = qgetenv(
"LANGUAGE");
126 snprintf(langenv, langenvMaxlen,
"LANGUAGE=%s", lang.constData());
132 : d( new KCatalogPrivate )
152 QString relpath = QString::fromLatin1(
"%1/LC_MESSAGES/%2.mo" )
153 .arg( language ).arg( name );
159 return QFile::decodeName(d->name);
164 return QFile::decodeName(d->language);
169 return QFile::decodeName(d->localeDir);
173 extern "C" int __declspec(dllimport) _nl_msg_cat_cntr;
176 void KCatalogPrivate::setupGettextEnv ()
179 systemLanguage = qgetenv(
"LANGUAGE");
180 if (systemLanguage != language) {
183 snprintf(langenv, langenvMaxlen,
"LANGUAGE=%s", language.constData());
188 if (language != currentLanguage || !bindDone) {
190 currentLanguage = language;
199 extern int _nl_msg_cat_cntr;
205 void KCatalogPrivate::resetSystemLanguage ()
207 if (language != systemLanguage) {
208 snprintf(langenv, langenvMaxlen,
"LANGUAGE=%s", systemLanguage.constData());
214 QMutexLocker locker(&catalogStaticData->mutex);
215 d->setupGettextEnv();
216 const char *msgstr =
dgettext(d->name, msgid);
217 d->resetSystemLanguage();
218 return QString::fromUtf8(msgstr);
223 QMutexLocker locker(&catalogStaticData->mutex);
224 d->setupGettextEnv();
226 d->resetSystemLanguage();
227 return QString::fromUtf8(msgstr);
231 unsigned long n)
const
233 QMutexLocker locker(&catalogStaticData->mutex);
234 d->setupGettextEnv();
235 const char *msgstr =
dngettext(d->name, msgid, msgid_plural, n);
236 d->resetSystemLanguage();
237 return QString::fromUtf8(msgstr);
241 const char * msgid_plural,
unsigned long n)
const
243 QMutexLocker locker(&catalogStaticData->mutex);
244 d->setupGettextEnv();
245 const char *msgstr =
dnpgettext_expr(d->name, msgctxt, msgid, msgid_plural, n);
246 d->resetSystemLanguage();
247 return QString::fromUtf8(msgstr);
252 QMutexLocker locker(&catalogStaticData->mutex);
253 d->setupGettextEnv();
254 const char *msgstr =
dgettext(d->name, msgid);
255 d->resetSystemLanguage();
256 return msgstr != msgid ? QString::fromUtf8(msgstr) :
QString();
261 QMutexLocker locker(&catalogStaticData->mutex);
262 d->setupGettextEnv();
264 d->resetSystemLanguage();
265 return msgstr != msgid ? QString::fromUtf8(msgstr) :
QString();
269 unsigned long n)
const
271 QMutexLocker locker(&catalogStaticData->mutex);
272 d->setupGettextEnv();
273 const char *msgstr =
dngettext(d->name, msgid, msgid_plural, n);
274 d->resetSystemLanguage();
275 return msgstr != msgid && msgstr != msgid_plural ? QString::fromUtf8(msgstr) :
QString();
279 const char * msgid_plural,
unsigned long n)
const
281 QMutexLocker locker(&catalogStaticData->mutex);
282 d->setupGettextEnv();
283 const char *msgstr =
dnpgettext_expr(d->name, msgctxt, msgid, msgid_plural, n);
284 d->resetSystemLanguage();
285 return msgstr != msgid && msgstr != msgid_plural ? QString::fromUtf8(msgstr) :
QString();
#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N)
static QString catalogLocaleDir(const QString &name, const QString &language)
Finds the locale directory for the given catalog in given language.
QString translateStrict(const char *msgid) const
Retrieves a translation of the specified message id, returning empty if the translation was not found...
#define K_GLOBAL_STATIC(TYPE, NAME)
This macro makes it easy to use non-POD types as global statics.
KStandardDirs * dirs()
Returns the application standard dirs object.
KCatalog & operator=(const KCatalog &rhs)
Assignment operator.
#define bindtextdomain(Domainname, Dirname)
#define bind_textdomain_codeset(Domainname, Codeset)
KCatalog(const QString &name, const QString &language)
Constructor.
int __declspec(dllimport) _nl_msg_cat_cntr
#define dgettext(Domainname, Msgid)
virtual ~KCatalog()
Destructor.
QString translate(const char *msgid) const
Retrieves a translation of the specified message id.
QString language() const
Returns the language of the catalog.
QString findResourceDir(const char *type, const QString &filename) const
Tries to find the directory the file is in.
QString localeDir() const
Returns locale directory of the catalog.
static const int langenvMaxlen
#define dpgettext_expr(Domainname, Msgctxt, Msgid)
QString name() const
Returns the name of the catalog.
QDebug operator<<(QDebug debug, const KCatalog &c)
This class abstracts a gettext message catalog.
#define dngettext(Domainname, Msgid1, Msgid2, N)