I applied the IntelliJ Android code style template to an open-source project OneBusAway Android using Android Studio in an effort to standardize the code style and formatting.
The problem is that applying the template pushes the <xliff:g>
tags in strings.xml
to a new line and strips off trailing white space from the previous line. This effectively prevents any spacing from being introduced prior to the plural value.
BEFORE applying the style template:
<plurals name="stop_info_no_additional_data_hours_minutes">
<item quantity="one">No additional arrivals in the next 1 hour and %1$d minutes.</item>
<item quantity="other">No additional arrivals in the next <xliff:g id="count">%2$d</xliff:g> hours and %1$d minutes.</item>
</plurals>
.. it creates the correct string:
No additional arrivals in the next 2 hours and 35 minutes.
AFTER applying the template, it cuts off the space preceding the plural value:
<plurals name="stop_info_no_additional_data_hours_minutes">
<item quantity="one">No additional arrivals in the next 1 hour and %1$d minutes.</item>
<item quantity="other">No additional arrivals in the next
<xliff:g id="count">%2$d</xliff:g>
hours and %1$d minutes.
</item>
</plurals>
...which results in the string:
No additional arrivals in the next2 hours and 35 minutes.
I looked at the Android Open Source Project to see how they handle this, and it appears that the XML tag is left on a single line: https://github.com/android/platform_packages_apps_mms/blob/master/res/values/strings.xml#L690 https://github.com/android/platform_packages_apps_contacts/blob/master/res/values/strings.xml#L568
AOSP's two exceptions to the line limit don't apply here.
My options seem to be:
<xliff:g>
tag (I'd prefer to have the entire project under the template, so someone doesn't reformat and trigger this issue again in the future).Am I missing something? Is there another way to introduce a space here (e.g., using special/encoded characters)?
I'm also tracking this as an issue for OneBusAway Android on Github, which has screenshots and additional links if anyone is interested.
UPDATE: I tried formatting this same XML in Eclipse using the Android Template for Eclipse, and it doesn't cause this problem. In other words, there is no change to the XML after applying the template. So it seems that this is either a bug with Android Studio or an issue with the IntelliJ template. I'm assuming this is why the AOSP lines are intact.
EDIT: This issue was fixed in Android Studio 0.4.4, but re-appeared in 0.8.9. See AOSP Issue 65394 for details.
This is an IntelliJ/Studio bug which will be fixed in Android Studio 0.4.4: https://code.google.com/p/android/issues/detail?id=65394
(Thanks for filing that issue!)