Fix plural handling for translations (#1424)
* .arg() doesn't handle plurals, replace %1 with %n and pass number to tr(), but only if there is an accompanying word for that we want singular/plural translations and only for whole numbers.
* Qt's translation methods only accept integers and we don't know what grammatical number form would be correct for floating-point numbers in different languages anyway.
* Add optional 2nd argument to SliderBase::SetFormat() to activate deferred plural handling:
SetFormat(QT_TRANSLATE_N_NOOP("olive::SliderBase", "%n unit(s)"), true)
* Generate en_US.ts with lupdate's -pluralonly option. Only source strings that require plural handling need to be translated (as long as the source language is American English).
This commit is contained in:
@@ -39,6 +39,7 @@ SliderBase::SliderBase(Mode mode, QWidget *parent) :
|
||||
dragged_diff_(0),
|
||||
require_valid_input_(true),
|
||||
tristate_(false),
|
||||
format_plural_(false),
|
||||
drag_ladder_(nullptr),
|
||||
ladder_element_count_(0),
|
||||
dragged_(false)
|
||||
@@ -101,9 +102,10 @@ bool SliderBase::IsDragging() const
|
||||
return drag_ladder_;
|
||||
}
|
||||
|
||||
void SliderBase::SetFormat(const QString &s)
|
||||
void SliderBase::SetFormat(const QString &s, const bool plural)
|
||||
{
|
||||
custom_format_ = s;
|
||||
format_plural_ = plural;
|
||||
ForceLabelUpdate();
|
||||
}
|
||||
|
||||
@@ -113,6 +115,11 @@ void SliderBase::ClearFormat()
|
||||
ForceLabelUpdate();
|
||||
}
|
||||
|
||||
bool SliderBase::IsFormatPlural() const
|
||||
{
|
||||
return format_plural_;
|
||||
}
|
||||
|
||||
void SliderBase::ForceLabelUpdate()
|
||||
{
|
||||
UpdateLabel(Value());
|
||||
@@ -209,6 +216,8 @@ void SliderBase::UpdateLabel(const QVariant &v)
|
||||
{
|
||||
if (tristate_) {
|
||||
label_->setText("---");
|
||||
} else if (format_plural_) {
|
||||
label_->setText(tr(GetFormat().toUtf8().constData(), nullptr, v.toInt()));
|
||||
} else {
|
||||
label_->setText(GetFormat().arg(ValueToString(v)));
|
||||
}
|
||||
|
||||
@@ -60,9 +60,11 @@ public:
|
||||
|
||||
bool IsDragging() const;
|
||||
|
||||
void SetFormat(const QString& s);
|
||||
void SetFormat(const QString& s, const bool plural=false);
|
||||
void ClearFormat();
|
||||
|
||||
bool IsFormatPlural() const;
|
||||
|
||||
void SetLadderElementCount(int b)
|
||||
{
|
||||
ladder_element_count_ = b;
|
||||
@@ -127,6 +129,8 @@ private:
|
||||
|
||||
QString custom_format_;
|
||||
|
||||
bool format_plural_;
|
||||
|
||||
SliderLadder* drag_ladder_;
|
||||
|
||||
int ladder_element_count_;
|
||||
|
||||
Reference in New Issue
Block a user