Skip to content

Instantly share code, notes, and snippets.

@ikhlaqmalik13
Created September 27, 2023 13:07
Show Gist options
  • Save ikhlaqmalik13/66abbbecfdaa0995eda4205216f450bf to your computer and use it in GitHub Desktop.
Save ikhlaqmalik13/66abbbecfdaa0995eda4205216f450bf to your computer and use it in GitHub Desktop.
Android Multi-Language Support
<!-- Add the Code in application Tag ->
<!-- This will store autostore the locale changes if you open the app for next time-->
<Application>
<!--
//.....
-->
<service
android:name="androidx.appcompat.app.AppLocalesMetadataHolderService"
android:enabled="false"
android:exported="false">
<meta-data
android:name="autoStoreLocales"
android:value="true" />
</service>
</Application>
// InCompose
onSomeActionChangeListener{
AppCompatDelegate.setApplicationLocales(
LocaleListCompat.forLanguageTags(
languageCode
)
)
}
// This action will recreate the activity and set the app language as you provide the languageCode - like hi, en, ta
// Added this in app/build.gradle.kts
android {
// ...
defaultConfig {
resourceConfigurations += mutableSetOf("en", "hi", "mr", "ta")
}
}
<!-- res/values-es/strings.xml for Spanish -->
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Mi Aplicación</string>
<string name="welcome_message">¡Bienvenido a mi aplicación!</string>
</resources>
<!-- res/values/strings.xml -->
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">My App</string>
<string name="welcome_message">Welcome to my app!</string>
</resources>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment