Repository: WeblateOrg/weblate

Issue:
Problems with i18next v4 JSON format
### Describe the issue

When importing base language files from languages other that English plural forms are not extracted correctly to translation components from i18next v4 JSON files.

Example:
/ru/test.json (i18next v4 JSON):
```json
{
  "tags": {
    "show-more": {
      "plural_one": "Показать еще {{count}} тег",
      "plural_few": "Показать еще {{count}} тега",
      "plural_many": "Показать еще {{count}} тегов"
    }
  }
}
```
![2023-02-06_13-46](https://user-images.githubusercontent.com/9917883/216952723-2cfa5bf7-9514-443e-b0c2-4b0fc9246fcf.png)


As you can see in Weblate UI `plural_one` value is incorrectly mapped to to "few" plural form, "one" and "many" is missing, and "other" is used instead of "many".

Also "zero" special plural suffix currently suported in i18next v4 json is seems to be not supported in weblate at all (see i18next [documentation](https://www.i18next.com/translation-function/plurals#languages-with-multiple-plurals)) breaking any locale file using it.

### I already tried

- [X] I've read and searched [the documentation](https://docs.weblate.org/).
- [X] I've searched for similar issues in this repository.

### Steps to reproduce the behavior

_No response_

### Expected behavior

_No response_

### Screenshots

_No response_

### Exception traceback

_No response_

### How do you run Weblate?

Docker container

### Weblate versions

_No response_

### Weblate deploy checks

_No response_

### Additional context

_No response_


Discussion:
What version do you use? This should be already fixed in recent releases, see https://github.com/translate/translate/pull/4818
This issue looks more like a support question than an issue. We strive to answer these reasonably fast, but [purchasing the support subscription](https://weblate.org/support/) is not only more responsible and faster for your business but also makes Weblate stronger.

In case your question is already answered, [making a donation](https://weblate.org/donate/) is the right way to say thank you!
> What version do you use? This should be already fixed in recent releases, see [translate/translate#4818](https://github.com/translate/translate/pull/4818)

Version 4.15.2, deployed from docker just today.
Ah, the translate-toolkit with the fix was not yet released. You can try `bleeding` version of the container for now, see https://docs.weblate.org/en/latest/admin/install/docker.html#choosing-docker-hub-tag for info on tags.
I've just released and it will land in the Docker container soon: https://github.com/WeblateOrg/docker/pull/1729
The issue you have reported is now resolved. If you don’t feel it’s right, please follow its labels to get a clue for further steps.

* 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](https://weblate.org/donate/).
> I've just released and it will land in the Docker container soon: [WeblateOrg/docker#1729](https://github.com/WeblateOrg/docker/pull/1729)

@nijel 
Just tested it 4.16-dev version, the behavior is a little different but still broken.

Same JSON now result in this:
![2023-02-06_18-09](https://user-images.githubusercontent.com/9917883/217008302-d5ba4a19-0dc9-413f-923c-500d0e73f227.png)
"_one" form is mapped correctly, "_few" - is empty, "_many" - is missing from UI, "_other" - is present and empty.
i18next "_zero" suffix is still not supported and missing from UI.

It seems the issue is not resolved.
Can you please take a look at translate-toolkit version it uses? It is visible at `/about/` URL.
> Can you please take a look at translate-toolkit version it uses? It is visible at `/about/` URL.

translate-toolkit 3.8.3
similar bug 
translate-toolkit 3.8.4

test case

```json
{
  "promotetitle": "21232",
  "promotegift": "21232",
  "promoteendsinNdays": "21232",
  "promoteenddate": "21232",
  "promoteextradeal": "21232",
  "promotetagtext": "21232",
  "pormotebannertext": "21232",
  "pormotebannertimerange": "21232"
}
```



weblate :
![image](https://user-images.githubusercontent.com/11308261/217761751-45cffeb9-0f88-4c2b-990b-134cb7a41ffe.png)


wrong key / value 




@Timsonrobl 
> translate-toolkit 3.8.3

Okay, then the above linked fix is not included, you need 3.8.4 for it.

@uihoh0 
> similar bug

Please open a separate issue for that with clear description of how your translations are configured. That apparently has nothing to do with handling plurals.

@nijel 
Just tested it on version with translate-toolkit 3.8.4 and the result is exactly the same as before: only "_one" is mapped, "_many" field is missing, "_other" present and empty
I don't understand why "many" field is missing in the UI, even with the source mapping issue aside.
Most Slavic languages have "many" plural form according to ISO CLDR [Language Plural Rules](https://unicode-org.github.io/cldr-staging/charts/37/supplemental/language_plural_rules.html) but Weblate is displaying "other" instead of "many" for them.
Could this be the source of this issue? This doesn't explain why "few" isn't mapping correctly though.
> I don't understand why "many" field is missing in the UI, even with the source mapping issue aside.

This is a naming issue only, https://github.com/WeblateOrg/weblate/pull/8773 will fix that.

The bug itself should be addressed by https://github.com/WeblateOrg/weblate/pull/8772, I would appreciate it if you could test it.
> The bug itself should be addressed by #8772, I would appreciate it if you could test it.

I can test it as soon as in hits `bleeding` docker channel
The issue you have reported is now resolved. If you don’t feel it’s right, please follow its labels to get a clue for further steps.

* 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](https://weblate.org/donate/).
@nijel 
Tested on [bleeding-2023-02-10-cd604cd0baa6bd7b9c4a370e1f7e6b8f9802cf9d](https://hub.docker.com/layers/weblate/weblate/bleeding-2023-02-10-cd604cd0baa6bd7b9c4a370e1f7e6b8f9802cf9d/images/sha256-ff31b70bd279eabba1e95678f209dc036a2f7e050d35230b5017636533dbd9f3?context=explore) image - the bug is still present
[test.zip](https://github.com/WeblateOrg/weblate/files/10706221/test.zip)
![image](https://user-images.githubusercontent.com/9917883/218066691-e590c313-70bd-46e9-a66e-be7bb019dd49.png)

This issue has been automatically marked as stale because there wasn’t any recent activity.

It will be closed soon if no further action occurs.

Thank you for your contributions!
Are there any news on this issue?
Also the issue is mislabeled as a question, while it is a confirmed bug, can someone please tag it?

Resolving patch:
diff --git a/weblate/formats/ttkit.py b/weblate/formats/ttkit.py
--- a/weblate/formats/ttkit.py
+++ b/weblate/formats/ttkit.py
@@ -242,13 +242,6 @@ def __init__(
             is_template=is_template,
             source_language=source_language,
         )
-        # Set language (needed for some which do not include this)
-        if language_code is not None and self.store.gettargetlanguage() is None:
-            # This gets already native language code, so no conversion is needed
-            self.store.settargetlanguage(language_code)
-        if source_language is not None and self.store.getsourcelanguage() is None:
-            # This gets already native language code, so no conversion is needed
-            self.store.setsourcelanguage(source_language)
 
     @staticmethod
     def serialize(store):
@@ -259,6 +252,11 @@ def fixup(self, store):
         """Perform optional fixups on store."""
         if self.force_encoding is not None:
             store.encoding = self.force_encoding
+        # This gets already native language code, so no conversion is needed
+        if self.language_code is not None:
+            store.settargetlanguage(self.language_code)
+        if self.source_language is not None:
+            store.setsourcelanguage(self.source_language)
         return
 
     def load(self, storefile, template_store):


Test patch: