Android uses a custom xml resource format for mobile app localization
The preferred way to automate the Android app translation with GL Strings is by using the GL Strings Android SDK. Alternatively, if you can not use the SDK, you can also use the GL Strings Localization CLI to automate the up and download of the android string resource files. A string resource provides text strings for your application with optional text styling and formatting as well as support for localizable string arrays and pluralization. You can create and edit base strings directly in Android Studio and the translated strings can be referenced in your ui layout files.
Website: https://developer.android.com/guide/topics/resources/string-resource
| Specification | Value |
|---|---|
| File Extension | .xml |
| CLI Format Key | android_xml |
| CLI Supported | true |
| SDK Supported | true |
| Pluralization Supported | true |
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="empty_string_key"/>
<string name="with_description_key">This key has a description in some file-formats.</string>
<string name="with_line_break_key">This key has a line break
in it.</string>
<string name="nested_key.level_one_a.level_two">A deeply nested key.</string>
<string name="nested_key.level_one_b">A nested key.</string>
<plurals name="plural_key">
<item quantity="one">Plural key one</item>
<item quantity="other">Plural key other</item>
<item quantity="zero">Plural key zero</item>
</plurals>
<string-array name="array_key">
<item>first entry</item>
<item>second entry</item>
<item>third entry</item>
</string-array>
<string name="simple_key">Most basic translation.</string>
</resources>
Compose Multiplatform uses the same strings.xml structure for Android, iOS, desktop and web (string, plurals, string-array, %1$s placeholders and values-<language> folders), but it reads the text differently than Android. It only decodes \n, \t, \uXXXX and \\, so Android escapes like \' show up as they are in the app.
To export files for Compose Multiplatform, enable the Compose Multiplatform option in the export dialog or set "compose_multiplatform": true on the pull target in the CLI. The option only changes the export: backslashes are written so that Compose Multiplatform shows the same text as Android, so strings that were imported before do not need to be imported again. Importing a Compose Multiplatform file works with the regular Android XML import.
| Value in GL Strings | Android export | Compose Multiplatform export |
|---|---|---|
it's "new" |
it\'s \"new\" |
it's "new" |
\@user, \? |
\@user, \? |
@user, ? |
Review & Submit |
Review & Submit |
Review & Submit |
a < b |
a < b |
a < b |
C:\new |
C:\\new |
C:\\new |
3 \u2022 ok |
3 \u2022 ok |
3 \u2022 ok |
<![CDATA[<b>it's</b>]]> |
<![CDATA[<b>it\'s</b>]]> |
<![CDATA[<b>it's</b>]]> |
| a line break | \n |
\n |
Example CLI configuration:
{
"app": {
"access_token": "5b1f..!..2ab",
"base_language": "en",
"pull": {
"target": [
{
"exclude_languages": ["en"],
"file_format": "android_xml",
"compose_multiplatform": true,
"path": "./composeApp/src/commonMain/composeResources/values-<language>/strings.xml"
}
]
}
}
}