[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>.
]]></string>

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;.
]]&gt;</string>

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

Hello @rfc2822,

Thank you for your question.

Regarding the issues you mentioned, please check my comments/answers below:

#1: when CDATA is used in the original string, force it for translations, too”
Answer: In order to ensure that such sections are preserved, Transifex offers the ability to set up custom translation checks. This means that if such text is not preserved in the translation, then the translation check is triggered raising an error or warning indicating that the condition has been violated. You can check our documentation guide here: https://docs.transifex.com/translation-checks/setting-translation-checks#section-custom-variables in order to find more information about this. Hope it helps.

#2. correctly handle CDATA and escaping”
Thank you for bringing this to our attention. We will investigate it further and let you know when new information arises. More information about the escaping behavior of our Android parser can be found in our documentation guide here: https://docs.transifex.com/formats/android-xml#escape-behavior