#include "support/gettext.h"
#include "support/lstrings.h"
#include "support/lyxalgo.h" // sorted
+#include "support/Messages.h"
#include "support/os.h"
#include "support/Package.h"
QCoreApplication::setOrganizationDomain("lyx.org");
QCoreApplication::setApplicationName(app_name + "-" + lyx_version);
+ // Install translator for GUI elements.
+ installTranslator(&d->qt_trans_);
+
// FIXME: quitOnLastWindowClosed is true by default. We should have a
// lyxrc setting for this in order to let the application stay resident.
// But then we need some kind of dock icon, at least on Windows.
// FIXME: Do we need a lyxrc setting for this on Mac? This behaviour
// seems to be the default case for applications like LyX.
setQuitOnLastWindowClosed(false);
+
+ // This allows to translate the strings that appear in the LyX menu.
+ /// A translator suitable for the entries in the LyX menu.
+ /// Only needed with Qt/Mac.
+ installTranslator(new MenuTranslator(this));
#endif
#ifdef Q_WS_X11
QApplication::setDoubleClickInterval(300);
#endif
- // install translation file for Qt built-in dialogs
- QString language_name = QString("qt_") + QLocale::system().name();
-
- // language_name can be short (e.g. qt_zh) or long (e.g. qt_zh_CN).
- // Short-named translator can be loaded from a long name, but not the
- // opposite. Therefore, long name should be used without truncation.
- // c.f. http://doc.trolltech.com/4.1/qtranslator.html#load
- if (d->qt_trans_.load(language_name,
- QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
- {
- installTranslator(&d->qt_trans_);
- // even if the language calls for RtL, don't do that
- setLayoutDirection(Qt::LeftToRight);
- LYXERR(Debug::LOCALE, "Successfully installed Qt translations for locale "
- << language_name);
- } else
- LYXERR(Debug::LOCALE, "Could not find Qt translations for locale "
- << language_name);
-
-#ifdef Q_WS_MACX
- // This allows to translate the strings that appear in the LyX menu.
- /// A translator suitable for the entries in the LyX menu.
- /// Only needed with Qt/Mac.
- installTranslator(new MenuTranslator(this));
-#endif
connect(this, SIGNAL(lastWindowClosed()), this, SLOT(onLastWindowClosed()));
using namespace lyx::graphics;
void GuiApplication::resetGui()
{
// Set the language defined by the user.
- setRcGuiLanguage();
+ setGuiLanguage();
// Read menus
if (!readUIFile(toqstr(lyxrc.ui_file)))
}
-void GuiApplication::execBatchCommands()
+void GuiApplication::setGuiLanguage()
{
// Set the language defined by the user.
setRcGuiLanguage();
+ QString const default_language = toqstr(Messages::defaultLanguage());
+ LYXERR(Debug::LOCALE, "Tring to set default locale to: " << default_language);
+ QLocale const default_locale(default_language);
+ QLocale::setDefault(default_locale);
+
+ // install translation file for Qt built-in dialogs
+ QString const language_name = QString("qt_") + default_locale.name();
+
+ // language_name can be short (e.g. qt_zh) or long (e.g. qt_zh_CN).
+ // Short-named translator can be loaded from a long name, but not the
+ // opposite. Therefore, long name should be used without truncation.
+ // c.f. http://doc.trolltech.com/4.1/qtranslator.html#load
+ if (!d->qt_trans_.load(language_name,
+ QLibraryInfo::location(QLibraryInfo::TranslationsPath))) {
+ LYXERR(Debug::LOCALE, "Could not find Qt translations for locale "
+ << language_name);
+ return;
+ }
+
+ LYXERR(Debug::LOCALE, "Successfully installed Qt translations for locale "
+ << language_name);
+
+ switch (default_locale.language()) {
+ case QLocale::Arabic :
+ case QLocale::Hebrew :
+ case QLocale::Persian :
+ case QLocale::Urdu :
+ setLayoutDirection(Qt::RightToLeft);
+ break;
+ default:
+ setLayoutDirection(Qt::LeftToRight);
+ }
+}
+
+
+void GuiApplication::execBatchCommands()
+{
+ setGuiLanguage();
+
// Read menus
if (!readUIFile(toqstr(lyxrc.ui_file)))
// Gives some error box here.
namespace lyx {
+void Messages::setDefaultLanguage()
+{
+ char * env_lang[5] = {"LANGUAGE", "LC_ALL", "LC_MESSAGES", "LC_MESSAGE",
+ "LANG"};
+ for (size_t i = 0; i != 5; ++i) {
+ string const lang = getEnv(env_lang[i]);
+ if (lang.empty())
+ continue;
+ Messages::main_lang_ = lang;
+ return;
+ }
+ // Not found!
+ LYXERR(Debug::LOCALE, "Default language not found!");
+}
+
+
+// Instanciate static member.
+string Messages::main_lang_;
+
+
// This version use the traditional gettext.
Messages::Messages(string const & l)
: lang_(l), warned_(false)
}
textdomain(PACKAGE);
+
+ // Reset default language;
+ setDefaultLanguage();
}
return it->second;
// The string was not found, use gettext to generate it
-
- static string oldLANGUAGE;
static string oldLC_ALL;
if (!lang_.empty()) {
- oldLANGUAGE = getEnv("LANGUAGE");
oldLC_ALL = getEnv("LC_ALL");
// This GNU extension overrides any language locale
// wrt gettext.
if (!trans_c)
LYXERR(Debug::LOCALE, "Undefined result from gettext");
else if (trans_c == m_c) {
- LYXERR(Debug::LOCALE, "Same as entered returned");
+ //LYXERR(Debug::LOCALE, "Same as entered returned");
trans = from_ascii(m);
} else {
//LYXERR(Debug::LOCALE, "We got a translation");
if (!lang_.empty()) {
// Reset everything as it was.
LYXERR(Debug::LOCALE, "restoring LANGUAGE from " << getEnv("LANGUAGE")
- << " to " << oldLANGUAGE);
- if (!setEnv("LANGUAGE", oldLANGUAGE))
+ << " to " << main_lang_);
+ if (!setEnv("LANGUAGE", main_lang_))
LYXERR(Debug::LOCALE, "\t... failed!");
LYXERR(Debug::LOCALE, "restoring LC_ALL from " << getEnv("LC_ALL")
<< " to " << oldLC_ALL);