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

unchanged strings have odd quoting added to them (Android strings.xml) #1519

Closed
eighthave opened this Issue Jun 13, 2017 · 5 comments

Comments

Projects
None yet
2 participants
@eighthave
Copy link

eighthave commented Jun 13, 2017

Steps to reproduce

It happens every time I merge new translation commits into our git repo. I'm not sure the exact steps to make it happen, but it happens frequently. My guess is that it is related to Unicode, e.g. strings that contain non-ASCII characters.

Actual behaviour

Random, unchanged strings are wrapped in " double-quotes, and sometimes there are spaces added, for example:

-------------------- app/src/main/res/values-de/strings.xml --------------------
index 714d0bb..29b758e 100644
@@ -231,7 +231,7 @@
         liegen, dass Sie Ihre Paketquellen aktualisieren müssen oder diese tatsächlich keine Ihrer Anwendungen
         beinhalten.
     </string>
-    <string name="empty_can_update_app_list">Glückwunsch! Alle Ihre Apps sind auf dem neuesten Stand (oder Ihre Paketquellen sind veraltet).</string>
+    <string name="empty_can_update_app_list">"Glückwunsch! Alle Ihre Apps sind auf dem neuesten Stand (oder Ihre Paketquellen sind veraltet). "</string>
 
     <string name="swap_send_fdroid">F-Droid senden</string>
     <string name="swap_connecting">Verbindungsaufbau</string>

-------------------- app/src/main/res/values-eo/strings.xml --------------------
index 1be4fc6..e5f56a1 100644
@@ -238,7 +238,7 @@
         En via aparato estas aplikaĵoj, tamen ili ne estas disponeblaj el F-Droid. Eble vi devas ĝisdatigi viajn
         deponejojn, aŭ la deponejoj vere ne enhavas viajn aplikaĵojn.
     </string>
-    <string name="empty_can_update_app_list">Bonege! Ĉiuj viaj aplikaĵoj estas ĝisdataj (aŭ viaj deponejoj estas neĝisdataj).</string>
+    <string name="empty_can_update_app_list">"Bonege! Ĉiuj viaj aplikaĵoj estas ĝisdataj (aŭ viaj deponejoj estas neĝisdataj). "</string>
     <string name="empty_search_available_app_list">Neniuj kongruaj aplikaĵoj disponeblaj.</string>
 
     <string name="requesting_root_access_body">Petado pri ĉefuzanta aliro…</string>
@@ -289,7 +289,7 @@
     <string name="swap_switch_to_wifi">Tuŝu por ŝanĝi al vifio</string>
     <string name="swap_confirm_connect">Ĉu vi volas elŝuti aplikaĵojn el %1$s nun?</string>
     <string name="swap_dont_show_again">Ne montri ĉi tion denove</string>
-    <string name="swap_scan_or_type_url">Unu persono devas skani la kodon, aŭ entajpi URL-n de aliulo en foliumilon.</string>
+    <string name="swap_scan_or_type_url">"Unu persono devas skani la kodon, aŭ entajpi URL-n de aliulo en foliumilon. "</string>
     <string name="swap_choose_apps">Elekti aplikaĵojn</string>
     <string name="swap_scan_qr">Skanu QR-kodon</string>
     <string name="swap_people_nearby">Homoj proksime</string>

------------------ app/src/main/res/values-zh-rCN/strings.xml ------------------
index 15a2ccd..e7e83ad 100644
@@ -1,8 +1,8 @@
 <?xml version='1.0' encoding='UTF-8'?>
 <resources>
     <string name="SignatureMismatch">新版本签名与旧版本不同,请先卸载旧版本应用再安装新版本。(注意:卸载旧版本会清除该应用存储的所有内部数据)</string>
-    <string name="installIncompatible">该应用程序好像与您的设备不兼容。您仍然要尝试安装吗?</string>
-    <string name="installDowngrade">您正在降级该应用程序。这样做可能会使该程序无法工作,甚至丢失您的数据。您仍然要尝试降级吗?</string>
+    <string name="installIncompatible">"该应用程序好像与您的设备不兼容。您仍然要尝试安装吗? "</string>
+    <string name="installDowngrade">"您正在降级该应用程序。这样做可能会使该程序无法工作,甚至丢失您的数据。您仍然要尝试降级吗? "</string>
     <string name="version">版本</string>
     <string name="delete">删除</string>
     <string name="enable_nfc_send">启用NFC发送…</string>
@@ -41,7 +41,7 @@
     <string name="repo_exists_add_fingerprint">此软件源已经设置,该操作将会添加新的密钥信息。</string>
     <string name="repo_exists_enable">此软件源已经设置,请确认您是否要重新启用它。</string>
     <string name="repo_exists_and_enabled">此软件源已经设置好并已启用。</string>
-    <string name="repo_delete_to_overwrite">在您添加不同密钥的软件源之前,您需要先删除该软件源。</string>
+    <string name="repo_delete_to_overwrite">"在您添加不同密钥的软件源之前,您需要先删除该软件源。 "</string>
     <string name="malformed_repo_uri">忽略异常格式的软件源URI:%s</string>
     <string name="menu_manage">管理软件源</string>
     <string name="menu_send_apk_bt">用蓝牙分享F-Droid</string>

This happens in most commits, you can see lots more in the most recent 20 commits in https://hosted.weblate.org/git/f-droid/f-droid

Expected behaviour

It should not modify strings that have not changed. It should not add pointless quoting around strings.

Server configuration

hosted.weblate.org

@nijel

This comment has been minimized.

Copy link
Member

nijel commented Jun 13, 2017

The quoting is there needed because of the added spaces and this is exactly change which seems to have happened there (I've checked Esperanto, but I assume it's same with others).

There is seems to be trailing newline in the string swap_scan_or_type_url which is interpreted as extra whitespace. I'm not sure this is correct, but there already have been numerous discussions about handling newlines in Android resources (see #1418, #711). Maybe just whitespace should be stripped there unless quoted. Still it would be great to have this format documented to avoid guesses like this.

@eighthave

This comment has been minimized.

Copy link

eighthave commented Jun 13, 2017

The source of these trailing spaces is from the Android Studio auto-formatter (Ctrl-Alt-L). A string like this:

    <string name="update_auto_download_summary">Updates are downloaded automatically and you are notified to install them</string>

Is auto-wrapped by Android Studio into this:

    <string name="update_auto_download_summary">Updates are downloaded automatically and you are notified to install
        them
    </string>

So I think that's clear that at least the Android Studio developers do not consider that space to be meaningful. If adding quoting is something valid for keeping spaces like that, then I think Weblate should not add those quotes, it should only keep them if they are already there. Quoting with " in the contents of an element is not an XML thing, so I guess those quotes mean something to Android. But the Android Studio code formatter does not really respect them. Could be that the Android Studio devs have not thought at all about this though, that's unfortunately common. Here's an Android Studio wrapping example with the quotes:

    <string name="latest__empty_state__never_updated">"Once your list of apps has been updated, the latest apps should show here "</string>

after wrapping:

    <string name="latest__empty_state__never_updated">"Once your list of apps has been updated, the latest apps should
        show here "
    </string>

So what to do without " quotes in the source strings seems pretty clear to me: it should strip leading and trailing whitespace, and normalize spaces between words to a single space (unless you want to try to parse the indenting). With quoting seems harder. I understand wanting to have readable blocks of text, but it seems that the Android strings.xml expects \n for meaningful space instead of newlines.

@eighthave

This comment has been minimized.

Copy link

eighthave commented Jun 13, 2017

As far as I can tell, Android expects \n for meaningful newlines when the string is not quoted with ". In order to have regular newlines have meaning, Android needs " quoting. It seems that Weblate should do the same. This is a nice discussion of some of this stuff:

So for this string in Android, the newlines are not displayed and all spaces between words are a single space:

    <string name="nearby_splash__both_parties_need_fdroid">Both parties need
        %1$s to use nearby.
    </string>

And in this string, the newlines are displayed in Android:

    <string name="nearby_splash__both_parties_need_fdroid">"Both parties need
        %1$s to use nearby.  "
    </string>

@nijel nijel added bug and removed question labels Jun 15, 2017

@nijel

This comment has been minimized.

Copy link
Member

nijel commented Jun 15, 2017

Thanks for digging into this, I've submitted pull request for translate-toolkit to address this:

translate/translate#3637

The fix has been just deployed to Hosted Weblate as well.

@nijel nijel closed this Jun 15, 2017

@nijel

This comment has been minimized.

Copy link
Member

nijel commented Jun 15, 2017

Thank you for your report, the issue you have reported has just been fixed.

  • In case you see problem with the fix, please comment on this issue.
  • In case you see similar problem, please open separate issue.
  • If you are happy with the outcome, consider supporting Weblate by donating.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment