WeblateOrg / weblate

Web based localization tool with tight version control integration.
https://weblate.org/
GNU General Public License v3.0
4.52k stars 999 forks source link

Android string download should not include newlines #12559

Open tipa opened 1 week ago

tipa commented 1 week ago

Describe the issue

When downloading Android translation strings (either through the website or the API), strings that include a line break have - additionally to the expected and required "\n" - a newline character in the export XML. This causes the string, when loaded in an Android app, to have an additional, unwanted space character: https://stackoverflow.com/a/31683548/3585218

I already tried

Steps to reproduce the behavior

Expected behavior

No newlines inside the string-tags in XML files, only \n

Screenshots

Current behavior: image

Expected behavior: image

Exception traceback

No response

How do you run Weblate?

Other

Weblate versions

Weblate deploy checks

System check identified some issues:

WARNINGS:
?: (security.W008) Your SECURE_SSL_REDIRECT setting is not set to True. Unless your site should be available over both SSL and non-SSL connections, you may want to either set this setting True or configure a load balancer or reverse-proxy server to redirect all connections to HTTPS.
?: (weblate.W033.Gerrit) Failure in loading VCS module for Gerrit: git: 'review' is not a git command. See 'git --help'.
 (1)
        HINT: https://docs.weblate.org/en/weblate-5.7.2/vcs.html
?: (weblate.W039.AlibabaTranslation) Error importing module 'weblate.machinery.alibaba' in WEBLATE_MACHINERY: No module named 'aliyunsdkalimt'
        HINT: https://docs.weblate.org/en/weblate-5.7.2/admin/machine.html

System check identified 3 issues (1 silenced).

Additional context

No response

nijel commented 1 week ago

Indeed, translate-toolkit (which Weblate uses to manipulate with the translation files) adds newline to improve XML readability. The additional whitespace due to the newline is added at the end of the string, what should be pretty harmless. To be precise, translate-toolkit does what SO answer you've shared suggests as a correct approach to this since https://github.com/translate/translate/pull/3606.

tipa commented 1 week ago

I don't agree with the "solution" in the SO post I linked. This comment also highlights the problem with the newlines.

Yes, the additional whitespace at the end of each line is harmless or unnoticeable in most of the cases (especially when used in uneditable, unselectable labels), but not in all of them. I noticed it in my app in a case where the multi-line localized string resource is the default for a user-editable value, shown in an editable text field. In the end, it's not the exact string that was translated in Weblate - and that should be the expected result imo.

github-actions[bot] commented 1 week ago

The issue you've reported needs to be addressed in the translate-toolkit. Please file the issue there, and include links to any relevant specifications about the formats (if applicable).

nijel commented 1 week ago

While I understand you, I'm a bit hesitant in breaking behavior translate-toolkit has for years. Let's see if somebody objects to https://github.com/translate/translate/pull/5352