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

weblate sees messages using msgctxt as ambiguous #7177

Closed
JohnRDOrazio opened this issue Jan 29, 2022 · 3 comments
Closed

weblate sees messages using msgctxt as ambiguous #7177

JohnRDOrazio opened this issue Jan 29, 2022 · 3 comments
Assignees
Labels
bug Something is broken.
Milestone

Comments

@JohnRDOrazio
Copy link
Contributor

JohnRDOrazio commented Jan 29, 2022

Describe the problem

When using gettext, we have the possibility of distinguishing one same word or phrase to be translated by context, so that it can be translated differently according to the context it's in. So the source word or phrase might be the same, but the translation will be different:

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

Even though PHP doesn't have native support for pgettext, I found that it is easy enough to implement with this function:

if (!function_exists('pgettext')) {
    function pgettext($context, $msgid) {
       $contextString = "{$context}\004{$msgid}";
       $translation = dcgettext('litcal', $contextString, LC_MESSAGES);
       if ($translation == $contextString)  return $msgid;
       else  return $translation;
    }
}

Tested and working, when I generate the pot file like this:

xgettext --from-code=UTF-8 --add-comments='translators:' --keyword="pgettext:1c,2"  ...

Weblate is picking up on msgctxt because I can see CONTEXT both in the string information box, and in the translation box (see screenshot below).

However, weblate is complaining that the translation is inconsistent, I'm guessing simply because there are different translations of the same source string? It's like weblate is ignoring the Context, which should distinguish between multiple source strings with the same msgid.

Describe the solution you'd like

Weblate should take msgctxt into account when doing consistency checks.

Describe alternatives you've considered

No response

Screenshots

For example, I have a project where I am translating the single possessive preposition "of" into various other languages, since it is needed by the program to build a phrase. However in English there will not always be a definite article that follows, whereas in other languages there will be, and the translation should therefore include the definite article which, in other languages, will most often have gender and number. So we have to distinguish between at least four contexts:

  • masculine singular
  • masculine plural
  • feminine singular
  • feminine plural

screenshot weblate msgctxt

From the above screenshot, we can see that weblate is trying to get me to apply the translation from one context to another context, simply because the msgid is the same. It does not take into account msgctxt when raising inconsistency flags and generating suggested translations.

Additional context

Weblate: 4.10.1

@JohnRDOrazio
Copy link
Contributor Author

When looking at the Other occurrences tab, I see that Weblate does distinguish between the situation where the source and the context are the same, or the other situation where the source is the same but the context is different. If it knows the underlying difference, it should take that into account before raising an inconsistency flag:
screenshot weblate msgctxt 2

@nijel
Copy link
Member

nijel commented Jan 30, 2022

The check is raised on the suggestion, what really doesn't make sense. It should be skipped there...

@nijel nijel added the bug Something is broken. label Jan 30, 2022
@nijel nijel added this to the 4.11 milestone Jan 30, 2022
@nijel nijel self-assigned this Feb 3, 2022
@nijel nijel closed this as completed in 7e3b755 Feb 3, 2022
@github-actions
Copy link

github-actions bot commented Feb 3, 2022

Thank you for your report; the issue you have reported has just been fixed.

  • In case you see a problem with the fix, please comment on this issue.
  • In case you see a similar problem, please open a separate issue.
  • If you are happy with the outcome, don’t hesitate to support Weblate by making a donation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken.
Projects
None yet
Development

No branches or pull requests

2 participants