Docs / Translate / Android strings.xml
Translate Android strings.xml
Translate res/values/strings.xml into values-<lang> folders, with %1$s arguments, <plurals>, <xliff:g> and apostrophe escaping handled, and translatable="false" strings skipped.
How it works
localize-dev translate reads res/values/strings.xml, or Compose Multiplatform’s composeResources/values/, and writes values-ru/strings.xml, values-pt-rBR/strings.xml and the rest. Strings marked translatable="false" are left out, and the XML comment above a string goes to the model as context.
Text is unescaped before translation and escaped again after it, so You\'ve stays valid and an apostrophe in a French or Italian translation doesn’t break the build. CDATA stays CDATA.
Before and after
Real output of localize-dev translate --locales ru on the first file. Russian needs few and many, the app name isn’t translated, and the <xliff:g> span is kept as written.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name" translatable="false">Trailmap</string>
<!-- Shown on the home screen above the list of trails -->
<string name="home_title">Trails near you</string>
<string name="saved_trail">You\'ve saved %1$s to <xliff:g id="list">%2$s</xliff:g></string>
<plurals name="trails_found">
<item quantity="one">%d trail found</item>
<item quantity="other">%d trails found</item>
</plurals>
</resources><?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="home_title">Трейлы рядом с вами</string>
<string name="saved_trail">Вы сохранили %1$s в <xliff:g id="list">%2$s</xliff:g></string>
<plurals name="trails_found">
<item quantity="one">%d трейл найден</item>
<item quantity="few">%d трейла найдено</item>
<item quantity="many">%d трейлов найдено</item>
<item quantity="other">%d трейлов найдено</item>
</plurals>
</resources>What stays intact
%1$s,%dand other format arguments, checked<xliff:g>spans, kept exactly as written<plurals>with the quantities each language uses- Inline markup like
<b>, and CDATA where the source has it
Common mistakes, and how they’re avoided
Unescaped apostrophes
“l’application” has to be written l\'application in strings.xml, or the resource compiler fails the build. Every translation is escaped on its way into the file.
Missing quantities
Russian, Polish and Arabic use few and many. With only one and other, getQuantityString falls back to other for counts like 3, and the grammar is wrong.
Translating what should stay
App names and <xliff:g> content, such as a product name or a variable, often get translated. translatable="false" strings are skipped, and <xliff:g> spans are masked so the model never sees them as text.
Run it
In the folder that holds your locale files. Languages without a file yet get one. --dry-run shows what would change first.
npx localize-dev login
# Preview, then write the missing translations
npx localize-dev translate --dry-run -l es,fr,de
npx localize-dev translate -l es,fr,deThen keep it complete in CI. This needs no API key and fails when a language is missing translations:
npx localize-dev check --only translationsFree for 1,000 strings a month. A string counts once however many languages it goes into. Create a free account
Guides for apps that use this format
When the copy is still hardcoded in your code, localize-dev run moves it into this format first.