Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix plural handling for translations #1424

Merged
merged 12 commits into from
Apr 12, 2021
Merged

Conversation

Simran-B
Copy link
Collaborator

@Simran-B Simran-B commented Nov 27, 2020

992b6eb does not fix #1421. The placeholder %n must be used instead of %1, %2 etc. and the value passed to tr() instead of via arg().

In the current state, this PR breaks widgets such as the FloatSlider. When entering a new value or dragging it, the label does not update. There are also QString::arg warnings, because a former placeholder such as %1 no longer exists (replaced by %n). It will require some refactoring to properly update the UI I'm afraid, but I couldn't figure out how so far.

This PR also replaces the English translation file with lupdate . -ts app/ts/en_US.ts -pluralonly, which only contains the strings which require plural handling. I added translations for the few strings that do. As long as the source strings are in American English, then we don't need a full translation (unless we want to allow users to change the English UI?!)

TODO:

  • Update Translation Wiki
  • Change build system so that CMake updates en_US.ts with -pluralonly option and document this special case in Wiki.
    -> The logic to conditionally create or add translations got removed here:
    b9724e3#diff-fd99ceeacdfe207bd1168e1c30c94ed9f316895e74154c83258807c703288b3fL272-L276
    qt5_add_translation is called unconditionally for updating .qm files
    qt5_add_translation(OLIVE_QM_FILES ${OLIVE_TS_FILES})

    The UPDATE_TS option does nothing and there is no call to qt5_create_translation anywhere that would update .ts files. So there isn't anything to change to pass -pluralonly...

Obsoletes #1423

.arg() doesn't handle plurals. This change is incomplete, it breaks widgets such as the FloatSlider (label is not updated QString::arg warnings are issued)
Only source strings which require plural handling need to be translated as long as the source language is American English.
@Simran-B Simran-B added the Translation UI languages / internationalization (i18n) label Nov 27, 2020
@prokoudine
Copy link
Contributor

I guess that obsoletes my patch in #1423 :)

@itsmattkc
Copy link
Contributor

Thanks for picking this up @Simran-B and @prokoudine, I misunderstood how Qt's plurals worked.

You may have noticed this already, but this might get complicated with those SetFormat calls in the Preferences dialog. The sliders use the format as a means of printing the value, while you can override the format and place the value directly in it, the slider won't know how to update it automatically anymore.

@Simran-B
Copy link
Collaborator Author

Simran-B commented Nov 27, 2020

Yeah, it's certainly not trivial. One could set the string in SetFormat() without calling tr() and do that dynamically sometime later. That might make the UI work, but I'm fairly sure that lupdate won't pick up the source string anymore. Pseudo code:

setFormat("%n foo");
...
tr(getFormat(), nullptr, Value().toInt()); // <-- not a string literal

Maybe an unused/unreachable piece of code could be added with the string literal so that it gets picked up by lupdate without interfering with get/setFormat?

The easiest solution would be to not add plural handling for sliders and such however.

@itsmattkc
Copy link
Contributor

Yeah pretty sure lupdate won't pick up tr() without an immediate string.

A hacky solution might be to connect a function to the sliders' "value changed" signal and update the format externally each time it's value changes? That's probably the simplest solution that actually makes it work, but it's definitely hacky.

Otherwise yeah I'd just be inclined to not handle plurals for those.

qCeil() gives us a better translation for English (1.0 -> second, 1.1 -> seconds), but other languages probably have different rules...
While we don't know whether some langauges use different singular/plural forms for numbers with decimal places, we can't use Qt for this anyway because tr() only accepts ints for %n.
@Simran-B Simran-B requested a review from itsmattkc April 12, 2021 13:30
@Simran-B Simran-B self-assigned this Apr 12, 2021
@Simran-B Simran-B marked this pull request as ready for review April 12, 2021 22:22
@Simran-B Simran-B merged commit fca485b into master Apr 12, 2021
@Simran-B Simran-B deleted the translation-numerus-forms branch April 12, 2021 22:58
ThomasWilshaw pushed a commit to ThomasWilshaw/olive that referenced this pull request Apr 14, 2021
* .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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Translation UI languages / internationalization (i18n)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[TRANSLATION] [UI] Missing plural forms support
3 participants