Skip to main content

Search 436 pages — tools, formats, elements, namespaces, directory, comparisons, XPath, datatypes, glossary, parse errors, schema errors, use cases, guides, blog and product.

XML format

Android strings

Android's translatable string resources, where apostrophes must be escaped and placeholders need XLIFF markup to survive translation.

res/values/strings.xml holds an Android app's user-visible text, with one file per locale. It is the source document for every translation workflow an app has, which is why it borrows from XLIFF: <xliff:g> marks the runs a translator must not touch, such as format specifiers and product names.

The escaping rules catch people out more than the structure does. Android applies its own layer of escaping on top of XML's, so an apostrophe in ordinary prose has to be escaped with a backslash even though XML is perfectly happy with it — and the failure is a build error in a file that looks correct.

Constraints that bite

  • Apostrophes and double quotes need a backslash escape, on top of XML escaping. A bare ' is a resource compiler error.
  • A string with more than one format specifier must number them (%1$s, %2$s) so translators can reorder them.
  • Wrap anything that must not be translated in <xliff:g id="…">, or it will come back localised.
  • Mark strings that should not be sent for translation with translatable="false".
  • An @ or ? at the start of a value is a resource reference; escape it with a backslash to use it literally.
Root element
<resources>
Media type
application/xml
Extensions
.xml
Namespaces
  • urn:oasis:names:tc:xliff:document:1.2
XMLDir label

Specification: Android string resources

A minimal valid document

Every example on this site is checked against the same parser the workspace uses, so what you see below is known to be well-formed.

android-strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
  <string name="app_name" translatable="false">Example</string>
  <string name="greeting">Hello, <xliff:g id="name" example="Ada">%1$s</xliff:g>!</string>
  <string name="cannot_open">Can\'t open that file</string>
  <plurals name="items">
    <item quantity="one">%1$d item</item>
    <item quantity="other">%1$d items</item>
  </plurals>
</resources>

Get started

Bring order to the XML your team can't afford to ignore.

Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.