StelTranslator.hpp   StelTranslator.hpp 
skipping to change at line 29 skipping to change at line 29
#ifndef _STELTRANSLATOR_HPP_ #ifndef _STELTRANSLATOR_HPP_
#define _STELTRANSLATOR_HPP_ #define _STELTRANSLATOR_HPP_
//! @file StelTranslator.hpp //! @file StelTranslator.hpp
//! Define some translation macros. //! Define some translation macros.
#include <QMap> #include <QMap>
#include <QString> #include <QString>
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include <QDebug>
// These macro are used as global function replacing standard gettext opera tion // These macro are used as global function replacing standard gettext opera tion
#include "gettext.h" #include "gettext.h"
//! @def q_(str) //! @def q_(str)
//! Return the gettext translated english text @a str using the current glo bal translator. //! Return the gettext translated english text @a str using the current glo bal translator.
//! The returned value is a localized QString. //! The returned value is a localized QString.
#define q_(str) StelTranslator::globalTranslator.qtranslate(str) #define q_(str) StelTranslator::globalTranslator.qtranslate(str)
//! @def qc_(str, ctxt)
//! Return the gettext translated english text @a str in context @b ctxt us
ing the current global translator.
//! The returned value is a localized QString.
#define qc_(str, ctxt) StelTranslator::globalTranslator.qtranslate(str, ctx
t)
//! @def N_(str) //! @def N_(str)
//! A pseudo function call that serves as a marker for the automated extrac tion of messages. //! A pseudo function call that serves as a marker for the automated extrac tion of messages.
//! A call to N_() doesn't translate. //! A call to N_() doesn't translate.
#define N_(str) gettext_noop(str) #define N_(str) gettext_noop(str)
//! Class used to translate strings to any language. //! Class used to translate strings to any language.
//! Implements a nice interface to gettext which is UTF-8 compliant and is somewhat multiplateform //! Implements a nice interface to gettext which is UTF-8 compliant and is somewhat multiplateform
//! All its operations do not modify the global locale. //! All its operations do not modify the global locale.
//! The purpose of this class is to remove all non-OO C locale functions fr om stellarium. //! The purpose of this class is to remove all non-OO C locale functions fr om stellarium.
//! @author Fabien Chereau //! @author Fabien Chereau
skipping to change at line 67 skipping to change at line 73
//! @param amoDirectory The directory where to look for the domain.m o translation files. //! @param amoDirectory The directory where to look for the domain.m o translation files.
//! @param alangName The C locale name or language name like "fr" or "fr_FR". If string is "" or "system" it will use the system locale. //! @param alangName The C locale name or language name like "fr" or "fr_FR". If string is "" or "system" it will use the system locale.
StelTranslator(const QString& adomain, const QString& amoDirectory, const QString& alangName) : StelTranslator(const QString& adomain, const QString& amoDirectory, const QString& alangName) :
domain(adomain), moDirectory(amoDirectory), langName (alangName) domain(adomain), moDirectory(amoDirectory), langName (alangName)
{ {
StelTranslator::lastUsed = NULL; StelTranslator::lastUsed = NULL;
} }
//! Translate input message and return it as a QString. //! Translate input message and return it as a QString.
//! @param s input string in english. //! @param s input string in english.
//! @param c disambiguation string (gettext "context" string).
//! @return The translated QString //! @return The translated QString
QString qtranslate(const QString& s) QString qtranslate(const QString& s, const QString& c = QString())
{ {
if (s.isEmpty()) return QString(); if (s.isEmpty()) return QString();
reload(); reload();
return QString::fromUtf8(gettext(s.toUtf8().constData())); if (c.isEmpty())
{
return QString::fromUtf8(gettext(s.toUtf8().constDat
a()));
}
else
{
// Avoid using pgettext() by manually forming
// the context/message combined string.
QByteArray bytesC = c.toUtf8();
QByteArray bytesS = s.toUtf8();
QByteArray glue(1, (char)0x4);
QByteArray bytes = bytesC + glue + bytesS;
QString t = QString::fromUtf8(gettext(bytes.data()))
;
// If no translation is found, return the original
// without the context.
if (t.toUtf8() == bytes)
return s;
else
return t;
}
} }
//! Get true translator locale name. Actual locale, never "system". //! Get true translator locale name. Actual locale, never "system".
//! @return Locale name e.g "fr_FR" //! @return Locale name e.g "fr_FR"
const QString& getTrueLocaleName(void) const const QString& getTrueLocaleName(void) const
{ {
if (langName=="system" || langName=="system_default") if (langName=="system" || langName=="system_default")
return StelTranslator::systemLangName; return StelTranslator::systemLangName;
else else
return langName; return langName;
 End of changes. 5 change blocks. 
2 lines changed or deleted 32 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/