Its0601TechAttrAndTrans

From W3C Wiki


ITS WG Collaborative editing page

Avoid translatable attributes

Whenever possible, a schema should ensure that translatable text is stored in elements rather than attributes.

There are a number of issues related to storing translatable text in attribute values. Some of them are:

  • The language identification mechanism (i.e. xml:lang) applies to the content of the element where it is declared, including its attribute values. If the text of an attribute is in a different language than the text of the element content, one cannot set the language for both correctly.
  • In some languages, bidirectional markers may be needed to provide a correct display. Tags cannot be used within an attribute value. One can use Unicode control characters instead, but this is not recommended (see the W3C Note and Unicode Technical Report Unicode in XML & Other Markup Languages).
  • It is difficult to apply to the text of the attribute value meta-information such as no-translate flags, designer's notes, etc.
  • The difficulty to attach unique identifiers to translatable attribute text makes it more complicated to use ID-based leveraging tools.
  • Translatable attributes can create problems when they are prepared for localization because they can occur within the content of a translatable element, breaking it into different parts, and possibly altering the sentence structure.

All these potential problems do not occur when the text is the content of an element rather than the value of an attribute.

Technique: Do no put translatable text in attributes

Use elements to store all transltable text.

Make sure all translatable text is stored as element content. For example, do not allow this:


<image src="elephants.png
 alt="Elephants bathing in the Zambezi river" />


but, instead design <image> for this:


<image src="elephants.png>Elephants bathing 
in the Zambezi river</image>