Skip to content

Commit

Permalink
[6.1.2] InlineLanguage
Browse files Browse the repository at this point in the history
  • Loading branch information
Bkm016 committed Jun 16, 2024
1 parent 7aa09ae commit 1246946
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 使用。
Expand Down Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package taboolib.module.lang.inline

import taboolib.module.lang.Language
import java.util.function.Function

/**
* Codex
Expand All @@ -9,7 +10,7 @@ import taboolib.module.lang.Language
* @author 坏黑
* @since 2024/6/15 20:47
*/
abstract class Translated<T>(val node: String, val default: T) {
abstract class Translated<T>(val node: String, var default: T) {

/** 获取翻译 */
abstract fun get(locale: String = "zh_CN"): T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import taboolib.module.lang.TypeText
* @author 坏黑
* @since 2024/6/15 20:47
*/
class TranslatedString(node: String, default: String) : Translated<String>(node, default) {
open class TranslatedString(node: String, default: String) : Translated<String>(node, default) {

override fun get(locale: String): String {
val type = Language.languageCodeTransfer[locale] ?: locale
Expand All @@ -22,4 +22,15 @@ class TranslatedString(node: String, default: String) : Translated<String>(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
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import taboolib.module.lang.TypeText
* @author 坏黑
* @since 2024/6/15 20:47
*/
class TranslatedStringList(node: String, default: List<String>) : Translated<List<String>>(node, default) {
open class TranslatedStringList(node: String, default: List<String>) : Translated<List<String>>(node, default) {

override fun get(locale: String): List<String> {
val type = Language.languageCodeTransfer[locale] ?: locale
Expand All @@ -26,4 +26,15 @@ class TranslatedStringList(node: String, default: List<String>) : Translated<Lis
else -> default
}
}

companion object {

fun of(value: List<String>): TranslatedStringList {
return object : TranslatedStringList("", value) {
override fun get(locale: String): List<String> {
return value
}
}
}
}
}

0 comments on commit 1246946

Please sign in to comment.