XML
XML localization with XPath control.
Choose with XPath which elements and attributes hold user-facing text, translate only those values, keep translations matched by a key, and write settings_de.xml with the structure untouched. Your application keeps the file format and how it loads it.
- Input
.xmlfiles and an XPath that selects the text- Output
settings_de.xmlfor each language, same structure- Key
- An XPath key, such as
./@id, matches translations on update - Runtime
- Your application loads the file for the user's language
On this page
Tutorial
Localize XML files with Lingobit, step by step.
Four steps from settings.xml to a translated file for each language.
An XPath picks the values, a key keeps them matched.
Without a rule, Lingobit offers every text node and every attribute of the file, IDs and numbers included. An XPath such as //message narrows it to the text your users see, and a key expression such as ./@id names each value, so translations stay matched when the file changes. Lingobit writes the same file with the values translated.
Lingobit does
- Translates the elements and attributes your XPath and filters select.
- Reuses earlier translations and the translation memory.
- Checks placeholders, empty and too long translations, and more.
- Writes
settings_de.xmlfor each language, with comments and layout kept.
Your application keeps
- The XML format and its schema.
- Loading the file for the user's language.
- Which values are text and which are settings.
- The final test in the running application.
Reference
XPath patterns for common files.
Lingobit uses XPath 1.0. In a file with a default namespace, address its elements with the prefix defns, as in //defns:message; declare other prefixes under Namespaces.
| The text is in | Select nodes to translate | Key expression |
|---|---|---|
<message id="saved">Saved.</message> | //message | ./@id |
<folder key="docs"><title>Documents</title> | //folder/title | ../@key |
<button id="send" text="Send"/> | //button/@text | ../@id |
<caption translate="true">Setup</caption> | //caption[@translate="true"] | — |
A file with xmlns="…" | //defns:message | ./@id |
XML settings.
Each XML file has its own settings in the project, under these names.
| Setting | What it does |
|---|---|
| Parser | Namespaces, Select nodes to translate, Key expression, and Parse comments |
| Node Filter, Attribute Filter | Allow or deny elements and attributes by name; the attributes of selected elements are offered unless denied here |
| XPath Mapping | Sends the text of selected nodes to another parser, for example HTML stored inside XML |
| Encoding and output | UTF-8 by default, detected from the file; the output name, by default settings_de.xml in the output folder |
Do and don't.
Do
- Set an XPath for every file, so IDs, numbers, and settings stay out of translation.
- Set a key expression when the file has IDs: translations stay matched when elements move.
- Deny technical attributes, such as
idorstyle, in the Attribute Filter. - Name the output files the way your application loads them.
Don't
- Translate a whole XML file without an XPath.
- Edit
settings_de.xmlby hand: the next Create overwrites it. - Build sentences in code from translated pieces.
- Send XML files to translators: they work in Lingobit.
Troubleshooting.
| Symptom | Likely cause | What to do |
|---|---|---|
| IDs and numbers appear as strings | The file has no XPath, so every text node and attribute is offered | Set Select nodes to translate, and deny technical attributes |
| The XPath selects nothing | The file has a default namespace | Write the elements with the prefix defns, as in //defns:message |
| Translations are New again after an update | There is no key expression, and the text or the place of the element changed | Set a key expression such as ./@id |
| The application stays in English | The translated file is not where the application looks, or its name differs | Change the output name in the file's settings to the name your application loads |
The XML sample.
Localizer installs an XML and XSL sample with its project, in German and French.
simple.xml, a menu of dishes: the Node Filter leaves out thepriceandcalorieselements, so only names and descriptions are translated.simple.xsl, the style sheet, with its attributes left out, andindex.html, the page that shows the result.
More about XML localization.
More XPath examples
Mixed XML resources
<item name="WelcomeTitle">
<value>Welcome</value>
<comment>Shown on the start page</comment>
</item>
Select nodes to translate: //item/value
Only <value> is translated; the comment stays out of the strings.
Key stored in a sibling element
<folder>
<key>UserDocs</key>
<title>User Documents</title>
</folder>
Select nodes to translate: //folder/title
Key expression: ../key/text()
Report definitions: skip formulas
In a report definition with a default namespace, select the visible text boxes and skip calculated expressions that start with =:
//defns:Textbox[not(starts-with(normalize-space(defns:Value), "="))]/defns:Value
Translatable and protected attributes
Prefer allowing the attributes translators need over offering all of them.
Usually translated: text tooltip caption title description
Usually protected: id name class type style width height x y binding resourceKey
Output patterns for localized XML files
Match the output name to the way your application or build loads the files. The default writes resources_de.xml into the project's output folder.
$(OutputDir)\$(SrcFileName)_$(CultureName)$(SrcFileExt) out\resources_de.xml (default)
$(OutputDir)\$(CultureName)\$(SrcFileName)$(SrcFileExt) out\de\resources.xml
$(OutputDir)\$(SrcFileName).$(CultureName)$(SrcFileExt) out\resources.de.xml
Which XML files fit
Good candidates have stable IDs or keys, clear text or value nodes, attributes that can be allowed by name, and a structure that stays predictable across releases. Take care with XML without stable keys, files that mix user-facing text with formulas, large mixed-content blocks, files regenerated from another source that overwrites translations, and XML where runtime logic depends on translated values.
Related paths
- Localization QA — Validation, placeholder checks, and more.
- HTML — Pages and templates, with markup protected.
- Release workflow — Scan for Changes and translated files for every release.
- Supported formats — XML-based formats Lingobit reads with its own rules.