XLIFF (.xlf, .xliff)

Updated 3 months ago ​by Artis Melko

Currently we support XLIFF files (.xlf, .xliff) version 1.2 as per XLIFF specification. Some XLIFF usage examples are:

Import

As the file is imported, we try to find the source and target language tags and match them against existing languages. If only one of either source or target languages is defined in the file, we import the language specified, however XLIFF specifications indicates both source and target must be specified. In case Lokalise does not properly detect the language of uploaded files automatically, turn off the "Auto-detect" option at the upload dialog. Specifying the language manually would assume target language is the one you set.

Export

Select appropriate platform's format when exporting. Choosing Angular XLIFF causes plurals (see below) to be exported in ICU format. As for the other XLIFF formats, plurals will be exported as JSON object with keys and values.

Elements supported 

The XLIFF specification is pretty tl;dr so we support the most popular stuff. Non-supported information or elements will not be saved. The context and notes will be saved as custom key attributes along with some other information for Angular XLIFF. The supported elements are:

Plural support

For Angular we support ICU message formated plurals. Currently that is the predefined set of plural forms according to the Unicode CLDR Project which are described in the Plural Rules specification. Each language has its own set of tags specified in the Language Plural Rules

Supported forms are:

  • zero
  • one
  • two
  • few
  • many
  • other

Forms like =0 or =404 will be lost at import.

Read more about plurals in our docs article.

Custom attributes

You can easily set XLIFF attributes using a handy JSON editor we've packed our key editor with. Follow the examples below.


Sample data

An XLIFF file example with English as the source language with 2 plural forms and Arabic as the target language with 6 plural forms:

<!--?xml version="1.0" encoding="UTF-8" ?-->
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
    <file source-language="en" target-language="ar" datatype="plaintext" original="user_section.tmpl">
        <body>
            <trans-unit id="header" datatype="html">
                <source>Hello</source>
                <target> ... </target>
                <context-group purpose="location">
                    <context context-type="sourcefile">app/app.component.ts</context>
                    <context context-type="linenumber">14</context>
                </context-group>
                <note priority="1" from="description">Sample header</note>
                <note priority="1" from="meaning">Welcome visitors</note>
            </trans-unit>
            <trans-unit id="wolves" datatype="html">
                <source>{wolves, plural, one {one} other {wolves}}</source>
                <target>{wolves, plural, zero {...} one {...} two {...} few {...} many {...} other {...}}</target>
            </trans-unit>
        </body>
    </file>
</xliff>

A full example of custom attributes in JSON with 1 context group and 2 notes:

{
    "datatype": "html",
    "context-groups": [
        {
            "contexts": [
                {
                    "context-type": "sourcefile",
                    "value": "app/app.component.ts"
                },
                {
                    "context-type": "linenumber",
                    "value": "1"
                }
            ],
            "purpose": "location"
        }
    ],
    "notes": [
        {
            "value": "An introduction header for this sample",
            "priority": "1",
            "from": "description"
        },
        {
            "value": "User welcome",
            "priority": "1",
            "from": "meaning"
        }
    ]
}

How did we do