chore!: migrate to version 2.x

This commit is contained in:
hstyi
2025-06-13 15:16:56 +08:00
committed by GitHub
parent ca484618c7
commit 6177bbdc68
444 changed files with 18594 additions and 3832 deletions

View File

@@ -1,14 +1,13 @@
package app.termora
import org.apache.commons.lang3.LocaleUtils
import org.apache.commons.text.StringSubstitutor
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.text.MessageFormat
import java.util.*
object I18n {
object I18n : AbstractI18n() {
private val log = LoggerFactory.getLogger(I18n::class.java)
private val bundle by lazy {
private val myBundle by lazy {
val bundle = ResourceBundle.getBundle("i18n/messages", Locale.getDefault())
if (log.isInfoEnabled) {
log.info("I18n: {}", bundle.baseBundleName ?: "null")
@@ -16,7 +15,6 @@ object I18n {
return@lazy bundle
}
private val substitutor by lazy { StringSubstitutor { key -> getString(key) } }
private val supportedLanguages = sortedMapOf(
"en_US" to "English",
"zh_CN" to "简体中文",
@@ -39,24 +37,13 @@ object I18n {
return supportedLanguages
}
fun getString(key: String, vararg args: Any): String {
val text = getString(key)
if (args.isNotEmpty()) {
return MessageFormat.format(text, *args)
}
return text
override fun getBundle(): ResourceBundle {
return myBundle
}
fun getString(key: String): String {
try {
return substitutor.replace(bundle.getString(key))
} catch (e: MissingResourceException) {
if (log.isWarnEnabled) {
log.warn(e.message, e)
}
return key
}
override fun getLogger(): Logger {
return log
}