-3

I have two language in my app urdu and english when i select english language it shows english calendar and same for urdu selection but i want to show english calendar when urdu is selected so i want to fix the language of calendar dialog e.g if locale is set to urdu calendar will in english. I use this but nothing change

            Locale.setDefault(Locale.ENGLISH);

How can i acheive this

calendar view screenshot i use > Locale.setDefault(Locale.ENGLISH); but it didn't change month language any recommendation how can i acheive it

1 Answers1

0

You need to set locale properly

first in activity:

 LocaleHelper.updateApplicationContextLocale(applicationContext, localeConfiguration, locale)

when LocaleHelper.updateApplicationContextLocale is:

 fun updateApplicationContextLocale(applicationContext: Context,
                                       localeConfiguration: Configuration,
                                       locale: Locale) {
        applicationContext.resources.updateConfiguration(localeConfiguration,
                applicationContext.resources.displayMetrics)
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            applicationContext.createConfigurationContext(localeConfiguration)
        } else {
            Locale.setDefault(locale)
            val config = applicationContext.resources.configuration
            config.locale = locale
            applicationContext.resources.updateConfiguration(config,
                    applicationContext.resources.displayMetrics)
        }
    }

and


  override fun getLocaleConfiguration(): Configuration {
        val config = Configuration()
        val locale = locale
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            config.setLocale(locale)
        } else {
            config.locale = locale
        }
        return config
    }

  override fun getLocale(): Locale {
        return Locale(currentLanguageCode)
    }


Antonis Radz
  • 3,036
  • 1
  • 16
  • 34