Merge branch 'main' into zhong_1
Merge main branch to keep zhong_1 up to date# Please enter a commit message to explain why this merge is necessary,
This commit is contained in:
@@ -234,22 +234,24 @@ object AgentViewModel: ViewModel() {
|
||||
|
||||
try {
|
||||
// 获取完整的语言标记(如 "zh-CN")
|
||||
val sysLang = com.aiosman.ravenow.utils.Utils.getPreferredLanguageTag()
|
||||
val fullLangTag = com.aiosman.ravenow.utils.Utils.getPreferredLanguageTag()
|
||||
// 转换为后端支持的语言代码(仅支持 zh、cn、ja)
|
||||
val sysLang = convertToSupportedLangCode(fullLangTag)
|
||||
val response = apiClient.getCategories(
|
||||
page = 1,
|
||||
pageSize = 100,
|
||||
isActive = true,
|
||||
withChildren = false,
|
||||
withParent = false,
|
||||
withCount = true,
|
||||
hideEmpty = true,
|
||||
// withChildren = false,
|
||||
// withParent = false,
|
||||
// withCount = true,
|
||||
// hideEmpty = true,
|
||||
lang = sysLang
|
||||
)
|
||||
println("分类数据请求完成,响应成功: ${response.isSuccessful}, 语言标记: $sysLang")
|
||||
println("分类数据请求完成,响应成功: ${response.isSuccessful}, 原始语言标记: $fullLangTag, 转换后: $sysLang")
|
||||
if (response.isSuccessful) {
|
||||
val categoryList = response.body()?.list ?: emptyList()
|
||||
println("获取到 ${categoryList.size} 个分类")
|
||||
// 使用当前语言获取翻译后的分类名称
|
||||
// 使用转换后的语言代码获取翻译后的分类名称
|
||||
categories = categoryList.map { category ->
|
||||
CategoryItem.fromCategoryTemplate(category, sysLang)
|
||||
}
|
||||
@@ -266,6 +268,24 @@ object AgentViewModel: ViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将完整的语言标记转换为后端支持的语言代码
|
||||
* 后端仅支持: zh, cn, ja
|
||||
*
|
||||
* @param langTag 完整的语言标记,如 "zh-CN", "zh-TW", "ja-JP", "en-US" 等
|
||||
* @return 后端支持的语言代码,默认返回 "zh"
|
||||
*/
|
||||
private fun convertToSupportedLangCode(langTag: String): String {
|
||||
return when {
|
||||
langTag.startsWith("zh", ignoreCase = true) -> "zh"
|
||||
langTag.startsWith("ja", ignoreCase = true) -> "ja"
|
||||
// 如果是中文相关的其他标记,也返回 zh
|
||||
langTag.equals("cn", ignoreCase = true) -> "cn"
|
||||
// 默认返回中文
|
||||
else -> "zh"
|
||||
}
|
||||
}
|
||||
|
||||
fun loadAgentsByCategory(categoryId: Int) {
|
||||
loadAgentData(categoryId)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user