Magento 1 – Use of

configurationlocalisationmagento-1magento-1.9system.xml

I've noticed that some comments in the native Magento 1 system.xml files are enclosed by <![CDATA[ / ]]> tags and some are not.

For example in app/code/core/Mage/Captcha/etc/system.xml we have:

<length translate="label comment">
    ...
    <comment>Please specify 8 symbols at the most. Range allowed (e.g. 3-5)</comment>
    ...
</length>

And:

<symbols translate="label comment">
    ...
    <comment><![CDATA[Please use only letters (a-z or A-Z) or numbers (0-9) in this field. No spaces or other characters are allowed.<br />Similar looking characters (e.g. "i", "l", "1") decrease chance of correct recognition by customer.]]></comment>
    ...
</symbols>

I first thought it could be because of HTML tags in the comment but in app/code/core/Mage/Catalog/etc/system.xml we have:

<flat_catalog_product translate="label comment">
    ...
    <comment><![CDATA[Enable for reindexing a big number of SKUs]]>.</comment>
    ...
</flat_catalog_product>

So my questions are :

  • in which case one should use the CDATA tags in system configuration comments ?
  • does the use of CDATA tags affect the translations ? (understand do we have to write the CDATA tags in the translation files ?)

Best Answer

You should use CDATA to ensure the text inside it is not interpreted as XML/HTML.
But nobody restricts you to use it for every text tag.
The fact there is one or more uses of CDATA without having special chars in it may mean that someone overlooked this, or just copy pasted it from somewhere else and forgot to remove the CDATA.
You can use it as you wish.
The translation is not affected in any way by CDATA.
CDATA is ignored by the XML parser.
with or without it the array (or SimplexmlElement or any other format) will look like this:

array(
    'flat_catalog_product' => 
         array(
             'translate' => 'label copmment'
             'comment' => 'Enable for reindexing a big number of SKUs'
         )
)

Format may vary depending on the parser.

More info on CDATA.