Localize the default decimal separator

Do not blindly use (English) "." as default, but the locale default of
the current context language.

Fixes: #7204
This commit is contained in:
Juergen Spitzmueller 2019-07-22 08:05:28 +02:00
parent 2b41bf22a9
commit b852df91bc
10 changed files with 129 additions and 57 deletions

View File

@ -25,8 +25,12 @@
#include "support/filetools.h"
#include "support/lassert.h"
#include "support/lstrings.h"
#include "support/qstring_helpers.h"
#include "support/Messages.h"
#include <QLocale>
#include <QString>
using namespace std;
using namespace lyx::support;
@ -111,6 +115,16 @@ string Language::dateFormat(size_t i) const
}
docstring Language::decimalSeparator() const
{
if (lyxrc.default_decimal_sep == "locale") {
QLocale loc = QLocale(toqstr(code()));
return qstring_to_ucs4(QString(loc.decimalPoint()));
}
return from_utf8(lyxrc.default_decimal_sep);
}
bool Language::readLanguage(Lexer & lex)
{
enum LanguageTags {

View File

@ -91,6 +91,8 @@ public:
std::string fontenc(BufferParams const &) const;
/// Return the localized date formats (long, medium, short format)
std::string dateFormat(size_t i) const;
/// Return the localized decimal separator
docstring decimalSeparator() const;
/// This language corresponds to a translation of the GUI
bool hasGuiSupport() const { return has_gui_support_; }
///

View File

@ -95,7 +95,7 @@ LexerKeyword lyxrcTags[] = {
{ "\\cursor_follows_scrollbar", LyXRC::RC_CURSOR_FOLLOWS_SCROLLBAR },
{ "\\cursor_width", LyXRC::RC_CURSOR_WIDTH },
{ "\\def_file", LyXRC::RC_DEFFILE },
{ "\\default_decimal_point", LyXRC::RC_DEFAULT_DECIMAL_POINT },
{ "\\default_decimal_point", LyXRC::RC_DEFAULT_DECIMAL_SEP },
{ "\\default_length_unit", LyXRC::RC_DEFAULT_LENGTH_UNIT },
{ "\\default_otf_view_format", LyXRC::RC_DEFAULT_OTF_VIEW_FORMAT },
{ "\\default_platex_view_format", LyXRC::RC_DEFAULT_PLATEX_VIEW_FORMAT },
@ -752,8 +752,8 @@ LyXRC::ReturnValues LyXRC::read(Lexer & lexrc, bool check_format)
if (lexrc.next())
backupdir_path = os::internal_path(lexrc.getString());
break;
case RC_DEFAULT_DECIMAL_POINT:
lexrc >> default_decimal_point;
case RC_DEFAULT_DECIMAL_SEP:
lexrc >> default_decimal_sep;
break;
case RC_DEFAULT_LENGTH_UNIT:
if (lexrc.next())
@ -2267,10 +2267,10 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
<< "#\n\n";
// fall through
case RC_DEFAULT_DECIMAL_POINT:
case RC_DEFAULT_DECIMAL_SEP:
if (ignore_system_lyxrc ||
default_decimal_point != system_lyxrc.default_decimal_point) {
os << "\\default_decimal_point " << default_decimal_point << '\n';
default_decimal_sep != system_lyxrc.default_decimal_sep) {
os << "\\default_decimal_point \"" << default_decimal_sep << "\"" << '\n';
}
if (tag != RC_LAST)
break;
@ -2892,7 +2892,7 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
case LyXRC::RC_FORWARD_SEARCH_DVI:
case LyXRC::RC_FORWARD_SEARCH_PDF:
case LyXRC::RC_EXPORT_OVERWRITE:
case LyXRC::RC_DEFAULT_DECIMAL_POINT:
case LyXRC::RC_DEFAULT_DECIMAL_SEP:
case LyXRC::RC_DEFAULT_LENGTH_UNIT:
case LyXRC::RC_SCROLL_WHEEL_ZOOM:
case LyXRC::RC_CURSOR_WIDTH:

View File

@ -68,7 +68,7 @@ public:
RC_COPIER,
RC_CURSOR_FOLLOWS_SCROLLBAR,
RC_CURSOR_WIDTH,
RC_DEFAULT_DECIMAL_POINT,
RC_DEFAULT_DECIMAL_SEP,
RC_DEFAULT_LENGTH_UNIT,
RC_DEFAULT_OTF_VIEW_FORMAT,
RC_DEFAULT_PLATEX_VIEW_FORMAT,
@ -525,7 +525,7 @@ public:
///
int export_overwrite = NO_FILES;
/// Default decimal point when aligning table columns on decimal
std::string default_decimal_point = ".";
std::string default_decimal_sep = "locale";
///
Length::UNIT default_length_unit = Length::CM;
///

View File

@ -2412,7 +2412,9 @@ PrefLanguage::PrefLanguage(GuiPreferences * form)
this, SIGNAL(changed()));
connect(uiLanguageCO, SIGNAL(activated(int)),
this, SIGNAL(changed()));
connect(defaultDecimalPointLE, SIGNAL(textChanged(QString)),
connect(defaultDecimalSepED, SIGNAL(textChanged(QString)),
this, SIGNAL(changed()));
connect(defaultDecimalSepCO, SIGNAL(activated(int)),
this, SIGNAL(changed()));
connect(defaultLengthUnitCO, SIGNAL(activated(int)),
this, SIGNAL(changed()));
@ -2421,8 +2423,8 @@ PrefLanguage::PrefLanguage(GuiPreferences * form)
startCommandED->setValidator(new NoNewLineValidator(startCommandED));
endCommandED->setValidator(new NoNewLineValidator(endCommandED));
defaultDecimalPointLE->setInputMask("X; ");
defaultDecimalPointLE->setMaxLength(1);
defaultDecimalSepED->setInputMask("X; ");
defaultDecimalSepED->setMaxLength(1);
defaultLengthUnitCO->addItem(lyx::qt_(unit_name_gui[Length::CM]), Length::CM);
defaultLengthUnitCO->addItem(lyx::qt_(unit_name_gui[Length::IN]), Length::IN);
@ -2473,6 +2475,12 @@ void PrefLanguage::on_languagePackageCO_currentIndexChanged(int i)
}
void PrefLanguage::on_defaultDecimalSepCO_currentIndexChanged(int i)
{
defaultDecimalSepED->setEnabled(i == 1);
}
void PrefLanguage::applyRC(LyXRC & rc) const
{
rc.visual_cursor = visualCursorRB->isChecked();
@ -2495,7 +2503,10 @@ void PrefLanguage::applyRC(LyXRC & rc) const
rc.language_command_end = fromqstr(endCommandED->text());
rc.gui_language = fromqstr(
uiLanguageCO->itemData(uiLanguageCO->currentIndex()).toString());
rc.default_decimal_point = fromqstr(defaultDecimalPointLE->text());
if (defaultDecimalSepCO->currentIndex() == 0)
rc.default_decimal_sep = "locale";
else
rc.default_decimal_sep = fromqstr(defaultDecimalSepED->text());
rc.default_length_unit = (Length::UNIT) defaultLengthUnitCO->itemData(defaultLengthUnitCO->currentIndex()).toInt();
}
@ -2519,10 +2530,17 @@ void PrefLanguage::updateRC(LyXRC const & rc)
save_langpack_ = toqstr(rc.language_custom_package);
languagePackageED->setEnabled(false);
}
defaultDecimalSepED->setEnabled(defaultDecimalSepCO->currentIndex() == 1);
globalCB->setChecked(rc.language_global_options);
startCommandED->setText(toqstr(rc.language_command_begin));
endCommandED->setText(toqstr(rc.language_command_end));
defaultDecimalPointLE->setText(toqstr(rc.default_decimal_point));
if (rc.default_decimal_sep == "locale") {
defaultDecimalSepCO->setCurrentIndex(0);
defaultDecimalSepED->clear();
} else {
defaultDecimalSepCO->setCurrentIndex(1);
defaultDecimalSepED->setText(toqstr(rc.default_decimal_sep));
}
int pos = defaultLengthUnitCO->findData(int(rc.default_length_unit));
defaultLengthUnitCO->setCurrentIndex(pos);

View File

@ -408,6 +408,7 @@ public:
private Q_SLOTS:
void on_uiLanguageCO_currentIndexChanged(int);
void on_languagePackageCO_currentIndexChanged(int);
void on_defaultDecimalSepCO_currentIndexChanged(int);
private:
///
QString save_langpack_;

View File

@ -22,10 +22,12 @@
#include "qt_helpers.h"
#include "Validator.h"
#include "Buffer.h"
#include "BufferView.h"
#include "Cursor.h"
#include "FuncRequest.h"
#include "FuncStatus.h"
#include "Language.h"
#include "LyX.h"
#include "LyXRC.h"
@ -550,10 +552,10 @@ docstring GuiTabular::dialogToParams() const
setHAlign(param_str);
// SET_DECIMAL_POINT must come after setHAlign() (ALIGN_DECIMAL)
string decimal_point = fromqstr(decimalPointED->text());
if (decimal_point.empty())
decimal_point = lyxrc.default_decimal_point;
setParam(param_str, Tabular::SET_DECIMAL_POINT, decimal_point);
string decimal_sep = fromqstr(decimalPointED->text());
if (decimal_sep.empty())
decimal_sep = to_utf8(decimal_sep_);
setParam(param_str, Tabular::SET_DECIMAL_POINT, decimal_sep);
setVAlign(param_str);
setTableAlignment(param_str);
@ -1053,10 +1055,12 @@ void GuiTabular::paramsToDialog(Inset const * inset)
hAlignCO->setCurrentIndex(hAlignCO->findData(toqstr(align)));
//
QString decimal_point = toqstr(tabular.column_info[col].decimal_point);
if (decimal_point.isEmpty())
decimal_point = toqstr(from_utf8(lyxrc.default_decimal_point));
decimalPointED->setText(decimal_point);
decimal_sep_ = tabular.column_info[col].decimal_point;
if (decimal_sep_.empty()) {
Language const * lang = itab->buffer().paragraphs().front().getParLanguage(itab->buffer().params());
decimal_sep_ = lang->decimalSeparator();
}
decimalPointED->setText(toqstr(decimal_sep_));
int valign = 0;
switch (tabular.getVAlignment(cell)) {

View File

@ -76,6 +76,8 @@ private:
GuiSetBorder::BorderState orig_rightborder_;
///
int lastrow_;
///
docstring decimal_sep_;
};
} // namespace frontend

View File

@ -282,44 +282,18 @@
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="decimalPointL">
<property name="toolTip">
<string>Here you can specify the decimal separator that is used in the tabular dialog by default. &quot;Language default&quot; selects the appropriate separator for the current language.</string>
</property>
<property name="text">
<string>Default decimal &amp;separator:</string>
</property>
<property name="buddy">
<cstring>defaultDecimalPointLE</cstring>
<cstring>defaultDecimalSepED</cstring>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="defaultLengthUnitLA">
<property name="text">
<string>Default length &amp;unit:</string>
</property>
<property name="buddy">
<cstring>defaultLengthUnitCO</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="defaultDecimalPointLE">
<property name="maximumSize">
<size>
<width>20</width>
<height>16777215</height>
</size>
</property>
<property name="inputMask">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="defaultLengthUnitCO"/>
</item>
<item row="1" column="2">
<item row="1" column="6">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -332,6 +306,62 @@
</property>
</spacer>
</item>
<item row="0" column="3">
<widget class="QLineEdit" name="defaultDecimalSepED">
<property name="maximumSize">
<size>
<width>40</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Insert a custom decimal separator here</string>
</property>
<property name="inputMask">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="defaultLengthUnitLA">
<property name="toolTip">
<string>Select the default length unit for LyX dialogs</string>
</property>
<property name="text">
<string>Default length &amp;unit:</string>
</property>
<property name="buddy">
<cstring>defaultLengthUnitCO</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="defaultDecimalSepCO">
<property name="toolTip">
<string>Here you can specify the decimal separator that is used in the tabular dialog by default. &quot;Language default&quot; selects the appropriate separator for the current language.</string>
</property>
<item>
<property name="text">
<string>Language Default</string>
</property>
</item>
<item>
<property name="text">
<string>Custom</string>
</property>
</item>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="defaultLengthUnitCO">
<property name="toolTip">
<string>Select the default length unit for LyX dialogs</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@ -359,8 +389,7 @@
<tabstop>languagePackageED</tabstop>
<tabstop>startCommandED</tabstop>
<tabstop>endCommandED</tabstop>
<tabstop>defaultDecimalPointLE</tabstop>
<tabstop>defaultLengthUnitCO</tabstop>
<tabstop>defaultDecimalSepED</tabstop>
<tabstop>globalCB</tabstop>
<tabstop>explicitDocLangBeginCB</tabstop>
<tabstop>markForeignCB</tabstop>

View File

@ -1210,8 +1210,10 @@ void Tabular::setAlignment(idx_type cell, LyXAlignment align,
}
column_info[col].alignment = align;
docstring & dpoint = column_info[col].decimal_point;
if (align == LYX_ALIGN_DECIMAL && dpoint.empty())
dpoint = from_utf8(lyxrc.default_decimal_point);
if (align == LYX_ALIGN_DECIMAL && dpoint.empty()) {
Language const * tlang = buffer().paragraphs().front().getParLanguage(buffer().params());
dpoint = tlang->decimalSeparator();
}
} else {
cellInfo(cell).alignment = align;
cellInset(cell)->setContentAlignment(align);