diff --git a/module/module-lang/src/main/kotlin/taboolib/module/lang/inline/InlineLanguage.kt b/module/module-lang/src/main/kotlin/taboolib/module/lang/inline/InlineLanguage.kt index 8f5fe3909..70818e693 100644 --- a/module/module-lang/src/main/kotlin/taboolib/module/lang/inline/InlineLanguage.kt +++ b/module/module-lang/src/main/kotlin/taboolib/module/lang/inline/InlineLanguage.kt @@ -3,6 +3,7 @@ package taboolib.module.lang.inline import taboolib.common.platform.function.dev import taboolib.library.configuration.ConfigurationSection import taboolib.module.configuration.util.getStringColored +import taboolib.module.configuration.util.getStringListColored /** * 内嵌语言文件,配合 Configuration 使用。 @@ -30,7 +31,7 @@ fun ConfigurationSection.getTranslatedString(path: String): TranslatedString? { fun ConfigurationSection.getTranslatedStringList(path: String): TranslatedStringList? { val node = getLanguageNode(path) ?: return null - val defaultValue = getStringList(path) + val defaultValue = if (isList(path)) getStringListColored(path) else getStringColored(path)?.lines() ?: emptyList() return TranslatedStringList(node, defaultValue) } diff --git a/module/module-lang/src/main/kotlin/taboolib/module/lang/inline/Translated.kt b/module/module-lang/src/main/kotlin/taboolib/module/lang/inline/Translated.kt index dc5388eaa..b8c861390 100644 --- a/module/module-lang/src/main/kotlin/taboolib/module/lang/inline/Translated.kt +++ b/module/module-lang/src/main/kotlin/taboolib/module/lang/inline/Translated.kt @@ -1,6 +1,7 @@ package taboolib.module.lang.inline import taboolib.module.lang.Language +import java.util.function.Function /** * Codex @@ -9,7 +10,7 @@ import taboolib.module.lang.Language * @author 坏黑 * @since 2024/6/15 20:47 */ -abstract class Translated(val node: String, val default: T) { +abstract class Translated(val node: String, var default: T) { /** 获取翻译 */ abstract fun get(locale: String = "zh_CN"): T diff --git a/module/module-lang/src/main/kotlin/taboolib/module/lang/inline/TranslatedString.kt b/module/module-lang/src/main/kotlin/taboolib/module/lang/inline/TranslatedString.kt index 567d6beca..a8ec9ca80 100644 --- a/module/module-lang/src/main/kotlin/taboolib/module/lang/inline/TranslatedString.kt +++ b/module/module-lang/src/main/kotlin/taboolib/module/lang/inline/TranslatedString.kt @@ -11,7 +11,7 @@ import taboolib.module.lang.TypeText * @author 坏黑 * @since 2024/6/15 20:47 */ -class TranslatedString(node: String, default: String) : Translated(node, default) { +open class TranslatedString(node: String, default: String) : Translated(node, default) { override fun get(locale: String): String { val type = Language.languageCodeTransfer[locale] ?: locale @@ -22,4 +22,15 @@ class TranslatedString(node: String, default: String) : Translated(node, val node = file.nodes[node] as? TypeText ?: return default return node.text ?: default } + + companion object { + + fun of(value: String): TranslatedString { + return object : TranslatedString("", value) { + override fun get(locale: String): String { + return value + } + } + } + } } \ No newline at end of file diff --git a/module/module-lang/src/main/kotlin/taboolib/module/lang/inline/TranslatedStringList.kt b/module/module-lang/src/main/kotlin/taboolib/module/lang/inline/TranslatedStringList.kt index 264c1f85f..5096495f1 100644 --- a/module/module-lang/src/main/kotlin/taboolib/module/lang/inline/TranslatedStringList.kt +++ b/module/module-lang/src/main/kotlin/taboolib/module/lang/inline/TranslatedStringList.kt @@ -12,7 +12,7 @@ import taboolib.module.lang.TypeText * @author 坏黑 * @since 2024/6/15 20:47 */ -class TranslatedStringList(node: String, default: List) : Translated>(node, default) { +open class TranslatedStringList(node: String, default: List) : Translated>(node, default) { override fun get(locale: String): List { val type = Language.languageCodeTransfer[locale] ?: locale @@ -26,4 +26,15 @@ class TranslatedStringList(node: String, default: List) : Translated default } } + + companion object { + + fun of(value: List): TranslatedStringList { + return object : TranslatedStringList("", value) { + override fun get(locale: String): List { + return value + } + } + } + } } \ No newline at end of file