[yew-devel] [PATCH proxmox-yew-comp] apt_repositories: Add context to string with plural form

Maximiliano Sandoval m.sandoval at proxmox.com
Thu Jan 23 10:57:05 CET 2025


Thomas Lamprecht <t.lamprecht at proxmox.com> writes:

> Am 22.01.25 um 13:09 schrieb Maximiliano Sandoval:
>> The "Warning" msgid is already used in proxmox-widget-toolkit. Gettext
>> does not allow duplicated msgids and therefore they cannot be shared for
>> translations with and without plurals.
>
> Hmm, a bit odd IMO, do you have by chance any reference to some background
> and/or rational here?

It is a bit odd tbh, it is the first time I ever encounter it. However,
considering the sheer size of messages.pot we will probably run into
this again.

The combination of `msgid` and `msgctxt` uniquely identifies a
translatable string. We currently have

```
#: proxmox-widget-toolkit/src/node/APTRepositories.js:270 proxmox-widget-toolkit/src/node/APTRepositories.js:447 proxmox-widget-toolkit/src/window/NotificationMatcherEdit.js:1065
msgid "Warning"
msgstr ""
```
and
```
#: proxmox-yew-comp/src/apt_repositories.rs:877
msgid "Warning"
msgid_plural "Warnings"
msgstr[0] ""
msgstr[1] ""
```

Normally, `msgmerge` or similar will just merge messages containing the
same `msgid` and `msgctxt`, but in this case this cannot be merged as
one has plurals forms and the other does not, on the app-side one will
be retrieved with `gettext("Warning")` while the other by
`ngettext("Warning", 1)` which explains why they can't be merged.
xgettext will throw the following error message:

```sh
$ xgettext proxmox-yew-comp.pot proxmox-widget-toolkit.pot
proxmox-widget-toolkit.pot:2080: duplicate message definition...
proxmox-yew-comp.pot:187: ...this is the location of the first definition
xgettext: found 1 fatal error
```
By adding a context, we can go around the issue.

> Can you also describe what context does in the commit message here, as this
> is the first commit introducing that usage IIRC.

Sure, it makes sense to send a v2 updating the commit message.

There are two ways to propagate context to translators, via comments on
top of the message (preferably with a suffix like `TRANSLATORS:` so
translators know the comment is intended for them) and via msgctxt. The
main difference is that messages with different comments will be merged
and all comments will be visible to the translator. On the other hand,
two messages with the same msgid but different msgctxt have to be
translated as separate strings.

Contexts are useful for when a string could be either a verb or a noun
and both variants appear in different places of the UI, e.g. "Backup".
More on contexts can be found at gettext's documentation [1].

Comments might be helpful with strings like "Expire" which generally
means "Expiry date". Or when there are acronyms (e.g "ACME Domain"),
even though they should not be expanded, they shed light into the
structure of the sentence, e.g. gender or case. They are also helpful
for e.g.

```
#. TRANSLATORS: This is Horizontal Ellipsis U+2026
#: src/some_file.rs.ui:21
msgid "Open…"
msgstr "Abrir…"
```

>>
>> Signed-off-by: Maximiliano Sandoval <m.sandoval at proxmox.com>
>> ---
>>  src/apt_repositories.rs | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/src/apt_repositories.rs b/src/apt_repositories.rs
>> index b671d01e..487ca7f 100644
>> --- a/src/apt_repositories.rs
>> +++ b/src/apt_repositories.rs
>> @@ -873,7 +873,8 @@ fn render_text_with_warnings(text: &str, warnings: &[String]) -> Html {
>>                  <i class="fa fa-fw fa-exclamation-circle"/>
>>              </span>
>>          };
>> -        let title = tr!("Warning" | "Warnings" % warnings.len());
>> +        let title =
>> +            tr!("This is a title" => "Warning" | "Warnings" % warnings.len());
>
> Do I need to use this context every time I use just the plural variant?

Unfortunately, here it was only added because there already a message
with the same `msgid`, this particular string does not really need
context otherwise. I count 8 plurals in proxmox-datacenter-manager.pot
and this was the only one with conflicts, and with a string which is not
used at all with proxmox-datacenter-manager.

Perhaps this would be simpler if there were different (and smaller) .po
files on a per project basis, but this workaround seems simpler than an
overhaul for now.

> And if that's the case, would another context make more sense, like
> "Unconditional plural"? Just trying to get a better understanding of the
> details here.

Perhaps one can add a better context though it is more of workaround
that something that would help translators for this specific string. I
think just stating the UI semantics is helpful enough here, e.g. "Dialog
title" or "Button label".

[1] https://www.gnu.org/software/gettext/manual/html_node/Contexts.html




More information about the yew-devel mailing list