~ubuntu-branches/ubuntu/maverick/stopmotion/maverick

« back to all changes in this revision

Viewing changes to src/application/languagehandler.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Bjoern Erik Nilsen
  • Date: 2008-07-25 12:59:29 UTC
  • mfrom: (1.1.7 upstream) (2.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20080725125929-bc75ds4t1f4hbywy
Tags: 0.6.2-1
* New upstream release
  - Fixed an invalid read reported by Valgrind.
  - Fixed a crash occuring on some 64-bit systems.
  - Fixed the default translation to be the same as the locale.
  - Rewrote the file system watcher to use inotify-tools instead of FAM.
  - Included the man page in upstream tarball.
  - Updated the Italian translation.
* segfault at startup (Closes: #488621)
* Upgrade to Standards-Version 3.8.0.
* Replace libfam-dev with libinotifytools-dev in control/Build-Depends

* Upload sponsored by Petter Reinholdtsen.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include <QDir>
26
26
#include <QTranslator>
27
27
#include <QLocale>
28
 
 
29
 
 
 
28
#include <QLatin1String>
 
29
 
 
30
 
 
31
#include <QDebug>
30
32
LanguageHandler::LanguageHandler(QObject *parent, QApplication *stApp, const char *name) 
31
33
        : QObject(parent)
32
34
{
33
35
        qmPath = QString(stopmotion::translationsDirectory);
34
36
        activeAction = 0;
35
37
        translator = new QTranslator(this);
36
 
        
37
 
        const char *localePtr = QLocale::system().name().toLatin1().constData();
38
 
        const char *languagePref = PreferencesTool::get()->getPreference("language", localePtr);
39
 
        QString locale(languagePref);
40
 
 
41
 
        if ( !locale.startsWith("en") ) {
42
 
                Logger::get().logDebug("Loading translator: ");
43
 
                Logger::get().logDebug(locale.toLatin1().constData());
44
 
                translator->load( "stopmotion_" + locale, qmPath);
45
 
        }
46
 
        
 
38
 
 
39
        // Get system locale.
 
40
        QString locale = QLocale::system().name().toLower();
 
41
        if (locale == QLatin1String("nb_no"))
 
42
            locale = QLatin1String("no_nb");
 
43
        else if (locale == QLatin1String("nn_no"))
 
44
            locale = QLatin1String("no_nn");
 
45
        else if (locale == QLatin1String("se_no"))
 
46
            locale = QLatin1String("no_se");
 
47
        else
 
48
            locale.truncate(2);
 
49
 
 
50
        // Put together a translation file based on the qmPath or keep
 
51
        // it empty if the locale is english.
 
52
        const bool englishLocale = (locale == QLatin1String("en"));
 
53
        const QString prefix = qmPath + QLatin1Char('/') + QLatin1String("stopmotion_");
 
54
        QString translationFile = englishLocale ? QString() : prefix + locale;
 
55
 
 
56
        if (!englishLocale && !QFile::exists(translationFile + QLatin1String(".qm"))) {
 
57
            // Was not able to find a translation file for the locale, so use the
 
58
            // language saved in the preferences file, or use English as fall-back.
 
59
            const QByteArray localeArray = locale.toLatin1();
 
60
            const char *localePtr = localeArray.constData();
 
61
            const char *languagePref = PreferencesTool::get()->getPreference("language", localePtr);
 
62
            if (languagePref) {
 
63
                translationFile = prefix + QLatin1String(languagePref);
 
64
                if (!QFile::exists(translationFile + QLatin1String(".qm")))
 
65
                    translationFile = QString();
 
66
                if (strcmp(languagePref, localePtr) != 0)
 
67
                    xmlFree((xmlChar*)languagePref);
 
68
            } else {
 
69
                translationFile = QString();
 
70
            }
 
71
        } else {
 
72
            PreferencesTool::get()->setPreference("language", locale.toLatin1().constData());
 
73
        }
 
74
 
 
75
        if (!translationFile.isEmpty()) {
 
76
            Logger::get().logDebug("Loading translator: ");
 
77
            Logger::get().logDebug(translationFile.toLatin1().constData());
 
78
            translator->load(translationFile);
 
79
        }
 
80
 
47
81
        stApp->installTranslator(translator);
48
82
        setObjectName(name);
49
 
        
50
 
        if (strcmp(languagePref, localePtr) != 0) {
51
 
                xmlFree((xmlChar*)languagePref);
52
 
        }
53
83
}
54
84
 
55
85