Pavel Sanda wrote: > i think we should use this only if there is some way how _not_ to have > localized numbers. either by our settings or to force lyx/qt respect > LC_NUMERIC variable of the environment. maybe i just dont use correct > syntax, but i'm not able to get rid of this localization when using > LC_NUMERIC=C. > are you able to switch it off and let other string be localized somehow?
It is supposed to respect the user's settings. However, our language setting (GuiApplication::setGuiLanguage()) is broken. It always uses Messages::defaultLanguage(), which overwrites manual LC_NUMERIC changes (the latter might be a bug in itself). The attached patch fixes that. If you have "Default" set in prefs, it will use the system defaults, and "LC_NUMERIC=C lyx" works as expected. BTW, I noticed that LyX::setRcGuiLanguage() always reports a failure when trying to set a different language from rc.gui_language. My inpression is that this report is wrong. Looking at Environment.cpp, I see the bool SetEnv return ::setenv(name.c_str(), encoded.c_str(), true); However, isn't setenv supposed to return "0" on success, and "-1" in case of failure? Jürgen
Index: src/frontends/qt4/qt_helpers.cpp =================================================================== --- src/frontends/qt4/qt_helpers.cpp (Revision 28169) +++ src/frontends/qt4/qt_helpers.cpp (Arbeitskopie) @@ -39,6 +39,7 @@ #include <QCheckBox> #include <QComboBox> #include <QLineEdit> +#include <QLocale> #include <QPalette> #include <QSet> @@ -78,7 +79,7 @@ Length::UNIT const unit = combo->currentLengthItem(); - return Length(length.toDouble(), unit).asString(); + return Length(length.trimmed().toDouble(), unit).asString(); } @@ -101,7 +102,7 @@ } } - return Length(length.toDouble(), unit); + return Length(length.trimmed().toDouble(), unit); } @@ -109,7 +110,8 @@ Length const & len, Length::UNIT /*defaultUnit*/) { combo->setCurrentItem(len.unit()); - input->setText(QString::number(Length(len).value())); + QLocale loc; + input->setText(loc.toString(Length(len).value())); } Index: src/frontends/qt4/GuiApplication.cpp =================================================================== --- src/frontends/qt4/GuiApplication.cpp (Revision 28169) +++ src/frontends/qt4/GuiApplication.cpp (Arbeitskopie) @@ -1076,9 +1076,17 @@ // 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 const gettext_locale(toqstr(Messages::defaultLanguage())); + LYXERR(Debug::LOCALE, "Locales: (1) LyX::Messages: " + << fromqstr(gettext_locale.name()) + << ", (2) preferences: " + << lyxrc.gui_language + << ", (3) system: " + << fromqstr(QLocale::system().name())); + QLocale const default_locale = (lyxrc.gui_language == "auto") ? + QLocale::system() : gettext_locale; + LYXERR(Debug::LOCALE, "Attempting to set locale to: " + << fromqstr(default_locale.name())); QLocale::setDefault(default_locale); // install translation file for Qt built-in dialogs Index: src/frontends/qt4/GuiPrefs.cpp =================================================================== --- src/frontends/qt4/GuiPrefs.cpp (Revision 28169) +++ src/frontends/qt4/GuiPrefs.cpp (Arbeitskopie) @@ -34,6 +34,7 @@ #include "paper.h" #include "Session.h" +#include "support/convert.h" #include "support/debug.h" #include "support/FileName.h" #include "support/filetools.h" @@ -55,6 +56,7 @@ #include <QFontDatabase> #include <QHeaderView> #include <QLineEdit> +#include <QLocale> #include <QMessageBox> #include <QPixmapCache> #include <QPushButton> @@ -667,16 +669,26 @@ rc.zoom = screenZoomSB->value(); rc.dpi = screenDpiSB->value(); - rc.font_sizes[FONT_SIZE_TINY] = fromqstr(screenTinyED->text()); - rc.font_sizes[FONT_SIZE_SCRIPT] = fromqstr(screenSmallestED->text()); - rc.font_sizes[FONT_SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text()); - rc.font_sizes[FONT_SIZE_SMALL] = fromqstr(screenSmallED->text()); - rc.font_sizes[FONT_SIZE_NORMAL] = fromqstr(screenNormalED->text()); - rc.font_sizes[FONT_SIZE_LARGE] = fromqstr(screenLargeED->text()); - rc.font_sizes[FONT_SIZE_LARGER] = fromqstr(screenLargerED->text()); - rc.font_sizes[FONT_SIZE_LARGEST] = fromqstr(screenLargestED->text()); - rc.font_sizes[FONT_SIZE_HUGE] = fromqstr(screenHugeED->text()); - rc.font_sizes[FONT_SIZE_HUGER] = fromqstr(screenHugerED->text()); + rc.font_sizes[FONT_SIZE_TINY] = + convert<string>(screenTinyED->text().trimmed().toDouble()); + rc.font_sizes[FONT_SIZE_SCRIPT] = + convert<string>(screenSmallestED->text().trimmed().toDouble()); + rc.font_sizes[FONT_SIZE_FOOTNOTE] = + convert<string>(screenSmallerED->text().trimmed().toDouble()); + rc.font_sizes[FONT_SIZE_SMALL] = + convert<string>(screenSmallED->text().trimmed().toDouble()); + rc.font_sizes[FONT_SIZE_NORMAL] = + convert<string>(screenNormalED->text().trimmed().toDouble()); + rc.font_sizes[FONT_SIZE_LARGE] = + convert<string>(screenLargeED->text().trimmed().toDouble()); + rc.font_sizes[FONT_SIZE_LARGER] = + convert<string>(screenLargerED->text().trimmed().toDouble()); + rc.font_sizes[FONT_SIZE_LARGEST] = + convert<string>(screenLargestED->text().trimmed().toDouble()); + rc.font_sizes[FONT_SIZE_HUGE] = + convert<string>(screenHugeED->text().trimmed().toDouble()); + rc.font_sizes[FONT_SIZE_HUGER] = + convert<string>(screenHugerED->text().trimmed().toDouble()); rc.use_pixmap_cache = pixmapCacheCB->isChecked(); if (rc.font_sizes != oldrc.font_sizes @@ -709,16 +721,27 @@ screenZoomSB->setValue(rc.zoom); screenDpiSB->setValue(rc.dpi); - screenTinyED->setText(toqstr(rc.font_sizes[FONT_SIZE_TINY])); - screenSmallestED->setText(toqstr(rc.font_sizes[FONT_SIZE_SCRIPT])); - screenSmallerED->setText(toqstr(rc.font_sizes[FONT_SIZE_FOOTNOTE])); - screenSmallED->setText(toqstr(rc.font_sizes[FONT_SIZE_SMALL])); - screenNormalED->setText(toqstr(rc.font_sizes[FONT_SIZE_NORMAL])); - screenLargeED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGE])); - screenLargerED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGER])); - screenLargestED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGEST])); - screenHugeED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGE])); - screenHugerED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGER])); + QLocale loc; + screenTinyED->setText( + loc.toString(convert<double>(rc.font_sizes[FONT_SIZE_TINY]))); + screenSmallestED->setText( + loc.toString(convert<double>(rc.font_sizes[FONT_SIZE_SCRIPT]))); + screenSmallerED->setText( + loc.toString(convert<double>(rc.font_sizes[FONT_SIZE_FOOTNOTE]))); + screenSmallED->setText( + loc.toString(convert<double>(rc.font_sizes[FONT_SIZE_SMALL]))); + screenNormalED->setText( + loc.toString(convert<double>(rc.font_sizes[FONT_SIZE_NORMAL]))); + screenLargeED->setText( + loc.toString(convert<double>(rc.font_sizes[FONT_SIZE_LARGE]))); + screenLargerED->setText( + loc.toString(convert<double>(rc.font_sizes[FONT_SIZE_LARGER]))); + screenLargestED->setText( + loc.toString(convert<double>(rc.font_sizes[FONT_SIZE_LARGEST]))); + screenHugeED->setText( + loc.toString(convert<double>(rc.font_sizes[FONT_SIZE_HUGE]))); + screenHugerED->setText( + loc.toString(convert<double>(rc.font_sizes[FONT_SIZE_HUGER]))); pixmapCacheCB->setChecked(rc.use_pixmap_cache); #if defined(Q_WS_X11) Index: src/frontends/qt4/Validator.cpp =================================================================== --- src/frontends/qt4/Validator.cpp (Revision 28169) +++ src/frontends/qt4/Validator.cpp (Arbeitskopie) @@ -24,6 +24,7 @@ #include "support/lstrings.h" #include <QLineEdit> +#include <QLocale> #include <QWidget> using namespace std; @@ -39,10 +40,13 @@ QValidator::State LengthValidator::validate(QString & qtext, int &) const { - string const text = fromqstr(qtext); - if (text.empty() || support::isStrDbl(text)) + bool ok; + double d = qtext.trimmed().toDouble(&ok); + if (qtext.isEmpty() || ok) return QValidator::Acceptable; + string const text = fromqstr(qtext); + if (glue_length_) { GlueLength gl; return (isValidGlueLength(text, &gl)) ?