Android XML resources

AI translation for Android XML resource files with Lingo.dev CLI

What are Android XML resources?

Android uses XML-based resource files to store string resources for localization. These files are typically stored in res/values/ directories with locale-specific subdirectories (e.g., res/values-es/ for Spanish).

For example:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">MyApp</string>
    <string name="welcome_message">Hello, world!</string>
    <string-array name="color_names">
        <item>Red</item>
        <item>Green</item>
    </string-array>
    <plurals name="notification_count">
        <item quantity="one">%d new message</item>
        <item quantity="other">%d new messages</item>
    </plurals>
</resources>

Note: Strings marked with translatable="false" are excluded from translation and will only appear in the source locale files.

What is Lingo.dev CLI?

Lingo.dev CLI is a free, open-source CLI for translating apps and content with AI. It's designed to replace traditional translation management software while integrating with existing pipelines.

To learn more, see Overview.

About this guide

This guide explains how to translate Android XML resource files with Lingo.dev CLI.

You'll learn how to:

  • Create a project from scratch
  • Configure a translation pipeline
  • Generate translations with AI

Prerequisites

To use Lingo.dev CLI, ensure that Node.js v18+ is installed:

❯ node -v
v22.17.0

Step 1. Set up a project

In your project's directory, create an i18n.json file:

{
  "$schema": "https://lingo.dev/schema/i18n.json",
  "version": "1.10",
  "locale": {
    "source": "en",
    "targets": ["es"]
  },
  "buckets": {}
}

This file defines the behavior of the translation pipeline, including what languages to translate between and where the localizable content exists on the file system.

To learn more about the available properties, see i18n.json.

Step 2. Configure the source locale

The source locale is the original language and region that your content was written in. To configure the source locale, set the locale.source property in the i18n.json file:

{
  "$schema": "https://lingo.dev/schema/i18n.json",
  "version": "1.10",
  "locale": {
    "source": "en",
    "targets": ["es"]
  },
  "buckets": {}
}

The source locale must be provided as a BCP 47 language tag.

For the complete list of the locale codes that Lingo.dev CLI supports, see Supported locale codes.

Step 3. Configure the target locales

The target locales are the languages and regions you want to translate your content into. To configure the target locales, set the locale.targets property in the i18n.json file:

{
  "$schema": "https://lingo.dev/schema/i18n.json",
  "version": "1.10",
  "locale": {
    "source": "en",
    "targets": ["es"]
  },
  "buckets": {}
}

Step 4. Create the source content

If you haven't already, create one or more Android XML resource files that contain the content to be translated.

In the case of Android XML resource files, the following requirements apply:

  • Files must be valid XML with a <resources> root element.
  • String resources are defined with <string name="key">value</string> tags.
  • String arrays use <string-array name="key"><item>value</item></string-array> structure.
  • Plurals use <plurals name="key"><item quantity="one|other">value</item></plurals> structure.
  • Elements marked with translatable="false" will not be translated.
  • Supports boolean (<bool>) and integer (<integer>) resource types.
  • CDATA sections and HTML entities are preserved.

Step 5. Create a bucket

  1. In the i18n.json file, add an "android" object to the buckets object:

    {
      "$schema": "https://lingo.dev/schema/i18n.json",
      "version": "1.10",
      "locale": {
        "source": "en",
        "targets": ["es"]
      },
      "buckets": {
        "android": {}
      }
    }
    
  2. In the "android" object, define an array of one or more include patterns:

    {
      "$schema": "https://lingo.dev/schema/i18n.json",
      "version": "1.10",
      "locale": {
        "source": "en",
        "targets": ["es"]
      },
      "buckets": {
        "android": {
          "include": ["./[locale]/example.xml"]
        }
      }
    }
    

    These patterns define which files to translate.

    The patterns themselves:

    • must contain [locale] as a placeholder for the configured locale
    • can point to file paths (e.g., "[locale]/strings.xml")
    • can use asterisks as wildcard placeholders (e.g., "[locale]/*.xml")

    Recursive glob patterns (e.g., **/*.xml) are not supported.

Step 6. Configure an LLM

Lingo.dev CLI uses large language models (LLMs) to translate content with AI. To use one of these models, you need an API key from a supported provider.

To get up and running as quickly as possible, we recommend using Lingo.dev Engine — our own, hosted platform that offers 10,000 tokens of free, monthly usage:

  1. Sign up for a Lingo.dev account.

  2. Run the following command:

    npx lingo.dev@latest login
    

    This will open your default browser and ask you to authenticte.

  3. Follow the prompts.

Step 7. Generate the translations

In the directory that contains the i18n.json file, run the following command:

npx lingo.dev@latest run

This command:

  1. Reads the i18n.json file.
  2. Finds the files that need to be translated.
  3. Extracts the translatable content from the files.
  4. Uses the configured LLM to translate the extracted content.
  5. Writes the translated content back to the file system.

The first time translations are generated, an i18n.lock file is created. This file keeps track of what content has been translated, preventing unnecessary retranslations on subsequent runs.

Example

en/example.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">MyApp</string>
    <string name="welcome_message">Hello, world!</string>
    <string name="button_text">Get Started</string>

    <string name="api_endpoint" translatable="false">https://api.example.com</string>

    <string-array name="color_names">
        <item>Red</item>
        <item>Green</item>
        <item>Blue</item>
    </string-array>

    <plurals name="notification_count">
        <item quantity="one">%d new message</item>
        <item quantity="other">%d new messages</item>
    </plurals>
</resources>

es/example.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">MyApp</string>
    <string name="welcome_message">¡Hola, mundo!</string>
    <string name="button_text">Comenzar</string>

    <string name="api_endpoint" translatable="false">https://api.example.com</string>

    <string-array name="color_names">
        <item>Rojo</item>
        <item>Verde</item>
        <item>Azul</item>
    </string-array>

    <plurals name="notification_count">
        <item quantity="one">%d mensaje nuevo</item>
        <item quantity="other">%d mensajes nuevos</item>
    </plurals>
</resources>

i18n.json

{
  "$schema": "https://lingo.dev/schema/i18n.json",
  "version": "1.10",
  "locale": {
    "source": "en",
    "targets": ["es"]
  },
  "buckets": {
    "android": {
      "include": ["./[locale]/example.xml"]
    }
  }
}

i18n.lock

version: 1
checksums:
  ec06a6ebae97ffd5f7afc99d9a8f051b:
    app_name: 7dc70110429d46e3685f385bd2cc941c
    welcome_message: 0468579ef2fbc83c9d520c2f2f1c5059
    button_text: 1d5f030c4ec9c869e647ae060518b948
    html_snippet: f060191b1af70b3848106a4df91f43cd
    apostrophe_example: 997099339b144b06266f8da411de8d93
    cdata_example: ba876d1379f854628eaebf67ea330ccc
    color_names/0: bace0083b78cdb188523bc4abc7b55c6
    color_names/1: 482ff383a4258357ba404f283682471d
    color_names/2: a5cf034b2d370a976119335cd99f4217
    mixed_items/0: 9278f79dfb062c6c04f6395108907816
    mixed_items/1: 9823a57cbe6e6e84c1d025ce24a1eec4
    notification_count/one: fe0aceb70f334c52a87937c36898a1d0
    notification_count/other: 13acfd95b16962ebe1f67dcd343513e1