miracle2k / android2po

Convert Android string resources to gettext, and back.
BSD 2-Clause "Simplified" License
126 stars 50 forks source link

Doesn't unescape XML. #30

Open murraycu opened 9 years ago

murraycu commented 9 years ago

If my strings.xml has a string such as this:

<string name="about_text2">This android app was developed by &lt;a href="http://murrayc.com/&quot;&gt;Murray Cumming&lt;a&gt;</string>

Then the strings.pot file (and the strings-*.po files) contains this:

msgctxt "about_text2"
msgid ""
"This android app was developed by &lt;a "
"href=http://murrayc.com/&gt;Murray Cumming&lt;a&gt;"
msgstr ""

These lt, gt and quot entities are entirely specific to XML so I wouldn't expect to see them in the .po file for translators to see.

I think there are at least some cases (full HTML to show in an HTML view?) where people really need to correctly escape their markup in strings.xml.

This could get awkward because Android also accepts unescaped markup in strings.xml, in which case it seems to parse the resulting child nodes and pretend that nothing odd happened. And that's actually the only way to have an a link in your TextView's text when specifying the text via the layout XML, so I have to set these in code via Html.fromHtml(getString(R.string.something)).

I actually started using the correct XML escaping in my strings.xml because a2po adds quotes around the strings when importing them back into strings.xml. Android seemes to ignore them, but it seemed odd and I considered it a bug in my strings.xml ratherr than a problem with a2po.

murraycu commented 9 years ago

Actually, maybe I just shouldn't do this. This documentation http://developer.android.com/guide/topics/resources/string-resource.html under "Escaping apostrophes and quotes" says that "XML encodings" don't work.

murraycu commented 9 years ago

Here's a bug report/question about those extra quotes when not escaping the markup: https://github.com/miracle2k/android2po/issues/31