Skip to content

Commit

Permalink
feat: 设置页面添加英文文本翻译
Browse files Browse the repository at this point in the history
  • Loading branch information
jixiaoyong committed Mar 31, 2024
1 parent 0868c40 commit e20cdf1
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 67 deletions.
8 changes: 4 additions & 4 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import kotlin.system.exitProcess

val LocalWindow = compositionLocalOf<ComposeWindow> { error("No Window provided") }
val LocalSettings = compositionLocalOf<SettingsTool> { error("No SettingsTool provided") }
val LocalStrings = compositionLocalOf<Lyricist<Strings>> { error("No SettingsTool provided") }
val LocalI18nStrings = compositionLocalOf<Lyricist<Strings>> { error("No SettingsTool provided") }

fun main() =
application {
Expand All @@ -56,7 +56,7 @@ fun main() =
CompositionLocalProvider(
LocalWindow provides window,
LocalSettings provides SettingsTool(scope = rememberCoroutineScope()),
LocalStrings provides lyricist
LocalI18nStrings provides lyricist
) {
LaunchedEffect(checkDualRunning) {
appState = AppState.Loading
Expand Down Expand Up @@ -98,13 +98,13 @@ fun LoadingPage() {
verticalArrangement = Arrangement.Center,
) {
CircularProgressIndicator()
Text(LocalStrings.current.strings.loading, Modifier.padding(top = 10.dp))
Text(LocalI18nStrings.current.strings.loading, Modifier.padding(top = 10.dp))
}
}

@Composable
fun AlreadyExistsPage(tryAgainFunc: () -> Unit) {
val i18nString = LocalStrings.current.strings
val i18nString = LocalI18nStrings.current.strings
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center,
Expand Down
43 changes: 42 additions & 1 deletion src/main/kotlin/io/github/jixiaoyong/i18n/StringEn.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,48 @@ internal val EnStrings = Strings(
retry = "Retry",
signConfig = "Signature information",
signApp = "Signature APP",
settingsConfig = "Settings Config"
settingsConfig = "Settings Config",
confirm = "Confirm",
change = "Change",
noContent = "No content",
currentSignInfo = "Current signature: ",
changeSignInfo = "Re-select signature",
deleteSignInfoTips = "Delete this tool stored signature information, it won't delete your APK signature files",
nickName = "Signature nickname",
nickNameDescription = "Nickname, used to distinguish different signatures",
filePath = "File path",
plzSelectSignFile = "Please select an Android signature file",
chooseFile = "Choose file",
absolutePathOfSignFile = "The absolute path of the signature file",
saveNewSignInfo = "Save new signature information",
saveNewSignInfoTips = "🎉Save successfully!\nPlease click the \"Re-select signature\" button to view. Whether to clear the filled in content?",
cleanUp = "Clean up",
resetSuccess = "Reset successful",
confirmReset = "Confirm reset",
confirmResetTips = "Resetting will clear the following content, please operate with caution",
signToolsConfigResetTips = "Signing tool configuration (files will not be deleted)",
signType = "Signature scheme",
signedApkOutputDir = "Signature file output directory",
chooseBuildTools = "Please select the build-tools directory",
chooseBuildToolsTips = "Please drag and drop the subfolder of Android SDK's build-tools here to modify the apkSigner and zipAlign directories at once",
apksignerDirectory = "apksigner directory",
plzChooseApksigner = "Please select apksigner file",
chooseApksignerTips = "Please select the apksigner file in the build-tools directory in the Android SDK",
notInit = "Not initialized yet",
changeSuccess = "Successfully modified",
zipDirectory = "zipalign directory",
chooseZipTips = "Please select the zipalign file in the build-tools directory in the Android SDK",
plzChooseZip = "Please select zipAlign file",
autoMatchSignature = "Automatically match signatures",
autoMatchSignatureTips = "When there is only one apk file, it will automatically try to match the last used signature information.",
aaptDirectory = "aapt directory",
chooseAaptDirectory = "Please select aapt file",
aaptDirectoryTips = "To automatically match signatures, please correctly configure the aapt file in the build-tools directory in the Android SDK",
reset = "Reset",
appIntro = { version, webSite ->
"This is a small tool for local visualization of signed APKs. \nIn order to avoid leaking information such as keys, this tool will not be connected to the Internet.\n" +
"Current version:$version,To view the latest version, please click to visit:$webSite"
},
)

//internal val EnStrings = Strings(
Expand Down
43 changes: 42 additions & 1 deletion src/main/kotlin/io/github/jixiaoyong/i18n/StringZh.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,46 @@ internal val ZhStrings = Strings(
retry = "重试",
signConfig = "签名信息",
signApp = "签名APP",
settingsConfig = "设置信息"
settingsConfig = "设置信息",
confirm = "确定",
change = "修改",
noContent = "暂无内容",
currentSignInfo = "当前签名: ",
changeSignInfo = "重新选择签名",
deleteSignInfoTips = "删除此工具存储的签名信息,不会删除apk签名文件",
nickName = "签名别名",
nickNameDescription = "备注名称,用来区分不同签名",
filePath = "文件路径",
plzSelectSignFile = "请选择Android签名文件",
chooseFile = "选择文件",
absolutePathOfSignFile = "签名文件的有效绝对路径",
saveNewSignInfo = "保存新签名信息",
saveNewSignInfoTips = "🎉保存成功!\n请点击【重新选择签名】按钮查看,是否清除已填写内容?",
cleanUp = "清空",
resetSuccess = "重置成功",
confirmReset = "确认重置吗",
confirmResetTips = "重置会清除以下内容,请谨慎操作",
signToolsConfigResetTips = "签名工具配置(不会删除文件)",
signType = "签名方案",
signedApkOutputDir = "签名文件输出目录",
chooseBuildTools = "请选择build-tools目录",
chooseBuildToolsTips = "请拖拽Android SDK的build-tools的子文件夹到这里,以一次性修改apkSigner和zipAlign目录",
apksignerDirectory = "apksigner目录",
plzChooseApksigner = "请选择apksigner文件",
chooseApksignerTips = "请选择Android SDK中build-tools目录apksigner文件",
notInit = "尚未初始化",
changeSuccess = "修改成功",
zipDirectory = "zipalign目录",
chooseZipTips = "请选择Android SDK中build-tools目录zipalign文件",
plzChooseZip = "请选择zipAlign文件",
autoMatchSignature = "自动匹配签名",
autoMatchSignatureTips = "当只有一个apk文件时,则自动尝试匹配上次使用的签名信息",
aaptDirectory = "aapt目录",
chooseAaptDirectory = "请选择aapt文件",
aaptDirectoryTips = "若要自动匹配签名,请正确配置Android SDK中build-tools目录aapt文件",
reset = "重置",
appIntro = { version, webSite ->
"这是一个本地可视化签名APK的小工具。为了避免泄漏密钥等信息,本工具不会联网。\n" +
"当前版本:$version,查看最新版本请点击访问:$webSite"
},
)
40 changes: 39 additions & 1 deletion src/main/kotlin/io/github/jixiaoyong/i18n/Strings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,42 @@ data class Strings(
val signConfig: String,
val signApp: String,
val settingsConfig: String,
)
val confirm:String,
val change:String,
val noContent:String,
val currentSignInfo:String,
val changeSignInfo:String,
val deleteSignInfoTips:String,
val nickName:String,
val nickNameDescription:String,
val filePath:String,
val plzSelectSignFile:String,
val chooseFile:String,
val absolutePathOfSignFile:String,
val saveNewSignInfo:String,
val saveNewSignInfoTips:String,
val cleanUp:String,
val resetSuccess:String,
val confirmReset:String,
val confirmResetTips:String,
val signToolsConfigResetTips:String,
val signType:String,
val signedApkOutputDir:String,
val chooseBuildTools:String,
val chooseBuildToolsTips:String,
val apksignerDirectory:String,
val chooseApksignerTips:String,
val plzChooseApksigner:String,
val notInit:String,
val changeSuccess:String,
val zipDirectory:String,
val chooseZipTips:String,
val plzChooseZip:String,
val autoMatchSignature:String,
val autoMatchSignatureTips: String,
val aaptDirectory:String,
val chooseAaptDirectory:String,
val aaptDirectoryTips: String,
val reset:String,
val appIntro:(version:String,webSite:String)->String,
)
4 changes: 2 additions & 2 deletions src/main/kotlin/io/github/jixiaoyong/pages/MainPage.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.jixiaoyong.pages

import LocalI18nStrings
import LocalSettings
import LocalStrings
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
Expand Down Expand Up @@ -36,7 +36,7 @@ import kotlinx.coroutines.launch
@Composable
fun App() {
val settings = LocalSettings.current
val i18nString = LocalStrings.current
val i18nString = LocalI18nStrings.current

val scope = rememberCoroutineScope()
val viewModel = viewModel { MainViewModel(settings, i18nString.strings) }
Expand Down
69 changes: 37 additions & 32 deletions src/main/kotlin/io/github/jixiaoyong/pages/settings/Settings.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.jixiaoyong.pages.settings

import ApkSigner
import LocalI18nStrings
import LocalSettings
import LocalWindow
import androidx.compose.foundation.background
Expand Down Expand Up @@ -56,6 +57,8 @@ fun PageSettingInfo() {
val scope = rememberCoroutineScope()
val window = LocalWindow.current
val settings = LocalSettings.current
val i18nStringTool = LocalI18nStrings.current
val i18nString = i18nStringTool.strings

val viewModel = viewModel { SettingInfoViewModel(settings) }
val uiState by viewModel.uiState.collectAsState()
Expand All @@ -72,32 +75,32 @@ fun PageSettingInfo() {
}, confirmButton = {
ButtonWidget(onClick = {
viewModel.runRestConfig()
showToast("重置成功")
}, title = "确定")
showToast(i18nString.resetSuccess)
}, title = i18nString.confirm)

}, title = {
Text("确定重置吗")
Text(i18nString.confirmReset)
}, text = {
Column {
Text("重置会清除以下内容,请谨慎操作")
Text(i18nString.confirmResetTips)
CheckBox(
checked = resetConfig.resetSignInfo,
title = "签名信息",
title = i18nString.signConfig,
onCheckedChange = {
viewModel.updateResetConfig(resetSignInfo = !resetConfig.resetSignInfo)
})
CheckBox(
checked = resetConfig.resetApkTools,
title = "签名工具配置(不会删除文件)",
title = i18nString.signToolsConfigResetTips,
onCheckedChange = { viewModel.updateResetConfig(resetApkTools = !resetConfig.resetApkTools) })

CheckBox(
checked = resetConfig.resetSignTypes,
title = "签名方案",
title = i18nString.signType,
onCheckedChange = { viewModel.updateResetConfig(resetSignTypes = !resetConfig.resetSignTypes) })
CheckBox(
checked = resetConfig.resetSignedDirectory,
title = "签名文件输出目录",
title = i18nString.signedApkOutputDir,
onCheckedChange = { viewModel.updateResetConfig(resetSignedDirectory = !resetConfig.resetSignedDirectory) })
}
})
Expand All @@ -119,11 +122,11 @@ fun PageSettingInfo() {
val chooseFileName =
FileChooseUtil.chooseSignDirectory(
window,
"请选择build-tools目录",
i18nString.chooseBuildTools,
oldDirectory
)
if (chooseFileName.isNullOrBlank()) {
showToast("请选择build-tools目录", ToastConfig.DURATION.Long)
showToast(i18nString.chooseBuildTools, ToastConfig.DURATION.Long)
} else {
viewModel.setupBuildToolsConfig(chooseFileName)
}
Expand All @@ -132,40 +135,41 @@ fun PageSettingInfo() {
component = JPanel(),
onFileDrop = { scope.launch { viewModel.setupBuildToolsConfig(it.first()) } }) {
Text(
text = "请拖拽Android SDK的build-tools的子文件夹到这里,以一次性修改apkSigner和zipAlign目录",
text = i18nString.chooseBuildToolsTips,
color = MaterialTheme.colors.onSurface,
textAlign = TextAlign.Center,
modifier = Modifier.align(alignment = Alignment.Center)
)
}

InfoItemWidget("apk signer目录",
uiState.apkSign ?: "尚未初始化",
description = "请选择Android SDK中build-tools目录apksigner文件",
InfoItemWidget(i18nString.apksignerDirectory,
uiState.apkSign ?: i18nString.notInit,
description = i18nString.chooseApksignerTips,
onClick = {
scope.launch {
val chooseFileName =
FileChooseUtil.chooseSignFile(window, "请选择apksigner文件")
FileChooseUtil.chooseSignFile(window, i18nString.plzChooseApksigner)
if (chooseFileName.isNullOrBlank()) {
showToast("请选择apksigner文件", ToastConfig.DURATION.Long)
showToast(i18nString.plzChooseApksigner, ToastConfig.DURATION.Long)
} else {
val result = ApkSigner.setupApkSigner(chooseFileName)
viewModel.saveApkSigner(ApkSigner.apkSignerPath)
showToast(result ?: "修改成功")
showToast(result ?: i18nString.changeSuccess)
}
}

})
InfoItemWidget("zipalign目录", uiState.zipAlign ?: "尚未初始化",
description = "请选择Android SDK中build-tools目录zipalign文件",
InfoItemWidget(i18nString.zipDirectory, uiState.zipAlign ?: i18nString.notInit,
description = i18nString.chooseZipTips,
onClick = {
scope.launch {
val chooseFileName = FileChooseUtil.chooseSignFile(window, "请选择zipAlign文件")
val chooseFileName = FileChooseUtil.chooseSignFile(window, i18nString.plzChooseZip)
if (chooseFileName.isNullOrBlank()) {
showToast("请选择zipAlign文件", ToastConfig.DURATION.Long)
showToast(i18nString.plzChooseZip, ToastConfig.DURATION.Long)
} else {
val result = ApkSigner.setupZipAlign(chooseFileName)
viewModel.saveZipAlign(ApkSigner.zipAlignPath)
showToast(result ?: "修改成功")
showToast(result ?: i18nString.changeSuccess)
}
}
})
Expand All @@ -176,11 +180,11 @@ fun PageSettingInfo() {
) {
Column(modifier = Modifier.weight(1f, true)) {
Text(
"自动匹配签名",
i18nString.autoMatchSignature,
style = TextStyle(fontWeight = FontWeight.ExtraBold, fontSize = 16.sp)
)
Text(
"当只有一个apk文件时,则自动尝试匹配上次使用的签名信息",
i18nString.autoMatchSignatureTips,
style = TextStyle(
fontWeight = FontWeight.Medium,
fontSize = 12.sp,
Expand All @@ -195,17 +199,18 @@ fun PageSettingInfo() {
)
}

if (uiState.isAutoMatchSignature) InfoItemWidget("aapt目录", uiState.aapt ?: "尚未初始化",
description = "若要自动匹配签名,请正确配置Android SDK中build-tools目录aapt文件",
if (uiState.isAutoMatchSignature) InfoItemWidget(i18nString.aaptDirectory,
uiState.aapt ?: i18nString.notInit,
description = i18nString.aaptDirectoryTips,
onClick = {
scope.launch {
val chooseFileName = FileChooseUtil.chooseSignFile(window, "请选择aapt文件")
val chooseFileName = FileChooseUtil.chooseSignFile(window, i18nString.chooseAaptDirectory)
if (chooseFileName.isNullOrBlank()) {
showToast("请选择aapt文件", ToastConfig.DURATION.Long)
showToast(i18nString.chooseAaptDirectory, ToastConfig.DURATION.Long)
} else {
val result = ApkSigner.setupAapt(chooseFileName)
viewModel.saveAapt(ApkSigner.aaptPath)
showToast(result ?: "修改成功")
showToast(result ?: i18nString.changeSuccess)
}
}
})
Expand All @@ -214,7 +219,7 @@ fun PageSettingInfo() {
Row(horizontalArrangement = Arrangement.Center, modifier = Modifier.fillMaxWidth().padding(top = 80.dp)) {
ButtonWidget(
onClick = { viewModel.toggleResetDialog() },
title = "重置",
title = i18nString.reset,
modifier = Modifier.size(250.dp, 50.dp)
)
}
Expand All @@ -224,8 +229,8 @@ fun PageSettingInfo() {
verticalArrangement = Arrangement.Bottom,
horizontalAlignment = Alignment.CenterHorizontally
) {
val str = "这是一个本地可视化签名APK的小工具。为了避免泄漏密钥等信息,本工具不会联网。\n" +
"当前版本:${uiState.version},查看最新版本请点击访问:$PROJECT_WEBSITE"

val str = i18nString.appIntro(uiState.version, PROJECT_WEBSITE)
val startIndex = str.indexOf(PROJECT_WEBSITE)
val endIndex = startIndex + PROJECT_WEBSITE.length

Expand Down

0 comments on commit e20cdf1

Please sign in to comment.