Multi-Language Support

As we all know Android phones are used by all kinds of people. So making apps in their language will make the user comfortable.

Watch this here

This is what we are going to show to users according to their preference

    Welcome to "CodeAndroid"       // English

    "CodeAndroid" க்கு வருக         // Tamil
    "CodeAndroid" में आपका स्वागत है    // Hindi

    Bienvenue dans "CodeAndroid"     // French

    Bienvenido a "CodeAndroid"       // Spanish
We need to keep equalent language text in its appropriate string.xml file under our "res" folder. Also we must add the string resource link in XML file.
        <string name="welcome">Welcome to "CodeAndroid"</string>

        <string name="welcome">"CodeAndroid" க்கு வருக</string>

        <string name="welcome">"CodeAndroid" में आपका स्वागत है</string>

        <string name="welcome">Bienvenue dans "CodeAndroid"</string>

        <string name="welcome">Bienvenido a "CodeAndroid"</string>


Database Insertion :

we have created a method called "insertData" for inserting data into database. We need to pass a ContentValue for inserting data. After inserting we will get the last inserted row id as result. So I am checking the result. "insert" will return -1 when something goes wrong while insertion.
    import android.os.Build
    import android.annotation.TargetApi
    import android.content.Context
    import android.content.ContextWrapper
    import android.content.res.Configuration
    import java.util.*

    class MyContextWrapper(base: Context) : ContextWrapper(base) {
        companion object {

            fun wrap(ctx: Context, language: String): ContextWrapper {
                var context = ctx
                val config = context.resources.configuration
                val sysLocale: Locale?
                sysLocale = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                } else {
                if (language != "" && sysLocale.language != language) {
                    val locale = Locale(language)
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                        setSystemLocale(config, locale)
                    } else {
                        setSystemLocaleLegacy(config, locale)

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                    context = context.createConfigurationContext(config)
                } else {
                    context.resources.updateConfiguration(config, context.resources.displayMetrics)
                return MyContextWrapper(context)

            private fun getSystemLocaleLegacy(config: Configuration): Locale {
                return config.locale

            fun getSystemLocale(config: Configuration): Locale {
                return config.locales.get(0)

            private fun setSystemLocaleLegacy(config: Configuration, locale: Locale) {
                config.locale = locale

            fun setSystemLocale(config: Configuration, locale: Locale) {

12700 Subscribers