Skip to content

Instantly share code, notes, and snippets.

@Sardorbekcyber
Created May 25, 2023 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sardorbekcyber/dfe89b625c05eafb46de5f658207d08d to your computer and use it in GitHub Desktop.
Save Sardorbekcyber/dfe89b625c05eafb46de5f658207d08d to your computer and use it in GitHub Desktop.
object LocaleHelper {
fun setLocale(context: Context?): Context {
return setAppLocale(context!!, Pref(context).lang)
}
private fun setAppLocale(
context: Context,
locale: String
): Context {
val res = context.resources
val dm = res.displayMetrics
val conf = res.configuration
conf.setLocale(Locale(locale.lowercase(Locale.getDefault())))
@Suppress("DEPRECATION")
res.updateConfiguration(conf, dm)
return context
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment