From 3a16fcb02192e6578dc959a50b32fb49b5a3fe5c Mon Sep 17 00:00:00 2001 From: SomeTroglodyte <63000004+SomeTroglodyte@users.noreply.github.com> Date: Sat, 29 Jun 2024 22:57:42 +0200 Subject: [PATCH] Minor TranslationFileWriter maintenance (#11858) * Replace confusing `[Food] Focus` template with prettier `[stat] Focus` * Minor lint --- .../models/translations/TranslationFileWriter.kt | 11 +++-------- .../com/unciv/ui/components/input/KeyboardBinding.kt | 10 ++++++++++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/core/src/com/unciv/models/translations/TranslationFileWriter.kt b/core/src/com/unciv/models/translations/TranslationFileWriter.kt index 789ee28014..93dd5e701c 100644 --- a/core/src/com/unciv/models/translations/TranslationFileWriter.kt +++ b/core/src/com/unciv/models/translations/TranslationFileWriter.kt @@ -127,21 +127,16 @@ object TranslationFileWriter { linesToTranslate += "$uniqueTarget = " linesToTranslate += "\n\n#################### Lines from spy actions #######################\n" - for (spyAction in SpyAction.values()) { + for (spyAction in SpyAction.values()) linesToTranslate += "${spyAction.displayString} = " - } linesToTranslate += "\n\n#################### Lines from diplomatic modifiers #######################\n" for (diplomaticModifier in DiplomaticModifiers.values()) linesToTranslate += "${diplomaticModifier.text} = " linesToTranslate += "\n\n#################### Lines from key bindings #######################\n" - for (category in KeyboardBinding.Category.values()) { - linesToTranslate += "${category.label} = " - } - for (binding in KeyboardBinding.values()) { - linesToTranslate += "${binding.label} = " - } + for (bindingLabel in KeyboardBinding.getTranslationEntries()) + linesToTranslate += "$bindingLabel = " for (baseRuleset in BaseRuleset.values()) { val generatedStringsFromBaseRuleset = diff --git a/core/src/com/unciv/ui/components/input/KeyboardBinding.kt b/core/src/com/unciv/ui/components/input/KeyboardBinding.kt index e5f4bba1d7..5d8b4aefb3 100644 --- a/core/src/com/unciv/ui/components/input/KeyboardBinding.kt +++ b/core/src/com/unciv/ui/components/input/KeyboardBinding.kt @@ -13,6 +13,8 @@ private fun unCamelCase(name: String) = unCamelCaseRegex.replace(name, """$1$4 $ * * Note a label is automatically generated from the name by inserting spaces before each uppercase letter (except the initial one), * and translation keys are automatically generated for all labels. This also works for [KeyboardBinding.Category]. + * + * [label] entries containing a placeholder need special treatment - see [getTranslationEntries] and update it when adding more. */ enum class KeyboardBinding( val category: Category, @@ -259,6 +261,14 @@ enum class KeyboardBinding( constructor(category: Category, key: Int) : this(category, KeyCharAndCode(key)) //endregion + companion object { + fun getTranslationEntries() = ( + Category.values().asSequence().map { it.label } + + values().asSequence().map { it.label }.filterNot { it.contains('[') } + + sequenceOf("[stat] Focus") + ) + } + /** Debug helper */ override fun toString() = "$category.$name($defaultKey)" }