manager: support locales for online template(2)
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package me.weishu.kernelsu.ui.screen
|
package me.weishu.kernelsu.ui.screen
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
@@ -29,6 +30,7 @@ import androidx.compose.runtime.LaunchedEffect
|
|||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
import com.ramcosta.composedestinations.annotation.Destination
|
import com.ramcosta.composedestinations.annotation.Destination
|
||||||
@@ -37,6 +39,7 @@ import kotlinx.coroutines.launch
|
|||||||
import me.weishu.kernelsu.R
|
import me.weishu.kernelsu.R
|
||||||
import me.weishu.kernelsu.ui.screen.destinations.TemplateEditorScreenDestination
|
import me.weishu.kernelsu.ui.screen.destinations.TemplateEditorScreenDestination
|
||||||
import me.weishu.kernelsu.ui.viewmodel.TemplateViewModel
|
import me.weishu.kernelsu.ui.viewmodel.TemplateViewModel
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author weishu
|
* @author weishu
|
||||||
|
|||||||
@@ -157,6 +157,18 @@ fun getTemplateInfoById(id: String): TemplateViewModel.TemplateInfo? {
|
|||||||
}.getOrNull()
|
}.getOrNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getLocaleString(json: JSONObject, key: String): String {
|
||||||
|
val fallback = json.getString(key)
|
||||||
|
val locale = Locale.getDefault()
|
||||||
|
val localeKey = "${locale.language}_${locale.country}"
|
||||||
|
json.optJSONObject("locales")?.let { locale ->
|
||||||
|
locale.optJSONObject(localeKey)?.let {
|
||||||
|
return it.optString(key, fallback)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
|
||||||
private fun fromJSON(templateJson: JSONObject): TemplateViewModel.TemplateInfo? {
|
private fun fromJSON(templateJson: JSONObject): TemplateViewModel.TemplateInfo? {
|
||||||
return runCatching {
|
return runCatching {
|
||||||
val groupsJsonArray = templateJson.getJSONArray("groups")
|
val groupsJsonArray = templateJson.getJSONArray("groups")
|
||||||
@@ -164,9 +176,9 @@ private fun fromJSON(templateJson: JSONObject): TemplateViewModel.TemplateInfo?
|
|||||||
val rulesJsonArray = templateJson.optJSONArray("rules")
|
val rulesJsonArray = templateJson.optJSONArray("rules")
|
||||||
val templateInfo = TemplateViewModel.TemplateInfo(
|
val templateInfo = TemplateViewModel.TemplateInfo(
|
||||||
id = templateJson.getString("id"),
|
id = templateJson.getString("id"),
|
||||||
name = templateJson.getString("name"),
|
name = getLocaleString(templateJson, "name"),
|
||||||
|
description = getLocaleString(templateJson, "description"),
|
||||||
author = templateJson.optString("author"),
|
author = templateJson.optString("author"),
|
||||||
description = templateJson.getString("description"),
|
|
||||||
local = templateJson.optBoolean("local"),
|
local = templateJson.optBoolean("local"),
|
||||||
namespace = Natives.Profile.Namespace.valueOf(
|
namespace = Natives.Profile.Namespace.valueOf(
|
||||||
templateJson.getString("namespace").uppercase()
|
templateJson.getString("namespace").uppercase()
|
||||||
|
|||||||
Reference in New Issue
Block a user