XLIFF File Structure and Requirements for Import
General Requirements
- File Extension: The file must have an .xliff extension.
- XLIFF Version: XLIFF 1.2 format.
- Structure: The file must be structured as a valid XLIFF document with <file>, <body>, and <trans-unit> elements. Each <trans-unit> represents a phrase and its corresponding translations.
- Required Elements: The <source> element within each <trans-unit> is mandatory and must contain the phrase in the source language (see example below).
Required Fields
- source: Each <trans-unit> element must include a <source> field containing the phrase in the site's source language.
Optional Fields
The following fields are optional but must adhere to specific naming and structure conventions:
- Phrase key: Each <trans-unit> element can include a resname attribute to provide a unique phrase key identifier for the phrase.
- <target>: Provides translations for the phrase. This field can be left empty if no translation exists. Each <file> element should have a target-language attribute (e.g., target-language="fr" for French).
- <note>: Additional metadata such as tag or attribute details can be included here. The format must be "Tag: [tag_name], Attribute: [attribute_name]" to provide extra context for the translation.
Example of a Valid XLIFF File
This example includes two original phrases translated into French (fr) and Spanish (es), along with metadata containing their (element) tag names.
<?xml version="1.0" encoding="UTF-8"?>
<xliff version="1.2">
<file source-language="en" target-language="es" datatype="plaintext" original="messages">
<body>
<trans-unit id="1">
<source>Example phrase</source>
<target>Frase de ejemplo</target>
<note>Tag: div</note>
</trans-unit>
<trans-unit id="2">
<source>Example phrase two</source>
<target>Frase de ejemplo dos</target>
<note>Tag: div</note>
</trans-unit>
</body>
</file>
<file source-language="en" target-language="fr" datatype="plaintext" original="messages">
<body>
<trans-unit id="1">
<source>Example phrase</source>
<target>Exemple de phrase</target>
<note>Tag: div</note>
</trans-unit>
<trans-unit id="2">
<source>Example phrase two</source>
<target>Exemple de phrase deux</target>
<note>Tag: div</note>
</trans-unit>
</body>
</file>
</xliff>
Validation Rules
- Source Term: Each <trans-unit> must have a <source> element, and cannot be empty or contain only whitespace.
- Valid Language Codes: The target-language attribute in the <file> element must follow the ISO 639-1 & country codes in ISO 3166-1 Alpha-2 standard (e.g., es-MX, fr).
- Matching Language Codes: Ensure that for each <source> term, the corresponding <target> term exists if a translation is available.
Additional Notes
If the <target> element is missing or empty for a particular language, the system will still process the file, but the phrase will be treated as if there is no translation for that language.