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:
{
"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:
- Rename your default
values/
folder to match your source locale (e.g.,values-en/
) - Create a symbolic link from
values/
to your source locale folder:
# 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:
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:
npx replexica@latest i18n
Replexica will:
- Read your source XML file (e.g.,
res/values-en/strings.xml
); - Identify new or changed strings;
- Translate them to your target languages;
- 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:
- It respects the standard Android resource file structure, fitting into your existing development process;
- It uses AI to understand context, providing more accurate translations than traditional methods;
- It's incremental, only translating what's new or changed, which is crucial for large apps with frequent updates.
Pro Tips
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>
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>
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.