1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-09-19 17:40:51 +02:00

Use TranslatableString in NumericTextCtrl...

... Fixing a minor error in TimerRecordDialog, where translation of format was
done too soon
This commit is contained in:
Paul Licameli 2019-12-01 11:05:29 -05:00
parent b351eabf47
commit 0b6618e491
3 changed files with 19 additions and 17 deletions

View File

@ -811,9 +811,9 @@ void TimerRecordDialog::PopulateOrExchange(ShuttleGui& S)
S.SetBorder(5); S.SetBorder(5);
using Options = NumericTextCtrl::Options; using Options = NumericTextCtrl::Options;
/* i18n-hint a format string for hours, minutes, and seconds */ /* i18n-hint a format string for hours, minutes, and seconds */
auto strFormat = _("099 h 060 m 060 s"); auto strFormat = XO("099 h 060 m 060 s");
/* i18n-hint a format string for days, hours, minutes, and seconds */ /* i18n-hint a format string for days, hours, minutes, and seconds */
auto strFormat1 = _("099 days 024 h 060 m 060 s"); auto strFormat1 = XO("099 days 024 h 060 m 060 s");
S.StartMultiColumn(2, wxCENTER); S.StartMultiColumn(2, wxCENTER);
{ {

View File

@ -285,7 +285,7 @@ private:
struct BuiltinFormatString struct BuiltinFormatString
{ {
NumericFormatSymbol name; NumericFormatSymbol name;
wxString formatStr; TranslatableString formatStr;
friend inline bool operator == friend inline bool operator ==
(const BuiltinFormatString &a, const BuiltinFormatString &b) (const BuiltinFormatString &a, const BuiltinFormatString &b)
@ -706,9 +706,10 @@ NumericConverter::NumericConverter(Type type,
SetValue(value); // mValue got overridden to -1 in ControlsToValue(), reassign SetValue(value); // mValue got overridden to -1 in ControlsToValue(), reassign
} }
void NumericConverter::ParseFormatString( const wxString & untranslatedFormat) void NumericConverter::ParseFormatString(
const TranslatableString & untranslatedFormat)
{ {
auto &format = ::wxGetTranslation( untranslatedFormat ); auto &format = untranslatedFormat.Translation();
mPrefix = wxT(""); mPrefix = wxT("");
mFields.clear(); mFields.clear();
@ -1057,7 +1058,7 @@ bool NumericConverter::SetFormatName(const NumericFormatSymbol & formatName)
SetFormatString(GetBuiltinFormat(formatName)); SetFormatString(GetBuiltinFormat(formatName));
} }
bool NumericConverter::SetFormatString(const wxString & formatString) bool NumericConverter::SetFormatString(const TranslatableString & formatString)
{ {
if (mFormatString != formatString) { if (mFormatString != formatString) {
mFormatString = formatString; mFormatString = formatString;
@ -1149,7 +1150,7 @@ NumericFormatSymbol NumericConverter::GetBuiltinName(const int index)
return {}; return {};
} }
wxString NumericConverter::GetBuiltinFormat(const int index) TranslatableString NumericConverter::GetBuiltinFormat(const int index)
{ {
if (index >= 0 && index < GetNumBuiltins()) if (index >= 0 && index < GetNumBuiltins())
return mBuiltinFormatStrings[index].formatStr; return mBuiltinFormatStrings[index].formatStr;
@ -1157,7 +1158,8 @@ wxString NumericConverter::GetBuiltinFormat(const int index)
return {}; return {};
} }
wxString NumericConverter::GetBuiltinFormat(const NumericFormatSymbol &name) TranslatableString NumericConverter::GetBuiltinFormat(
const NumericFormatSymbol &name)
{ {
int ndx = int ndx =
std::find( mBuiltinFormatStrings, mBuiltinFormatStrings + mNBuiltins, std::find( mBuiltinFormatStrings, mBuiltinFormatStrings + mNBuiltins,
@ -1378,7 +1380,7 @@ bool NumericTextCtrl::SetFormatName(const NumericFormatSymbol & formatName)
SetFormatString(GetBuiltinFormat(formatName)); SetFormatString(GetBuiltinFormat(formatName));
} }
bool NumericTextCtrl::SetFormatString(const wxString & formatString) bool NumericTextCtrl::SetFormatString(const TranslatableString & formatString)
{ {
auto result = auto result =
NumericConverter::SetFormatString(formatString); NumericConverter::SetFormatString(formatString);

View File

@ -79,7 +79,7 @@ public:
virtual void ControlsToValue(); virtual void ControlsToValue();
private: private:
void ParseFormatString(const wxString & untranslatedFormat); void ParseFormatString(const TranslatableString & untranslatedFormat);
public: public:
void PrintDebugInfo(); void PrintDebugInfo();
@ -88,7 +88,7 @@ public:
bool SetFormatName(const NumericFormatSymbol & formatName); bool SetFormatName(const NumericFormatSymbol & formatName);
// returns true iff the format string really changed: // returns true iff the format string really changed:
bool SetFormatString(const wxString & formatString); bool SetFormatString(const TranslatableString & formatString);
void SetSampleRate(double sampleRate); void SetSampleRate(double sampleRate);
void SetValue(double newValue); void SetValue(double newValue);
@ -105,8 +105,8 @@ public:
int GetNumBuiltins(); int GetNumBuiltins();
NumericFormatSymbol GetBuiltinName(const int index); NumericFormatSymbol GetBuiltinName(const int index);
wxString GetBuiltinFormat(const int index); TranslatableString GetBuiltinFormat(const int index);
wxString GetBuiltinFormat(const NumericFormatSymbol & name); TranslatableString GetBuiltinFormat(const NumericFormatSymbol & name);
// Adjust the value by the number "steps" in the active format. // Adjust the value by the number "steps" in the active format.
// Increment if "dir" is 1, decrement if "dir" is -1. // Increment if "dir" is 1, decrement if "dir" is -1.
@ -124,7 +124,7 @@ protected:
double mMaxValue; double mMaxValue;
double mInvalidValue; double mInvalidValue;
wxString mFormatString; TranslatableString mFormatString;
std::vector<NumericField> mFields; std::vector<NumericField> mFields;
wxString mPrefix; wxString mPrefix;
@ -158,7 +158,7 @@ class NumericTextCtrl final : public wxControl, public NumericConverter
bool menuEnabled { true }; bool menuEnabled { true };
bool hasInvalidValue { false }; bool hasInvalidValue { false };
double invalidValue { -1.0 }; double invalidValue { -1.0 };
wxString format {}; TranslatableString format {};
bool hasValue { false }; bool hasValue { false };
double value{ -1.0 }; double value{ -1.0 };
@ -170,7 +170,7 @@ class NumericTextCtrl final : public wxControl, public NumericConverter
Options &InvalidValue (bool has, double v = -1.0) Options &InvalidValue (bool has, double v = -1.0)
{ hasInvalidValue = has, invalidValue = v; return *this; } { hasInvalidValue = has, invalidValue = v; return *this; }
// use a custom format not in the tables: // use a custom format not in the tables:
Options &Format (const wxString &f) Options &Format (const TranslatableString &f)
{ format = f; return *this; } { format = f; return *this; }
Options &Value (bool has, double v) Options &Value (bool has, double v)
{ hasValue = has, value = v; return *this; } { hasValue = has, value = v; return *this; }
@ -194,7 +194,7 @@ class NumericTextCtrl final : public wxControl, public NumericConverter
void SetValue(double newValue); void SetValue(double newValue);
// returns true iff the format string really changed: // returns true iff the format string really changed:
bool SetFormatString(const wxString & formatString); bool SetFormatString(const TranslatableString & formatString);
// returns true iff the format name really changed: // returns true iff the format name really changed:
bool SetFormatName(const NumericFormatSymbol & formatName); bool SetFormatName(const NumericFormatSymbol & formatName);