localize.dev

Docs / Android

Android string resources, automated

Move hardcoded text in Android layouts and Jetpack Compose into string resources: strings.xml per language, stringResource() calls, and the per-app language list.

How it works

In layouts and menus, android:text, hint, contentDescription and title become @string/…. In Compose, Text("…") and contentDescription = "…" inside @Composable functions become stringResource(R.string.…, args); toasts use context.getString.

Placeholders become %1$s, %2$s… numbered by their order in the source text, so a translation can reorder them.

Before and after

The engine’s real output for this file. In a real run, the hosted model names the keys from context.

app/src/main/java/com/acme/shop/ui/Cart.kt · before
@Composable
fun Cart(name: String) {
    Column {
        Text("Welcome back, $name!")
        Text(text = "Checkout")
    }
}
app/src/main/java/com/acme/shop/ui/Cart.kt · after
import androidx.compose.ui.res.stringResource

@Composable
fun Cart(name: String) {
    Column {
        Text(stringResource(R.string.cart_welcome_back, name))
        Text(text = stringResource(R.string.cart_checkout))
    }
}
res/values/strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="cart_welcome_back">Welcome back, %1$s!</string>
    <string name="cart_checkout">Checkout</string>
</resources>

What the setup adds

The first run sets up Android string resources if the project doesn’t have it yet:

  • res/values/strings.xml and res/values-<lang>/strings.xml
  • res/xml/locales_config.xml and android:localeConfig, so Android 13+ lists the languages in the app’s settings

Run it

The CLI needs Node.js 22 or later, nothing else: npx runs it without adding a package.json to the project. No Node on your machine? The GitHub Action below runs it for you.

npx localize-dev login

# Preview, then write the changes
npx localize-dev run --dry-run -l es,fr,de
npx localize-dev run -l es,fr,de

# Or open a pull request instead
npx localize-dev pr -l es,fr,de

Or add the GitHub Action and get a pull request on every push. Try it on your own code first in the playground.