-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
234 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
zmusic-core/src/main/kotlin/me/zhenxin/zmusic/config/I18n.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package me.zhenxin.zmusic.config | ||
|
||
import com.electronwill.nightconfig.core.CommentedConfig | ||
import com.electronwill.nightconfig.toml.TomlParser | ||
import me.zhenxin.zmusic.ZMusic | ||
import me.zhenxin.zmusic.logger | ||
import java.util.* | ||
|
||
/** | ||
* 国际化 | ||
* | ||
* @author 真心 | ||
* @since 2024/2/7 9:19 | ||
*/ | ||
object I18n { | ||
object Platform { | ||
val netease: String | ||
get() = i18n.get("platform.netease") ?: "" | ||
|
||
val bilibili: String | ||
get() = i18n.get("platform.bilibili") ?: "" | ||
} | ||
|
||
object Init { | ||
val loaded: List<String> | ||
get() = i18n.get("init.loaded") ?: emptyList() | ||
} | ||
|
||
object Update { | ||
val checking: String | ||
get() = i18n.get("update.checking") ?: "" | ||
|
||
val available: List<String> | ||
get() = i18n.get("update.available") ?: emptyList() | ||
|
||
val notAvailable: String | ||
get() = i18n.get("update.not_available") ?: "" | ||
} | ||
|
||
object Help { | ||
val tips: String | ||
get() = i18n.get("help.tips") ?: "" | ||
} | ||
} | ||
|
||
/** | ||
* 初始化国际化配置 | ||
*/ | ||
fun initI18n() { | ||
// 支持的语言 | ||
val languages = arrayOf("en-US", "zh-CN") | ||
logger.debug("Supported languages: ${languages.joinToString()}") | ||
|
||
// 获取配置文件中的语言 | ||
var language = Config.language | ||
|
||
// 如果是自动则使用系统语言 | ||
if (language == "auto") { | ||
val locale = Locale.getDefault() | ||
language = "${locale.language}-${locale.country}" | ||
} | ||
|
||
// 如果不支持则使用默认语言 | ||
if (language !in languages) { | ||
logger.warn("Language $language is not supported, use default language en-US.") | ||
logger.warn("Supported languages: ${languages.joinToString()}") | ||
language = "en-US" | ||
} | ||
|
||
// 从资源文件加载 | ||
val classLoader = ZMusic::class.java.classLoader | ||
val file = classLoader.getResource("i18n/$language.toml") | ||
logger.debug("I18n file: $file") | ||
|
||
// 如果文件存在则加载, 否则禁用插件 | ||
if (file != null) { | ||
val parser = TomlParser() | ||
i18n = parser.parse(file) | ||
logger.info("I18n is initialized.") | ||
} else { | ||
logger.error("Failed to load $language.toml, please check your plugin jar.") | ||
// TODO: disablePlugin() | ||
} | ||
} | ||
|
||
private lateinit var i18n: CommentedConfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
zmusic-core/src/main/kotlin/me/zhenxin/zmusic/platform/Platform.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package me.zhenxin.zmusic.platform | ||
|
||
/** | ||
* 平台 | ||
* | ||
* @author 真心 | ||
* @since 2024/2/7 14:19 | ||
*/ | ||
enum class Platform { | ||
BUKKIT, | ||
BUNGEE, | ||
VELOCITY | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
############################################### | ||
# ______ __ __ _ # | ||
# |___ / | \/ | (_) # | ||
# / / | \ / | _ _ ___ _ ___ # | ||
# / / | |\/| | | | | | / __| | | / __| # | ||
# / /__ | | | | | |_| | \__ \ | | | (__ # | ||
# /_____| |_| |_| \__,_| |___/ |_| \___| # | ||
# # | ||
############################################### | ||
|
||
# Language file format: TOML (Please modify according to the specification) | ||
# For specification, please refer to https://toml.io/en/ | ||
|
||
[platform] | ||
netease = "Netease Cloud Music" | ||
bilibili = "BiliBili" | ||
|
||
[init] | ||
loaded = [ | ||
"&aPlugin Loaded!", | ||
"&aVersion: &b{version}", | ||
"&aPlatform: &b{platform}", | ||
"&aDocs: &b{docs-url}", | ||
"&aAuthor: &b{author}", | ||
] | ||
|
||
[update] | ||
checking = "&aChecking for updates..." | ||
available = [ | ||
"&aNew version available: &b{version}", | ||
"&aChangeLog:" | ||
] | ||
not_available = "&aNo new version available." | ||
|
||
[help] | ||
tips = "&aInput &a/&e{command} &bhelp &aShow Help." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
############################################### | ||
# ______ __ __ _ # | ||
# |___ / | \/ | (_) # | ||
# / / | \ / | _ _ ___ _ ___ # | ||
# / / | |\/| | | | | | / __| | | / __| # | ||
# / /__ | | | | | |_| | \__ \ | | | (__ # | ||
# /_____| |_| |_| \__,_| |___/ |_| \___| # | ||
# # | ||
############################################### | ||
|
||
# 语言文件格式为: TOML (请按规范修改) | ||
# 规范说明请参考 https://toml.io/cn/ | ||
|
||
[platform] | ||
netease = "网易云音乐" | ||
bilibili = "哔哩哔哩" | ||
|
||
[init] | ||
loaded = [ | ||
"&a插件加载完毕!", | ||
"&a插件版本: &b{version}", | ||
"&a当前平台: &b{platform}", | ||
"&a使用文档: &b{docs-url}", | ||
"&a插件作者: &b{author}", | ||
] | ||
|
||
[update] | ||
checking = "&a正在检查更新..." | ||
available = [ | ||
"&a发现新版本: &b{version}", | ||
"&a更新日志:", | ||
] | ||
not_available = "&a当前已是最新版本!" | ||
|
||
[help] | ||
tips = "&a输入 &a/&e{command} &bhelp &a查看帮助." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters