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 d4950a8 commit ca17b44
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package taboolib.module.lang.inline

import taboolib.common.platform.function.dev
import taboolib.library.configuration.ConfigurationSection
import taboolib.module.configuration.util.getStringColored

/**
* 内嵌语言文件,配合 Configuration 使用。
Expand All @@ -21,5 +23,24 @@ import taboolib.library.configuration.ConfigurationSection
* ```
*/
fun ConfigurationSection.getTranslatedString(path: String): TranslatedString? {
val node = getLanguageNode(path) ?: return null
val defaultValue = getStringColored(path) ?: return null
return TranslatedString(node, defaultValue)
}

fun ConfigurationSection.getTranslatedStringList(path: String): TranslatedStringList? {
val node = getLanguageNode(path) ?: return null
val defaultValue = getStringList(path)
return TranslatedStringList(node, defaultValue)
}

fun ConfigurationSection.getLanguageNode(path: String): String? {
val comments = getComments(path)
for (comment in comments) {
val line = comment.trim()
if (line.startsWith("@lang:")) {
return line.substring(6)
}
}
return null
}

0 comments on commit ca17b44

Please sign in to comment.