title: IntelliJ Android code style template with Android Studio removes spaces preceding plurals in strings
body: <p>I applied the <a href="https://android.googlesource.com/platform/development/+/master/ide/intellij/codestyles/AndroidStyle.xml" rel="nofollow">IntelliJ Android code style template</a> to an open-source project <a href="https://github.com/OneBusAway/onebusaway-android" rel="nofollow">OneBusAway Android</a> using Android Studio in an effort to standardize the code style and formatting.</p>
  
  <p>The problem is that applying the template pushes the <code>&lt;xliff:g&gt;</code> tags in <a href="https://github.com/OneBusAway/onebusaway-android/blob/master/onebusaway-android/src/main/res/values/strings.xml#L146" rel="nofollow"><code>strings.xml</code></a> 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.</p>
  
  <p>BEFORE applying the style template:</p>
  
  <pre><code>&lt;plurals name="stop_info_no_additional_data_hours_minutes"&gt;
      &lt;item quantity="one"&gt;No additional arrivals in the next 1 hour and %1$d minutes.&lt;/item&gt;
      &lt;item quantity="other"&gt;No additional arrivals in the next &lt;xliff:g id="count"&gt;%2$d&lt;/xliff:g&gt; hours and %1$d minutes.&lt;/item&gt;
  &lt;/plurals&gt;
  </code></pre>
  
  <p>.. it creates the correct string:</p>
  
  <pre><code>No additional arrivals in the next 2 hours and 35 minutes.
  </code></pre>
  
  <p>AFTER applying the template, it cuts off the space preceding the plural value:</p>
  
  <pre><code>&lt;plurals name="stop_info_no_additional_data_hours_minutes"&gt;
      &lt;item quantity="one"&gt;No additional arrivals in the next 1 hour and %1$d minutes.&lt;/item&gt;
      &lt;item quantity="other"&gt;No additional arrivals in the next
          &lt;xliff:g id="count"&gt;%2$d&lt;/xliff:g&gt;
          hours and %1$d minutes.
      &lt;/item&gt;
  &lt;/plurals&gt;
  </code></pre>
  
  <p>...which results in the string:</p>
  
  <pre><code>No additional arrivals in the next2 hours and 35 minutes.
  </code></pre>
  
  <p>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:
  <a href="https://github.com/android/platform_packages_apps_mms/blob/master/res/values/strings.xml#L690" rel="nofollow">https://github.com/android/platform_packages_apps_mms/blob/master/res/values/strings.xml#L690</a>
  <a href="https://github.com/android/platform_packages_apps_contacts/blob/master/res/values/strings.xml#L568" rel="nofollow">https://github.com/android/platform_packages_apps_contacts/blob/master/res/values/strings.xml#L568</a></p>
  
  <p>AOSP's <a href="http://source.android.com/source/code-style.html#limit-line-length" rel="nofollow">two exceptions to the line limit</a> don't apply here.</p>
  
  <p>My options seem to be:</p>
  
  <ol>
  <li>Change the style template to allow leading or trailing white space (I'd prefer to avoid this to keep the template identical to AOSP)</li>
  <li>Ignore the template for these lines by either extending them beyond 100 characters or adding a leading space inside the <code>&lt;xliff:g&gt;</code> 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).</li>
  </ol>
  
  <p>Am I missing something?  Is there another way to introduce a space here (e.g., using special/encoded characters)?</p>
  
  <p>I'm also tracking this as <a href="https://github.com/OneBusAway/onebusaway-android/issues/99" rel="nofollow">an issue</a> for OneBusAway Android on Github, which has screenshots and additional links if anyone is interested.</p>
  
  <p>UPDATE: I tried formatting this same XML in Eclipse using the <a href="https://android.googlesource.com/platform/development/+/master/ide/eclipse" rel="nofollow">Android Template for Eclipse</a>, 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.</p>
  
  <p>EDIT:  This issue was fixed in Android Studio 0.4.4, but re-appeared in 0.8.9.  See <a href="https://code.google.com/p/android/issues/detail?id=65394" rel="nofollow">AOSP Issue 65394</a> for details.</p>