From 722772b08e0dcc8f1dc9767247df030b29f4fa2b Mon Sep 17 00:00:00 2001 From: SomeTroglodyte <63000004+SomeTroglodyte@users.noreply.github.com> Date: Wed, 21 Apr 2021 20:45:58 +0200 Subject: [PATCH] Solves #3802 Mod translations don't appear in new game screen (#3823) * Solves #3802 Mod translations don't appear in new game screen * Rehomed translationActiveMods to Translations --- core/src/com/unciv/models/translations/Translations.kt | 9 +++++++-- core/src/com/unciv/ui/newgamescreen/GameOptionsTable.kt | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/core/src/com/unciv/models/translations/Translations.kt b/core/src/com/unciv/models/translations/Translations.kt index 4508e4d4ef..96ddadeb17 100644 --- a/core/src/com/unciv/models/translations/Translations.kt +++ b/core/src/com/unciv/models/translations/Translations.kt @@ -32,6 +32,10 @@ class Translations : LinkedHashMap(){ private var modsWithTranslations: HashMap = hashMapOf() // key == mod name + // used by tr() whenever GameInfo not initialized (allowing new game screen to use mod translations) + var translationActiveMods = LinkedHashSet() + + /** * Searches for the translation entry of a given [text] for a given [language]. * This includes translations provided by mods from [activeMods] @@ -222,8 +226,9 @@ val curlyBraceRegex = Regex("""\{([^}]*)\}""") * but with placeholder or sentence brackets removed. */ fun String.tr(): String { - val activeMods = if (UncivGame.Current.isGameInfoInitialized()) - UncivGame.Current.gameInfo.gameParameters.mods else null + val activeMods = with(UncivGame.Current) { + if (isGameInfoInitialized()) gameInfo.gameParameters.mods else translations.translationActiveMods + } // There might still be optimization potential here! if (contains("[")) { // Placeholders! diff --git a/core/src/com/unciv/ui/newgamescreen/GameOptionsTable.kt b/core/src/com/unciv/ui/newgamescreen/GameOptionsTable.kt index 2ae1bb38e7..7e9edaa3ce 100644 --- a/core/src/com/unciv/ui/newgamescreen/GameOptionsTable.kt +++ b/core/src/com/unciv/ui/newgamescreen/GameOptionsTable.kt @@ -4,6 +4,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.CheckBox import com.badlogic.gdx.scenes.scene2d.ui.SelectBox import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.utils.Array +import com.unciv.UncivGame import com.unciv.models.metadata.BaseRuleset import com.unciv.models.metadata.GameSpeed import com.unciv.models.ruleset.RulesetCache @@ -174,6 +175,7 @@ class GameOptionsTable(val previousScreen: IPreviousScreen, val updatePlayerPick fun Table.addModCheckboxes() { val table = ModCheckboxTable(gameParameters.mods, previousScreen as CameraStageBaseScreen) { + UncivGame.Current.translations.translationActiveMods = gameParameters.mods reloadRuleset() update()