StelTranslator.cpp   StelTranslator.cpp 
skipping to change at line 20 skipping to change at line 20
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US A. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US A.
*/ */
#include <config.h>
#include <dirent.h> #include <dirent.h>
#include <cstdio> #include <cstdio>
#include <algorithm> #include <algorithm>
#include <fstream> #include <fstream>
#include <clocale> #include <clocale>
#include <cstdlib> #include <cstdlib>
#include <QFile> #include <QFile>
#include <QDebug> #include <QDebug>
#include <QStringList> #include <QStringList>
#include <QRegExp> #include <QRegExp>
skipping to change at line 105 skipping to change at line 104
{ {
if (StelTranslator::lastUsed == this) if (StelTranslator::lastUsed == this)
return; return;
// Find out what the system language is if not defined yet // Find out what the system language is if not defined yet
if (systemLangName.isEmpty()) if (systemLangName.isEmpty())
initSystemLanguage(); initSystemLanguage();
// Apply that // Apply that
// This needs to be static as it is used a each gettext call... It t ooks me quite a while before I got that :( // This needs to be static as it is used a each gettext call... It t ooks me quite a while before I got that :(
static char envstr[25]; static char envstr[128];
if (langName=="system" || langName=="system_default") if (langName=="system" || langName=="system_default")
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
{ {
snprintf(envstr, 25, "LANG=%s", StelTranslator::systemLangNa me.toUtf8().constData()); qsnprintf(envstr, 128, "LANG=%s", StelTranslator::systemLang Name.toUtf8().constData());
} }
else else
{ {
snprintf(envstr, 25, "LANG=%s", langName.toUtf8().constData( )); qsnprintf(envstr, 128, "LANG=%s", langName.toUtf8().constDat a());
} }
#elif defined (Q_OS_WIN) //MSCVER #elif defined (Q_OS_WIN) //MSCVER
{ {
_snprintf(envstr, 25, "LANGUAGE=%s", StelTranslator::systemL angName.toUtf8().constData()); qsnprintf(envstr, 128, "LANGUAGE=%s", StelTranslator::system LangName.toUtf8().constData());
} }
else else
{ {
_snprintf(envstr, 25, "LANGUAGE=%s", langName.toUtf8().const Data()); qsnprintf(envstr, 128, "LANGUAGE=%s", langName.toUtf8().cons tData());
} }
#else // UNIX #else // UNIX
{ {
snprintf(envstr, 25, "LANGUAGE=%s", StelTranslator::systemLa ngName.toUtf8().constData()); qsnprintf(envstr, 128, "LANGUAGE=%s", StelTranslator::system LangName.toUtf8().constData());
} }
else else
{ {
snprintf(envstr, 25, "LANGUAGE=%s", langName.toUtf8().constD ata()); qsnprintf(envstr, 128, "LANGUAGE=%s", langName.toUtf8().cons tData());
} }
#endif #endif
putenv(envstr); putenv(envstr);
#ifndef Q_OS_WIN #ifndef Q_OS_WIN
setlocale(LC_MESSAGES, ""); setlocale(LC_MESSAGES, "");
#else #else
setlocale(LC_CTYPE,""); setlocale(LC_CTYPE,"");
#endif #endif
QString result = bind_textdomain_codeset(domain.toUtf8().constData() , "UTF-8"); QString result = bind_textdomain_codeset(domain.toUtf8().constData() , "UTF-8");
Q_ASSERT(result=="UTF-8"); Q_ASSERT(result=="UTF-8");
bindtextdomain (domain.toUtf8().constData(), QFile::encodeName(moDir ectory).constData()); bindtextdomain (domain.toUtf8().constData(), QFile::encodeName(moDir ectory).constData());
textdomain (domain.toUtf8().constData()); textdomain (domain.toUtf8().constData());
StelTranslator::lastUsed = this; StelTranslator::lastUsed = this;
} }
//! Convert from ISO639-1 2 letters langage code to native language name //! Convert from ISO639-1 2 letters langage code to native language name
QString StelTranslator::iso639_1CodeToNativeName(const QString& languageCod e) QString StelTranslator::iso639_1CodeToNativeName(const QString& languageCod e)
{ {
if (languageCode=="C")
return "English";
QLocale loc(languageCode); QLocale loc(languageCode);
QString l = loc.name(); QString l = loc.name();
// There is a QLocale for this code. This should be the cas // There is a QLocale for this code. This should be the case for mo
e for most st
// language codes, but there are a few without QLocales, e.g // language codes, but there are a few without QLocales, e.g. Interl
. Interlingua ingua
if (l.contains('_')) if (l.contains('_'))
l.truncate(l.indexOf('_')); l.truncate(l.indexOf('_'));
if (iso639codes.find(l)!=iso639codes.end()) if (iso639codes.find(l)!=iso639codes.end())
return iso639codes[l]+ (languageCode.size()==2 ? "" return iso639codes[l]+ (languageCode.size()==2 ? "" : QStrin
: QString(" (")+QLocale::countryToString(loc.country())+")"); g(" (")+QLocale::countryToString(loc.country())+")");
// For codes which return the locale C, use the language cod // For codes which return the locale C, use the language code to do
e to do the lookup the lookup
if (iso639codes.contains(languageCode)) if (iso639codes.contains(languageCode))
return iso639codes[languageCode]; return iso639codes[languageCode];
// qWarning() << "WARNING: Cannot determine name of language // qWarning() << "WARNING: Cannot determine name of language for cod
for code" << languageCode; e" << languageCode;
return languageCode; return languageCode;
} }
//! Convert from native language name to ISO639-1 2(+3) letters langage cod e //! Convert from native language name to ISO639-1 2(+3) letters langage cod e
QString StelTranslator::nativeNameToIso639_1Code(const QString& languageNam e) QString StelTranslator::nativeNameToIso639_1Code(const QString& languageNam e)
{ {
QMap<QString, QString>::iterator iter; QMap<QString, QString>::iterator iter;
for (iter=iso639codes.begin();iter!=iso639codes.end();++iter) for (iter=iso639codes.begin();iter!=iso639codes.end();++iter)
if (iter.value() == languageName) if (iter.value() == languageName)
return iter.key(); return iter.key();
skipping to change at line 245 skipping to change at line 247
Q_ASSERT(0); Q_ASSERT(0);
} }
if (!iso639codes.empty()) if (!iso639codes.empty())
iso639codes.clear(); iso639codes.clear();
while (!inf.atEnd()) while (!inf.atEnd())
{ {
QString record = QString::fromUtf8(inf.readLine()); QString record = QString::fromUtf8(inf.readLine());
record.remove(QRegExp("[\\n\\r]*$")); // chomp new lines record.remove(QRegExp("[\\n\\r]*$")); // chomp new lines
QStringList fields = record.split("\t", QString::SkipEmptyPa rts); const QStringList& fields = record.split("\t", QString::Skip EmptyParts);
iso639codes.insert(fields.at(0), fields.at(2)); iso639codes.insert(fields.at(0), fields.at(2));
} }
} }
 End of changes. 12 change blocks. 
26 lines changed or deleted 28 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/