Its0601TechLangDev

From W3C Wiki


ITS WG Collaborative editing page

Provide a way to specify language content

Use the xml:lang attribute to provide a way for document authors to specify in what language is the content of their documents. See the Language Identification section in the XML Specification for more information on xml:lang.

It is not recommended to use your own attribute to specify the language content. The xml:lang is supported by various XML technologies such as XPath, or XSL. Using a different attribute would diminish the interoperability of your documents and reduce your capability to take advantage of some XML applications.

If not the language of the content, but a natural language value as data or meta-data about something external to the document has to be specified, a different attribute than xml:lang should be used. An example is the hreflang attribute in HTML.


<a xml:lang="en" href="german.html" hreflang="de">Click here for German</a>


For further information, see [1]"

Note: The scope of the xml:lang attribute applies to both the attributes and the content of the element where it appears, therefore one cannot specify different languages for an attribute and the element content. ITS does not provide remedy for this. Instead, it is recommended to not use attribute for translatable text.

Including xml:lang in XML Schema

To include the xml:lang attribute in your XSD document, import the namespace for XML Schema together with xml.xsd in your own XSD document using the <xsd:import> element as shown below:


<xsd:schema targetNamespace="myNamespaceURI"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 xmlns:t="myNamespaceURI" elementFormDefault="qualified" xml:lang="en">
 <!-- Import for xml:lang and xml:space -->
 <xsd:import namespace="http://www.w3.org/XML/1998/namespace"
 schemaLocation="http://www.w3.org/2001/xml.xsd"/>
 ...


Once xml.xsd is imported, you can use the reference to xml:lang in any of your element declarations.


...
<xsd:element name="myDoc">
 <xsd:complexType>
  <xsd:sequence maxOccurs="unbounded">
   <xsd:element name="section" type="t:Section_Type"/>
  </xsd:sequence>
  <xsd:attribute name="version" type="xsd:string" use="required"/>
  <xsd:attribute ref="xml:lang" use="optional"/>
 </xsd:complexType>
 ...


Including xml:lang in Relax NG

In RELAX NG, declare xml:lang directly in your schema.


<define name="att.global.attribute.xmllang">
 <optional>
  <attribute name="xml:lang">
   <a:documentation>indicates the language of the element content using the
      codes from RFC 3066
   </a:documentation>
   <ref name="data.language"/>
  </attribute>
 </optional>
</define>
<define name="data.language">
 <data type="language"/>
</define>


Then, you can reference this declaration in any of your element declarations.


<element name="myDoc">
...
 <ref name="att.global.attribute.xmllang"/>
</element>


Including xml:lang in XML DTD

For example, to add xml:lang to a <para> element you can specify the following DTD constructs:


<!ELEMENT para (#PCDATA) >
<!ATTLIST para
          xml:lang CDATA #IMPLIED >