Created
September 27, 2023 13:07
-
-
Save ikhlaqmalik13/66abbbecfdaa0995eda4205216f450bf to your computer and use it in GitHub Desktop.
Android Multi-Language Support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Added this in app/build.gradle.kts | |
android { | |
// ... | |
defaultConfig { | |
resourceConfigurations += mutableSetOf("en", "hi", "mr", "ta") | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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