fun LocaleManager.getSelectedLocale( context: Context, localeList: List<Locale> = getSupportedLocales(), ): Locale { val selectedLocale = getCurrentLocale(context)?.toLanguageTag() val defaultLocale = getSystemDefault() return if (selectedLocale == null) { defaultLocale } else { val supportedMatch = localeList .firstOrNull { it.toLanguageTag() == selectedLocale } supportedMatch ?: defaultLocale } }
Returns the locale that corresponds to the language stored locally by us. If no suitable one is found, return default.