Last active
September 9, 2025 14:06
-
-
Save gptshubham595/4d7617d00cb13e06b529e90153b1f183 to your computer and use it in GitHub Desktop.
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
| object LocaleHelper { | |
| fun setLocale(context: Context, languageCode: String) { | |
| val appLocale: LocaleListCompat = LocaleListCompat.forLanguageTags(languageCode) | |
| AppCompatDelegate.setApplicationLocales(appLocale) | |
| val sharedPref = context.getSharedPreferences("Settings", Context.MODE_PRIVATE) | |
| sharedPref.edit(commit = true) { | |
| putString("language", languageCode) | |
| } | |
| } | |
| fun loadLocale(context: Context) { | |
| val sharedPref = context.getSharedPreferences("Settings", Context.MODE_PRIVATE) | |
| val language = sharedPref.getString("language", "") ?: "" | |
| if (language.isNotEmpty()) { | |
| val appLocale = LocaleListCompat.forLanguageTags(language) | |
| AppCompatDelegate.setApplicationLocales(appLocale) | |
| } | |
| } | |
| fun getLanguage(context: Context): String { | |
| val sharedPref = context.getSharedPreferences("Settings", Context.MODE_PRIVATE) | |
| return sharedPref.getString("language", "en") ?: "en" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment