From 2d6a88f3e368110dcba285b58644a13008e38fb1 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Mon, 20 Mar 2023 00:41:58 +0200 Subject: [PATCH] Resolved #8968 - stats for notifications string'd without special characters --- core/src/com/unciv/models/stats/Stats.kt | 3 +-- core/src/com/unciv/models/translations/Translations.kt | 3 ++- tests/src/com/unciv/testing/TranslationTests.kt | 9 +++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/core/src/com/unciv/models/stats/Stats.kt b/core/src/com/unciv/models/stats/Stats.kt index ddfe462afc..e438cd0bbc 100644 --- a/core/src/com/unciv/models/stats/Stats.kt +++ b/core/src/com/unciv/models/stats/Stats.kt @@ -1,6 +1,5 @@ package com.unciv.models.stats -import com.unciv.Constants import com.unciv.models.translations.tr import kotlin.reflect.KMutableProperty0 @@ -152,7 +151,7 @@ open class Stats( /** Since notifications are translated on the fly, when saving stats there we need to do so in English */ fun toStringForNotifications() = this.joinToString { - (if (it.value > 0) "+" else "") + it.value.toInt() + " " + it.key.toString().tr(Constants.english) + (if (it.value > 0) "+" else "") + it.value.toInt() + " " + it.key.toString() } // For display in diplomacy window diff --git a/core/src/com/unciv/models/translations/Translations.kt b/core/src/com/unciv/models/translations/Translations.kt index 0afbebb59b..846931adb7 100644 --- a/core/src/com/unciv/models/translations/Translations.kt +++ b/core/src/com/unciv/models/translations/Translations.kt @@ -291,7 +291,8 @@ object TranslationActiveModsCache { * defaults to the input string if no translation is available, * but with placeholder or sentence brackets removed. */ -fun String.tr(language:String = UncivGame.Current.settings.language): String { +fun String.tr(): String { + val language:String = UncivGame.Current.settings.language if (contains('<') && contains('>')) { // Conditionals! /** * So conditionals can contain placeholders, such as , which themselves diff --git a/tests/src/com/unciv/testing/TranslationTests.kt b/tests/src/com/unciv/testing/TranslationTests.kt index 0fc93759b8..47d345acd2 100644 --- a/tests/src/com/unciv/testing/TranslationTests.kt +++ b/tests/src/com/unciv/testing/TranslationTests.kt @@ -7,6 +7,7 @@ import com.unciv.UncivGame import com.unciv.models.metadata.GameSettings import com.unciv.models.ruleset.Ruleset import com.unciv.models.ruleset.RulesetCache +import com.unciv.models.stats.Stats import com.unciv.models.translations.* import com.unciv.utils.debug import org.junit.Assert @@ -282,6 +283,14 @@ class TranslationTests { superNestedString.tr()) } + @Test + fun isStatsRecognizesStatsIncludingStatCharacter(){ + UncivGame.Current = UncivGame() + UncivGame.Current.settings = GameSettings() + + Assert.assertTrue(Stats.isStats(Stats(1f,2f,3f).toStringForNotifications())) + } + // @Test // fun allConditionalsAreContainedInConditionalOrderTranslation() {