Skip to content

Android Resource Translation

Replexica seamlessly handles Android resource files, making it easy to localize your Android apps without changing your existing workflow.

Setting Up

Start by creating an i18n.json config file in your project root:

json
{
  "version": 1,
  "locale": {
    "source": "en",
    "targets": ["es", "fr", "de"]
  },
  "buckets": {
    "android": {
      "include": ["res/values-[locale]/strings.xml"]
    }
  }
}

Important: Default Resources Folder

Android requires a default values/ folder (without a locale suffix) for your resources. However, for Replexica to work correctly:

  1. Rename your default values/ folder to match your source locale (e.g., values-en/)
  2. Create a symbolic link from values/ to your source locale folder:
bash
# If English is your source language:
mv res/values res/values-en
ln -s values-en res/values

This setup maintains Android compatibility while allowing Replexica to properly track your source language resources.

Available Languages

To see what languages Replexica supports:

bash
npx replexica@latest show locale sources  # List available source languages
npx replexica@latest show locale targets  # List available target languages

Use these to choose the right locale codes for your Android project.

Translating

With your config set, run:

bash
npx replexica@latest i18n

Replexica will:

  1. Read your source XML file (e.g., res/values-en/strings.xml);
  2. Identify new or changed strings;
  3. Translate them to your target languages;
  4. Update or create the target XML files (e.g., res/values-es/strings.xml, res/values-fr/strings.xml, res/values-de/strings.xml).

Why This Works

Replexica's approach is effective for Android resources because:

  1. It respects the standard Android resource file structure, fitting into your existing development process;
  2. It uses AI to understand context, providing more accurate translations than traditional methods;
  3. It's incremental, only translating what's new or changed, which is crucial for large apps with frequent updates.

Pro Tips

  1. String Arrays: Replexica handles string arrays in Android resource files. Your list-based translations are safe:

    xml
    <resources>
      <string-array name="planets_array">
        <item>Mercury</item>
        <item>Venus</item>
        <item>Earth</item>
        <item>Mars</item>
      </string-array>
    </resources>
  2. Plurals: Replexica understands Android's plural format:

    xml
    <resources>
      <plurals name="numberOfSongsAvailable">
        <item quantity="one">%d song found.</item>
        <item quantity="other">%d songs found.</item>
      </plurals>
    </resources>
  3. String Parameters: Replexica preserves string parameters in your translations:

    xml
    <resources>
      <string name="welcome_messages">Hello, %1$s! You have %2$d new messages.</string>
    </resources>

By leveraging these features, you can maintain a robust, scalable localization setup for your Android app, all while using the standard resource file format you're already familiar with.