Support other locales for decimal and list separators (#1060)

* Support other locales for decimal and list seperators

* PR fixes
This commit is contained in:
Pepe Rivera 2020-03-04 15:15:18 -08:00 committed by GitHub
parent 880072016f
commit f1d53fba61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 43 additions and 6 deletions

View File

@ -74,6 +74,8 @@ GraphingCalculator::GraphingCalculator()
// Update where the pointer value is (ie: where the user cursor from keyboard inputs moves the point to) // Update where the pointer value is (ie: where the user cursor from keyboard inputs moves the point to)
GraphingControl->PointerValueChangedEvent += ref new PointerValueChangedEventHandler(this, &GraphingCalculator::OnPointerPointChanged); GraphingControl->PointerValueChangedEvent += ref new PointerValueChangedEventHandler(this, &GraphingCalculator::OnPointerPointChanged);
GraphingControl->UseCommaDecimalSeperator = LocalizationSettings::GetInstance().GetDecimalSeparator() == ',';
// OemMinus and OemAdd aren't declared in the VirtualKey enum, we can't add this accelerator XAML-side // OemMinus and OemAdd aren't declared in the VirtualKey enum, we can't add this accelerator XAML-side
auto virtualKey = ref new KeyboardAccelerator(); auto virtualKey = ref new KeyboardAccelerator();
virtualKey->Key = (VirtualKey)189; // OemPlus key virtualKey->Key = (VirtualKey)189; // OemPlus key

View File

@ -9,6 +9,7 @@
#include "Controls/MathRichEditBox.h" #include "Controls/MathRichEditBox.h"
using namespace CalculatorApp; using namespace CalculatorApp;
using namespace CalculatorApp::Common;
using namespace Platform; using namespace Platform;
using namespace Windows::Foundation; using namespace Windows::Foundation;
@ -60,9 +61,9 @@ static const std::unordered_map<NumbersAndOperatorsEnum, std::tuple<Platform::St
{ NumbersAndOperatorsEnum::LogBaseE, { L"ln()", 3, 0 } }, { NumbersAndOperatorsEnum::LogBaseE, { L"ln()", 3, 0 } },
{ NumbersAndOperatorsEnum::Sqrt, { L"sqrt()", 5, 0 } }, { NumbersAndOperatorsEnum::Sqrt, { L"sqrt()", 5, 0 } },
{ NumbersAndOperatorsEnum::CubeRoot, { L"cbrt()", 5, 0 } }, { NumbersAndOperatorsEnum::CubeRoot, { L"cbrt()", 5, 0 } },
{ NumbersAndOperatorsEnum::YRootX, { L"root(x,n)", 7, 1 } }, { NumbersAndOperatorsEnum::YRootX, { L"root(x" + StringReference(LocalizationSettings::GetInstance().GetListSeparator().data()) + L"n)", 7, 1 } },
{ NumbersAndOperatorsEnum::TwoPowerX, { L"2^", 2, 0 } }, { NumbersAndOperatorsEnum::TwoPowerX, { L"2^", 2, 0 } },
{ NumbersAndOperatorsEnum::LogBaseX, { L"log(b, x)", 4, 1 } }, { NumbersAndOperatorsEnum::LogBaseX, { "log(b" + StringReference(LocalizationSettings::GetInstance().GetListSeparator().data()) + L" x)", 4, 1 } },
{ NumbersAndOperatorsEnum::EPowerX, { L"e^", 4, 0 } }, { NumbersAndOperatorsEnum::EPowerX, { L"e^", 4, 0 } },
{ NumbersAndOperatorsEnum::Abs, { L"abs()", 4, 0 } }, { NumbersAndOperatorsEnum::Abs, { L"abs()", 4, 0 } },
{ NumbersAndOperatorsEnum::X, { L"x", 1, 0 } }, { NumbersAndOperatorsEnum::X, { L"x", 1, 0 } },
@ -90,13 +91,13 @@ static const std::unordered_map<NumbersAndOperatorsEnum, std::tuple<Platform::St
{ NumbersAndOperatorsEnum::Seven, { L"7", 1, 0 } }, { NumbersAndOperatorsEnum::Seven, { L"7", 1, 0 } },
{ NumbersAndOperatorsEnum::Eight, { L"8", 1, 0 } }, { NumbersAndOperatorsEnum::Eight, { L"8", 1, 0 } },
{ NumbersAndOperatorsEnum::Nine, { L"9", 1, 0 } }, { NumbersAndOperatorsEnum::Nine, { L"9", 1, 0 } },
{ NumbersAndOperatorsEnum::Decimal, { L".", 1, 0 } }, { NumbersAndOperatorsEnum::Decimal, { StringReference(LocalizationSettings::GetInstance().GetDecimalSeparatorStr().data()), 1, 0 } },
}; };
GraphingNumPad::GraphingNumPad() GraphingNumPad::GraphingNumPad()
{ {
InitializeComponent(); InitializeComponent();
const auto& localizationSettings = CalculatorApp::Common::LocalizationSettings::GetInstance(); const auto& localizationSettings = LocalizationSettings::GetInstance();
DecimalSeparatorButton->Content = localizationSettings.GetDecimalSeparator(); DecimalSeparatorButton->Content = localizationSettings.GetDecimalSeparator();
Num0Button->Content = localizationSettings.GetDigitSymbolFromEnUsDigit('0'); Num0Button->Content = localizationSettings.GetDigitSymbolFromEnUsDigit('0');
Num1Button->Content = localizationSettings.GetDigitSymbolFromEnUsDigit('1'); Num1Button->Content = localizationSettings.GetDigitSymbolFromEnUsDigit('1');

View File

@ -29,6 +29,7 @@ using namespace Windows::UI::Xaml::Media;
using namespace GraphControl; using namespace GraphControl;
DEPENDENCY_PROPERTY_INITIALIZATION(Grapher, ForceProportionalAxes); DEPENDENCY_PROPERTY_INITIALIZATION(Grapher, ForceProportionalAxes);
DEPENDENCY_PROPERTY_INITIALIZATION(Grapher, UseCommaDecimalSeperator);
DEPENDENCY_PROPERTY_INITIALIZATION(Grapher, Variables); DEPENDENCY_PROPERTY_INITIALIZATION(Grapher, Variables);
DEPENDENCY_PROPERTY_INITIALIZATION(Grapher, Equations); DEPENDENCY_PROPERTY_INITIALIZATION(Grapher, Equations);
DEPENDENCY_PROPERTY_INITIALIZATION(Grapher, AxesColor); DEPENDENCY_PROPERTY_INITIALIZATION(Grapher, AxesColor);
@ -278,9 +279,16 @@ namespace GraphControl
} }
if (numValidEquations++ > 0) if (numValidEquations++ > 0)
{
if (!UseCommaDecimalSeperator)
{ {
request += L"<mo>,</mo>"; request += L"<mo>,</mo>";
} }
else
{
request += L"<mo>;</mo>";
}
}
auto equationRequest = eq->GetRequest()->Data(); auto equationRequest = eq->GetRequest()->Data();
// If the equation request failed, then fail graphing. // If the equation request failed, then fail graphing.
@ -511,6 +519,20 @@ namespace GraphControl
TryUpdateGraph(false); TryUpdateGraph(false);
} }
void Grapher::OnUseCommaDecimalSeperatorPropertyChanged(bool oldValue, bool newValue)
{
if (newValue)
{
m_solver->ParsingOptions().SetLocalizationType(::LocalizationType::DecimalCommaAndListSemicolon);
m_solver->FormatOptions().SetLocalizationType(::LocalizationType::DecimalCommaAndListSemicolon);
}
else
{
m_solver->ParsingOptions().SetLocalizationType(::LocalizationType::DecimalPointAndListComma);
m_solver->FormatOptions().SetLocalizationType(::LocalizationType::DecimalPointAndListComma);
}
}
void Grapher::OnPointerEntered(PointerRoutedEventArgs ^ e) void Grapher::OnPointerEntered(PointerRoutedEventArgs ^ e)
{ {
if (m_renderMain) if (m_renderMain)

View File

@ -38,6 +38,7 @@ public
DEPENDENCY_PROPERTY_OWNER(Grapher); DEPENDENCY_PROPERTY_OWNER(Grapher);
DEPENDENCY_PROPERTY_WITH_DEFAULT_AND_CALLBACK(bool, ForceProportionalAxes, true); DEPENDENCY_PROPERTY_WITH_DEFAULT_AND_CALLBACK(bool, ForceProportionalAxes, true);
DEPENDENCY_PROPERTY_WITH_DEFAULT_AND_CALLBACK(bool, UseCommaDecimalSeperator, false);
DEPENDENCY_PROPERTY_WITH_DEFAULT( DEPENDENCY_PROPERTY_WITH_DEFAULT(
SINGLE_ARG(Windows::Foundation::Collections::IObservableMap<Platform::String ^, double> ^), SINGLE_ARG(Windows::Foundation::Collections::IObservableMap<Platform::String ^, double> ^),
Variables, Variables,
@ -266,6 +267,7 @@ public
private: private:
void OnForceProportionalAxesPropertyChanged(bool oldValue, bool newValue); void OnForceProportionalAxesPropertyChanged(bool oldValue, bool newValue);
void OnUseCommaDecimalSeperatorPropertyChanged(bool oldValue, bool newValue);
void OnEquationsPropertyChanged(EquationCollection ^ oldValue, EquationCollection ^ newValue); void OnEquationsPropertyChanged(EquationCollection ^ oldValue, EquationCollection ^ newValue);
void OnAxesColorPropertyChanged(Windows::UI::Color oldValue, Windows::UI::Color newValue); void OnAxesColorPropertyChanged(Windows::UI::Color oldValue, Windows::UI::Color newValue);
void OnGraphBackgroundPropertyChanged(Windows::UI::Color oldValue, Windows::UI::Color newValue); void OnGraphBackgroundPropertyChanged(Windows::UI::Color oldValue, Windows::UI::Color newValue);

View File

@ -13,6 +13,10 @@ namespace MockGraphingImpl
void SetFormatType(Graphing::FormatType type) override void SetFormatType(Graphing::FormatType type) override
{ {
} }
void SetLocalizationType(Graphing::LocalizationType value) override
{
}
}; };
class EvalOptions : public Graphing::IEvalOptions class EvalOptions : public Graphing::IEvalOptions
@ -46,6 +50,10 @@ namespace MockGraphingImpl
void SetMathMLPrefix(const std::wstring& value) override void SetMathMLPrefix(const std::wstring& value) override
{ {
} }
void SetLocalizationType(Graphing::LocalizationType value) override
{
}
}; };
class MockExpression : public Graphing::IExpression class MockExpression : public Graphing::IExpression

View File

@ -34,6 +34,7 @@ namespace Graphing
virtual ~IParsingOptions() = default; virtual ~IParsingOptions() = default;
virtual void SetFormatType(FormatType type) = 0; virtual void SetFormatType(FormatType type) = 0;
virtual void SetLocalizationType(LocalizationType value) = 0;
}; };
struct IEvalOptions : public NonCopyable, public NonMoveable struct IEvalOptions : public NonCopyable, public NonMoveable
@ -50,6 +51,7 @@ namespace Graphing
virtual void SetFormatType(FormatType type) = 0; virtual void SetFormatType(FormatType type) = 0;
virtual void SetMathMLPrefix(const std::wstring& value) = 0; virtual void SetMathMLPrefix(const std::wstring& value) = 0;
virtual void SetLocalizationType(LocalizationType value) = 0;
}; };
struct IMathSolver : public NonCopyable, public NonMoveable struct IMathSolver : public NonCopyable, public NonMoveable