improve resolve of language

This commit is contained in:
InsanusMokrassar 2018-09-15 18:02:48 +08:00
parent 4fc2e39451
commit 3943358db3

View File

@ -10,8 +10,25 @@ const val characteristicsFolder = "characteristics"
private val gson: Gson = GsonBuilder().create()
val availableTranslations = listOf(
"en_US"
)
private val defaultLanguage = availableTranslations.first()
private fun findSubTranslation(language: String): String {
return if (availableTranslations.contains(language)) {
return language
} else {
val localeUpper = language.split("_").first()
availableTranslations.firstOrNull {
it.startsWith(localeUpper)
} ?: defaultLanguage
}
}
fun resolveCeilsDescriptionsByLanguage(language: String = "en_US"): CeilsInfosRoot {
return load("$characteristicsFolder/$language.json").let {
return load("$characteristicsFolder/${findSubTranslation(language)}.json").let {
gson.fromJson(InputStreamReader(it), CeilsInfosRoot::class.java)
}
}