[Android XML] CDATA and " escaping

In Android resource XMLs, you can use CDATA like this (especially useful if you don’t want to escape "):

<string name="app_info_gplv3_note"><![CDATA[
You should have received a copy of the GNU General Public License
along with this program.  If not, see <a href="https://www.gnu.org/licenses/">https://www.gnu.org/licenses/</a>.

When such strings are translated on Transifex, the CDATA code appears for translators, who may not know about this and just translate the text. Transifes then returns something like that:

<string name="app_info_gplv3_note">Você deve ter recebido uma cópia da GNU General Public License junto com
este programa. Se não recebeu, leia em &lt;a href="https://www.gnu.org/licenses/"&gt;https://www.gnu.org/licenses/&lt;/a&gt;.

Note that CDATA is not used anymore, but " is not quoted, too, so that the now string breaks compilation of the app.

My suggestion:

  1. when CDATA is used in the original string, force it for translations, too, or
  2. correctly handle CDATA and " escaping

In either case, CDATA should not be expoed to translators in a way that they can break XML syntax.

1 Like