Removing multiple locale object and cleaning code

This commit is contained in:
Hritik Wadhwa 2020-03-23 02:03:18 +05:30
parent 2b07462ae1
commit e108d04903

View File

@ -23,22 +23,16 @@ import java.util.Locale
* Created by mhutti1 on 19/04/17. * Created by mhutti1 on 19/04/17.
*/ */
class BookUtils { class BookUtils {
val localeMap = Locale.getISOLanguages().associateBy({ Locale(it).isO3Language }, ::Locale) val localeMap = Locale.getISOLanguages().map(::Locale).associateBy { it.isO3Language }
// Get the language from the language codes of the parsed xml stream // Get the language from the language codes of the parsed xml stream
@Suppress("MagicNumber") @Suppress("MagicNumber")
fun getLanguage(languageCode: String): String? { fun getLanguage(languageCode: String): String {
return when { return when {
languageCode == null -> "" languageCode == null -> ""
languageCode.length == 2 -> { languageCode.length == 2 -> LanguageContainer(languageCode).languageName
LanguageContainer(languageCode).languageName languageCode.length == 3 -> localeMap[languageCode]?.displayLanguage.orEmpty()
} else -> ""
languageCode.length == 3 -> {
localeMap[languageCode]?.displayLanguage
}
else -> {
""
}
} }
} }
} }