tutorials/android-xml
Android XML Localization
Complete guide to localizing Android apps with LocEngine
Overview
Android applications store all translatable text in XML resource files. LocEngine provides comprehensive support for scanning, extracting, and injecting translations into Android projects, including support for plural strings, string arrays, and resource qualifiers.
Key Features
đ Full Resource Support
Complete support for strings.xml, plurals.xml, arrays.xml, and all resource qualifiers (values-fa, values-ar, values-en-rUS, etc.)
đ Smart Detection
Automatically detects hardcoded strings in Java/Kotlin code and suggests moving them to resources
đ Language Management
Easily add new languages, manage translations across all resource folders, and ensure consistency
đ Safe Injection
Automatically inject translations back into the correct resource files with backup and rollback
Working with String Resources
Basic string resources are stored in res/values/strings.xml:
<resources>
<string name="app_name">My Awesome App</string>
<string name="welcome_message">Welcome to our application!</string>
<string name="button_save">Save Changes</string>
<string name="button_cancel">Cancel</string>
<string name="user_greeting">Hello, %s!</string>
</resources>
Adding New Languages
LocEngine automatically creates language-specific resource folders:
âââ values/ (default - usually English)
â âââ strings.xml
âââ values-fa/ (Persian)
â âââ strings.xml
âââ values-ar/ (Arabic - RTL)
â âââ strings.xml
âââ values-es-rMX/ (Mexican Spanish)
â âââ strings.xml
âââ values-pt-rBR/ (Brazilian Portuguese)
âââ strings.xml
Working with Plurals
Android's plural system handles language-specific quantity rules:
<plurals name="number_of_messages">
<item quantity="one">%d message</item>
<item quantity="other">%d messages</item>
</plurals>
<!-- res/values-fa/strings.xml (Persian) -->
<plurals name="number_of_messages">
<item quantity="one">%d ŮžŰا٠</item>
<item quantity="other">%d ŮžŰا٠</item>
</plurals>
String Arrays for Lists
<item>Monday</item>
<item>Tuesday</item>
<item>Wednesday</item>
<item>Thursday</item>
<item>Friday</item>
<item>Saturday</item>
<item>Sunday</item>
</string-array>
Detecting Hardcoded Strings
LocEngine finds strings directly in your code and suggests moving them to resources:
TextView textView = findViewById(R.id.textView);
textView.setText("Welcome to our app!");
// After (using resources)
TextView textView = findViewById(R.id.textView);
textView.setText(R.string.welcome_message);
RTL Language Support
Android has excellent RTL support. LocEngine helps you manage RTL-specific resources:
- Automatic mirroring of layouts for RTL languages
- Support for start/end attributes instead of left/right
- RTL-aware string validation
- Special handling for numbers and punctuation in RTL context
Integration with Android Studio
LocEngine works seamlessly with Android projects:
- Preserves Gradle build files and project structure
- Works with both Java and Kotlin
- Compatible with AndroidX and support libraries
- No changes to your build process required