Skip to content

Commit

Permalink
chore: built-in theme name localization
Browse files Browse the repository at this point in the history
  • Loading branch information
nopdan authored and goofyz committed May 24, 2024
1 parent 6ebe8c2 commit 88ed36a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,10 @@ object ThemeManager {
DataManager.addOnChangedListener(onDataDirChange)
}

private val suffixRegex = Regex("(.*?)(\\.trime\\.yaml$|\\.yaml$)")

private fun listThemes(path: File): MutableList<String> {
return path.listFiles { _, name -> name.endsWith("trime.yaml") }
?.mapNotNull { f ->
suffixRegex.matchEntire(f.name)?.let { result ->
val basename = if (result.groups[2]?.value == ".trime.yaml") result.groupValues[1] else f.nameWithoutExtension
basename
}
if (f.name == "trime.yaml") "trime" else f.name.substringBeforeLast(".trime.yaml")
}
?.toMutableList() ?: mutableListOf()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,24 @@ object ThemePickerDialog {
withContext(Dispatchers.IO) {
ThemeManager.getAllThemes()
}
val allNames =
all.map {
when (it) {
"trime" -> context.getString(R.string.theme_trime)
"tongwenfeng" -> context.getString(R.string.theme_tongwenfeng)
else -> it
}
}
val current =
AppPrefs.defaultInstance().theme.selectedTheme
val currentIndex = all.indexOfFirst { it == current }
return AlertDialog.Builder(context).apply {
setTitle(R.string.looks__selected_theme_title)
if (all.isEmpty()) {
if (allNames.isEmpty()) {
setMessage(R.string.no_theme_to_select)
} else {
setSingleChoiceItems(
all.toTypedArray(),
allNames.toTypedArray(),
currentIndex,
) { dialog, which ->
scope.launch {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,6 @@ SPDX-License-Identifier: GPL-3.0-or-later
<item>跟随键盘背景色</item>
<item>键盘背景图片</item>
</string-array>
<string name="theme_trime">默认</string>
<string name="theme_tongwenfeng">同文风</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,6 @@ SPDX-License-Identifier: GPL-3.0-or-later
<item>跟隨鍵盤背景色</item>
<item>鍵盤背景圖片</item>
</string-array>
<string name="theme_trime">預設</string>
<string name="theme_tongwenfeng">同文風</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -288,4 +288,6 @@ SPDX-License-Identifier: GPL-3.0-or-later
<item>Follow keyboard color</item>
<item>Keyboard background image</item>
</string-array>
<string name="theme_trime">default</string>
<string name="theme_tongwenfeng">tongwenfeng</string>
</resources>

0 comments on commit 88ed36a

Please sign in to comment.