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

Plural forms for downloaded and uploading PO-files. #30

Closed
RomaKozeko opened this issue Jul 29, 2019 · 13 comments
Closed

Plural forms for downloaded and uploading PO-files. #30

RomaKozeko opened this issue Jul 29, 2019 · 13 comments

Comments

@RomaKozeko
Copy link

Hello!
I use locize-cli to synchronize localization files with locize.
In the project we use the PO file format.
Here is an example of a valid key.

msgid "tied with% {count} other% {test_one} test"
msgid_plural "tied with% {count} others% {test_one} test"
msgstr [0] "à égalité avec% {count} other% {test_one} test"
msgstr [1] "à égalité avec% {count} others% {test_one} test"

After locize sync --api-key api_key --project-id project_id --format po
we see the following fields in locize:

"tied with% {count} other% {test_one} test": "à égalité avec% {count} other% {test_one} test",
"tied with% {count} other% {test_one} test_plural": "à égalité avec% {count} others% {test_one} test"

When you need to synchronize translation files or download them using locize download, we get the following:

msgctxt "one} test"
msgid "tied with% {count} other% {test"
msgid_plural "tied with% {count} other% {test"
msgstr [0] "à égalité avec% {count} other% {test_one} test"
msgstr [1] "à égalité avec% {count} others% {test_one} test"

From this result questions follow.
In msgid and msgid_plural identical keys are stored. When requesting the key tied with% {count} others% {test_one} test we will not receive a translation.
And the second question.
Why is everything going after "_" placed in msgctxt?
As far as I know, msgctxt is used for Disambiguating Contexts.

@jamuhl
Copy link
Contributor

jamuhl commented Jul 29, 2019

Can you try again but with setting i18n format to "other" in your locize project settings? If using default format (i18next) it will handle part after _ as context...I guess you're not using i18next as that format looks different -> so setting your project to other format should at least solve that issue.

@RomaKozeko
Copy link
Author

I change project setting now it looks
image

But result not changed.
In locize:

"tied with %{count} other %{test_one} test": "à égalité avec %{count} other %{test_one} test",
"tied with %{count} other %{test_one} test_plural": "à égalité avec %{count} others %{test_one} test"

After download or sync:

msgctxt "one} test"
msgid "tied with% {count} other% {test"
msgid_plural "tied with% {count} other% {test"
msgstr [0] "à égalité avec% {count} other% {test_one} test"
msgstr [1] "à égalité avec% {count} others% {test_one} test"

@jamuhl
Copy link
Contributor

jamuhl commented Jul 30, 2019

Just had to confirm...detection of plural will automatically assume i18next format

We will need to see what we can do to avoid that handling...will ping you asap.

@jamuhl
Copy link
Contributor

jamuhl commented Jul 30, 2019

can you please try with locize-cli@4.8.3

@RomaKozeko
Copy link
Author

I checked the new version of locize-cli. The problem with "msgctxt" is fixed.
But there was a problem with plural forms.
Initially we have:

msgid "tied with %{count} other %{test_one} test"
msgid_plural "tied with %{count} others %{test_one} test"
msgstr [0] "à égalité avec %{count} other %{test_one} test"
msgstr [1] "à égalité avec %{count} others %{test_one} test"

The values ​​in "msgid" and "msgid_plural" are different.
After downloading or synchronization, the plural keys are as follows:

msgid "tied with %{count} other %{test_one} test"
msgid_plural "tied with %{count} other %{test_one} test"
msgstr [0] "à égalité avec %{count} other %{test_one} test"
msgstr [1] "à égalité avec %{count} others %{test_one} test"

And when we try to get the plural translation by the key "tied with %{count} others %{test_one} test" we do not find it.

@jamuhl
Copy link
Contributor

jamuhl commented Jul 31, 2019

May I ask what framework you're using for i18n? As I understand pluralforms in gettext (PHP) it's like the accepted reply here: https://stackoverflow.com/questions/12121515/multiple-plural-forms-in-gettext

msgid "%d Comment"
msgid_plural "%d Comments"
msgstr[0] "%d Komentarz"
msgstr[1] "%d Komentarze"
msgstr[2] "%d Komentarzy"

@RomaKozeko
Copy link
Author

We use https://github.com/grosser/gettext_i18n_rails
Yea this is pluralforms in gettext.
msgid and msgid_plural values are different. gettext stores two key values plural and singular "%d Comment" and "%d Comments".

@jamuhl
Copy link
Contributor

jamuhl commented Jul 31, 2019

while I understand it stores two keys (for translators) in the po file - I'm not sure that the plural key / msgid_plural is needed for the lookup for translations? Is that really the case...I was in the believe it uses the msgid to find a key and takes the right form based on the index in msgstr...?

@RomaKozeko
Copy link
Author

I can’t say exactly how pluralforms in gettext work. But at the moment I can’t get the pluralform translation in this case:
ns _ ('tied with %{count} other', 'tied with %{count} others', advocate_count) % {count: advocate_count}
After finding translated strings with gettext_i18n_rails, we see different keys in msgid and msgid_plural. And after downloading from locize, the keys become the same. I would like them to stay different.

@jamuhl
Copy link
Contributor

jamuhl commented Aug 1, 2019

The current big problem is that for non singular/plural language we store the pluralforms in JSON format with suffixed key_0, key_1, ... reflecting the index used in gettext msgstr - so in those cases we do only have the msgid (=key) in singular. And there is no way to get that msgid_plural.

Can't you just call: ns _ ('tied with %{count} other', 'tied with %{count} other', advocate_count) % {count: advocate_count} in that case?

We will have to think of a solution for this one...but currently, I have no idea how to solve this - as we do not have the plural key/msgid_plural.

@jamuhl
Copy link
Contributor

jamuhl commented Aug 3, 2019

The only way I currently see is adding an option to combine msgid and msgid_plural into one json key instead of using msgid only...will need to create a PR in an upstream module...might take a few days to get that through...

@RomaKozeko
Copy link
Author

Thank you!
I'll wait.

@jamuhl
Copy link
Contributor

jamuhl commented Aug 5, 2019

Could you please retry with: locize-cli@5.0.0

msgid "tied with% {count} other% {test_one} test"
msgid_plural "tied with% {count} others% {test_one} test"
msgstr [0] "à égalité avec% {count} other% {test_one} test"
msgstr [1] "à égalité avec% {count} others% {test_one} test"

results now in JSON

"tied with% {count} other% {test_one} test|#|tied with% {count} others% {test_one} test": "à égalité avec% {count} other% {test_one} test",
"tied with% {count} other% {test_one} test|#|tied with% {count} others% {test_one} test_plural": "à égalité avec% {count} others% {test_one} test"

So we can convert po -> JSON (locize UI) -> po keeping the msgid_plural by merging that into the JSON key.

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

No branches or pull requests

2 participants