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
This commit is contained in:
SomeTroglodyte 2021-04-21 20:45:58 +02:00 committed by GitHub
parent 6ffbce4ee1
commit 722772b08e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -32,6 +32,10 @@ class Translations : LinkedHashMap<String, TranslationEntry>(){
private var modsWithTranslations: HashMap<String, Translations> = hashMapOf() // key == mod name
// used by tr() whenever GameInfo not initialized (allowing new game screen to use mod translations)
var translationActiveMods = LinkedHashSet<String>()
/**
* 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!

View File

@ -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()