Repository: translate/pootle

Issue:
Plural translations can't be saved if first plural form is not changed
If you change translation in the second plural form only and first plural from is left as it is then your change won't be applied.

The problem is in this line
https://github.com/translate/pootle/commit/bf9f008a6386bdcedf10ea1c8968ffed503d1897#diff-c35dd2b39fc0fd6ef39d097f2b1f222cR224

``` python
if self.instance.target.strings != multistring(value or [u'']):
```

It doesn't detect the changes.

But it works on Pootle 2.5.1-rc1. Hence something has been changed how multistrings are compared.



Discussion:

Resolving patch:
diff --git a/pootle/apps/pootle_store/forms.py b/pootle/apps/pootle_store/forms.py
--- a/pootle/apps/pootle_store/forms.py
+++ b/pootle/apps/pootle_store/forms.py
@@ -244,7 +244,7 @@ def updated_fields(self):
         def clean_target_f(self):
             value = self.cleaned_data['target_f']
 
-            if self.instance.target.strings != multistring(value or [u'']):
+            if self.instance.target != multistring(value or [u'']):
                 self.instance._target_updated = True
                 self._updated_fields.append((SubmissionFields.TARGET,
                                             to_db(self.instance.target),
diff --git a/pytest_pootle/factories.py b/pytest_pootle/factories.py
--- a/pytest_pootle/factories.py
+++ b/pytest_pootle/factories.py
@@ -78,6 +78,8 @@ class Meta(object):
         model = 'pootle_language.Language'
         django_get_or_create = ("code", )
 
+    nplurals = 2
+
     @factory.lazy_attribute
     def code(self):
         from pootle_language.models import Language
diff --git a/pytest_pootle/fixtures/models/unit.py b/pytest_pootle/fixtures/models/unit.py
--- a/pytest_pootle/fixtures/models/unit.py
+++ b/pytest_pootle/fixtures/models/unit.py
@@ -18,3 +18,16 @@ def unit_syncer(store0):
     unit = store0.units.filter(state=TRANSLATED).first()
     ttk = getclass(store0)
     return unit, ttk.UnitClass
+
+
+@pytest.fixture
+def unit_plural(store0):
+    from pootle_store.constants import TRANSLATED
+    from ...factories import UnitDBFactory
+
+    return UnitDBFactory(
+        store=store0,
+        state=TRANSLATED,
+        source=["%d day ago", "%d days ago"],
+        target=["%d dag gelede", "%d dae gelede"]
+    )


Test patch:
diff --git a/tests/views/unit.py b/tests/views/unit.py
--- a/tests/views/unit.py
+++ b/tests/views/unit.py
@@ -12,6 +12,8 @@
 
 from pytest_pootle.utils import create_api_request
 
+from translate.misc.multistring import multistring
+
 from pootle.core.exceptions import Http400
 from pootle_app.models.permissions import check_permission
 from pootle_comment import get_model as get_comment_model
@@ -239,3 +241,36 @@ def test_toggle_quality_check(rf, admin):
     response = toggle_qualitycheck(request, unit.id, qc.id)
     assert response.status_code == 200
     assert QualityCheck.objects.get(id=qc.id).false_positive is False
+
+
+@pytest.mark.django_db
+def test_submit_unit_plural(client, unit_plural, request_users, settings):
+    """Tests translation can be applied after suggestion is accepted."""
+    settings.POOTLE_CAPTCHA_ENABLED = False
+    user = request_users["user"]
+    if user.username != "nobody":
+        client.login(
+            username=user.username,
+            password=request_users["password"])
+
+    url = '/xhr/units/%d/' % unit_plural.id
+    target = [
+        "%s" % unit_plural.target.strings[0],
+        "%s changed" % unit_plural.target.strings[1]
+    ]
+    response = client.post(
+        url,
+        {
+            'target_f_0': target[0],
+            'target_f_1': target[1],
+        },
+        HTTP_X_REQUESTED_WITH='XMLHttpRequest'
+    )
+
+    if check_permission('translate', response.wsgi_request):
+        assert response.status_code == 200
+        changed = Unit.objects.get(id=unit_plural.id)
+        assert changed.target == multistring(target)
+
+    else:
+        assert response.status_code == 403