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

Adding Translation Units behaves differently based on order of invocations. #4277

Closed
jojurajan opened this issue Aug 6, 2020 · 5 comments
Closed
Labels
needinfo This needs more information from the reporter to be implemented.

Comments

@jojurajan
Copy link
Contributor

Describe the bug

Adding a translation unit with same key for different languages in a component behaves differently based on order

To Reproduce

If we have a project with en as source language,

Scenario 1:

  • Post a new translation unit to en. {"key": "string A", value: "This is string A in en"}
  • Post same translation unit to de. {"key": "string A", value: "This is string A in de"}

We get an error Translation with this key seem to already exist!

Scenario 2:

  • Post a new translation unit to de. {"key": "string B", value: "This is string B in de"}
  • Post same translation unit to en. {"key": "string B", value: "This is string B in en"}

The translated string is visible under German language for the component.

Expected behavior

The translated string is visible in German, irrespective of the order of execution of translation Unit APIs

@nijel nijel added the needinfo This needs more information from the reporter to be implemented. label Aug 6, 2020
@nijel
Copy link
Member

nijel commented Aug 6, 2020

How exactly do you add units? In Weblate should be possible to add only units to source language.

What Weblate version do you use?

@jojurajan
Copy link
Contributor Author

Adding the versions output

$ ./manage.py list_versions
 * Weblate: weblate-4.1.1-702-gc7564737db
 * Django: 3.0.8
 * siphashc: 1.3
 * Whoosh: 2.7.4
 * translate-toolkit: 3.0.0
 * lxml: 4.5.2
 * Pillow: 7.2.0
 * bleach: 3.1.5
 * python-dateutil: 2.8.1
 * social-auth-core: 3.3.3
 * social-auth-app-django: 4.0.0
 * django-crispy-forms: 1.9.2
 * oauthlib: 3.1.0
 * django-compressor: 2.4
 * djangorestframework: 3.11.0
 * django-filter: 2.3.0
 * django-appconf: 1.0.3
 * user-agents: 2.1
 * filelock: 3.0.12
 * setuptools: 40.6.2
 * jellyfish: 0.8.2
 * openpyxl: 3.0.4
 * celery: 4.4.6
 * kombu: 4.6.11
 * translation-finder: 2.1
 * html2text: 2020.1.16
 * pycairo: 1.19.1
 * pygobject: 3.36.1
 * diff-match-patch: 20200713
 * requests: 2.24.0
 * django-redis: 4.12.1
 * hiredis: 1.1.0
 * sentry_sdk: 0.16.1
 * Cython: 0.29.21
 * misaka: 2.1.1
 * GitPython: 3.1.7
 * borgbackup: 1.1.13
 * pyparsing: 2.4.7
 * Python: 3.6.8
 * Git: 2.27.0
 * psycopg2-binary: 2.8.5
 * chardet: 3.0.4
 * ruamel.yaml: 0.16.10
 * git-svn: 2.27.0
 * Redis server: 6.0.5
 * PostgreSQL server: 9.6.18
 * Database backends: django.db.backends.postgresql
 * Cache backends: default:RedisCache, avatar:FileBasedCache
 * Email setup: django.core.mail.backends.smtp.EmailBackend: localhost
 * OS encoding: filesystem=utf-8, default=utf-8
 * Platform: Darwin 18.7.0 (x86_64)

@jojurajan
Copy link
Contributor Author

I used this script to add the units. Just changed the language and value parameters as required.

import requests

def check_unit_upload():
    SETTINGS = {
        "base_url": "http://localhost:8000/api",
        "api_key": "<add_key>"
    }
    base_url = SETTINGS["base_url"]
    api_key = SETTINGS["api_key"]
    project = "mono-trans-project"
    comp = "sample-1k-mono-new"
    langauge = "en"
    data = {
        "key": "String F",
        "value" : "This is string F in en"
    }
    resp = requests.post(
        f"{base_url}/translations/{project}/{comp}/{langauge}/units/",
        headers={"Authorization": f"Token {api_key}"},
        data=data
    )
    print(resp._content)

@nijel
Copy link
Member

nijel commented Aug 6, 2020

When I try it, I (correctly) get HTTP 403 when trying to add unit to non source language:

<Response [403]>
'{"detail":"Can not add unit"}'

On source language it works just fine and returns the newly added unit and fails on second execution when unit is already added.

@jojurajan
Copy link
Contributor Author

@nijel Thank you for the quick response. I had a look after your reply. I had forgotten to remove an update which was bypassing the checks due to which this weird scenario was possible. After reverting back, I can confirm that it works as you have said.

I'm extremely sorry for the trouble that I caused you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needinfo This needs more information from the reporter to be implemented.
Projects
None yet
Development

No branches or pull requests

2 participants