Android Jetpack Compose Internationalization (Support Multiple Languages)

String Value files

  • res/values/strings.xml (default)
  • res/values-ms/strings.xml (malay)
  • res/values-zh/strings.xml (chinese)

NOTE: You can create these resource files via File -> New -> Android Resource File, under Available qualifiers select Locale -> Language Region, put in strings as File name then click OK.

Open res/values/strings.xml in Android Studio will highlight string name which is not translated. Click Open editor on the top-right corner will show the translation in table format, where you can fill in the translation value without the need to open each individual file.

Usage in Jetpack Compose

Text(stringResource(R.string.username))

NOTE: You can right click on a string (e.g. "Username") in Android Studio and click Extract string resource to automatically convert string to entry in strings.xml

OutlinedTextField(    value =  username,    onValueChange = { username = it },    label = { Text(stringResource(R.string.username)) })
Text(stringResource(item.username))

Non-compose Usage

val context = LocalContext.currentLaunchedEffect {  val brand = context.getString(R.string.brand)}

NOTE: Read the following resources for more complex use case

References:

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.