mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-14 21:18:56 +01:00
Added country/region support for locale when displayed for sources (#1240)
* Added country support for locale when displayed for sources * code review changes/comments fix
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
package eu.kanade.tachiyomi.util
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.content.res.Configuration
|
||||
import android.os.Build
|
||||
import android.os.LocaleList
|
||||
import android.view.ContextThemeWrapper
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.util.*
|
||||
@@ -45,10 +47,34 @@ object LocaleHelper {
|
||||
if (pref.isNullOrEmpty()) {
|
||||
return null
|
||||
}
|
||||
val parts = pref.split("_", "-")
|
||||
val lang = parts[0]
|
||||
val country = parts.getOrNull(1) ?: ""
|
||||
return Locale(lang, country)
|
||||
return getLocale(pref)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Display name of a string language code
|
||||
*/
|
||||
fun getDisplayName(lang: String?, context: Context): String {
|
||||
return when (lang) {
|
||||
null -> ""
|
||||
"" -> context.getString(R.string.other_source)
|
||||
"all" -> context.getString(R.string.all_lang)
|
||||
else -> {
|
||||
val locale = getLocale(lang)
|
||||
locale.getDisplayName(locale).capitalize()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*Return Locale from string language code
|
||||
|
||||
*/
|
||||
private fun getLocale(lang: String): Locale {
|
||||
val sp = lang.split("_", "-")
|
||||
return when (sp.size) {
|
||||
2 -> Locale(sp[0], sp[1])
|
||||
3 -> Locale(sp[0], sp[1], sp[2])
|
||||
else -> Locale(lang)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user