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:
Simran
2021-04-13 00:58:46 +02:00
committed by GitHub
parent c03c197412
commit fca485bd69
10 changed files with 58 additions and 4759 deletions
@@ -69,7 +69,7 @@ PreferencesDiskTab::PreferencesDiskTab()
cache_behavior_layout->addWidget(new QLabel(tr("Cache Ahead:")), row, 0);
cache_ahead_slider_ = new FloatSlider();
cache_ahead_slider_->SetFormat(tr("%1 second(s)"));
cache_ahead_slider_->SetFormat(tr("%1 seconds"));
cache_ahead_slider_->SetMinimum(0);
cache_ahead_slider_->SetValue(Config::Current()["DiskCacheAhead"].value<rational>().toDouble());
cache_behavior_layout->addWidget(cache_ahead_slider_, row, 1);
@@ -78,7 +78,7 @@ PreferencesDiskTab::PreferencesDiskTab()
cache_behind_slider_ = new FloatSlider();
cache_behind_slider_->SetMinimum(0);
cache_behind_slider_->SetFormat(tr("%1 second(s)"));
cache_behind_slider_->SetFormat(tr("%1 seconds"));
cache_behind_slider_->SetValue(Config::Current()["DiskCacheBehind"].value<rational>().toDouble());
cache_behavior_layout->addWidget(cache_behind_slider_, row, 3);
@@ -103,7 +103,7 @@ PreferencesGeneralTab::PreferencesGeneralTab()
default_still_length_ = new FloatSlider();
default_still_length_->SetMinimum(0.1);
default_still_length_->SetFormat(tr("%1 second(s)"));
default_still_length_->SetFormat(tr("%1 seconds"));
default_still_length_->SetValue(Config::Current()["DefaultStillLength"].value<rational>().toDouble());
timeline_layout->addWidget(default_still_length_);
@@ -136,7 +136,7 @@ PreferencesGeneralTab::PreferencesGeneralTab()
autorecovery_interval_ = new IntegerSlider();
autorecovery_interval_->SetMinimum(1);
autorecovery_interval_->SetMaximum(60);
autorecovery_interval_->SetFormat(tr("%1 minute(s)"));
autorecovery_interval_->SetFormat(QT_TRANSLATE_N_NOOP("olive::SliderBase", "%n minute(s)"), true);
autorecovery_interval_->SetValue(Config::Current()[QStringLiteral("AutorecoveryInterval")].toLongLong());
autorecovery_layout->addWidget(autorecovery_interval_, row, 1);
+3 -4
View File
@@ -295,10 +295,9 @@ QString Footage::DescribeVideoStream(const VideoParams &params)
QString Footage::DescribeAudioStream(const AudioParams &params)
{
return tr("%1: Audio - %2 Channel(s), %3Hz")
.arg(QString::number(params.stream_index()),
QString::number(params.channel_count()),
QString::number(params.sample_rate()));
return tr("%1: Audio - %n Channel(s), %2Hz", nullptr, params.channel_count())
.arg(QString::number(params.stream_index()),
QString::number(params.sample_rate()));
}
void Footage::Hash(const QString& output, QCryptographicHash &hash, const rational &time) const
+1 -1
View File
@@ -41,7 +41,7 @@ ProjectImportTask::ProjectImportTask(ProjectViewModel *model, Folder *folder, co
file_count_ = Core::CountFilesInFileList(filenames_);
SetTitle(tr("Importing %1 file(s)").arg(file_count_));
SetTitle(tr("Importing %n file(s)", nullptr, file_count_));
}
const int &ProjectImportTask::GetFileCount() const
+32 -4745
View File
File diff suppressed because it is too large Load Diff
@@ -53,7 +53,7 @@ void NodeParamViewArrayWidget::UpdateCounter(const QString& input, int old_size,
{
Q_UNUSED(old_size)
if (input == input_) {
count_lbl_->setText(tr("%1 element(s)").arg(new_size));
count_lbl_->setText(tr("%n element(s)", nullptr, new_size));
}
}
@@ -376,7 +376,7 @@ void NodeParamViewItemBody::Retranslate()
if (ic.IsArray() && ic.element() >= 0) {
// Make the label the array index
i.value().main_label->setText(tr("%n:", nullptr, ic.element()));
i.value().main_label->setText(tr("%1:").arg(ic.element()));
} else {
// Set to the input's name
i.value().main_label->setText(tr("%1:").arg(ic.name()));
+10 -1
View File
@@ -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)));
}
+5 -1
View File
@@ -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_;
+1 -1
View File
@@ -71,7 +71,7 @@ void MainStatusBar::UpdateStatus()
if (manager_->GetTaskCount() == 1) {
showMessage(t->GetTitle());
} else {
showMessage(tr("Running %1 background task(s)").arg(manager_->GetTaskCount()));
showMessage(tr("Running %n background task(s)", nullptr, manager_->GetTaskCount()));
}
bar_->setVisible(true);