diff --git a/core/src/com/unciv/logic/map/TileInfo.kt b/core/src/com/unciv/logic/map/TileInfo.kt index 10af6d3931..393be4b0f7 100644 --- a/core/src/com/unciv/logic/map/TileInfo.kt +++ b/core/src/com/unciv/logic/map/TileInfo.kt @@ -20,7 +20,7 @@ open class TileInfo { fun getUnits()= listOf(militaryUnit,civilianUnit).filterNotNull() var position: Vector2 = Vector2.Zero - var baseTerrain: String? = null + lateinit var baseTerrain: String var terrainFeature: String? = null var resource: String? = null var improvement: String? = null @@ -152,12 +152,12 @@ open class TileInfo { val city = getCity()!! SB.appendln(city.name+ " ("+city.health+"),\r\n" + city.cityConstructions.getProductionForTileInfo()) } - SB.appendln(this.baseTerrain) - if (terrainFeature != null) SB.appendln(terrainFeature!!) - if (hasViewableResource(tileMap.gameInfo.getPlayerCivilization())) SB.appendln(resource!!) - if (roadStatus !== RoadStatus.None && !isCityCenter()) SB.appendln(roadStatus) - if (improvement != null) SB.appendln(improvement!!) - if (improvementInProgress != null) SB.appendln("$improvementInProgress in ${this.turnsToImprovement} "+"turns".tr()) + SB.appendln(this.baseTerrain.tr()) + if (terrainFeature != null) SB.appendln(terrainFeature!!.tr()) + if (hasViewableResource(tileMap.gameInfo.getPlayerCivilization())) SB.appendln(resource!!.tr()) + if (roadStatus !== RoadStatus.None && !isCityCenter()) SB.appendln(roadStatus.toString().tr()) + if (improvement != null) SB.appendln(improvement!!.tr()) + if (improvementInProgress != null) SB.appendln("{$improvementInProgress} in ${this.turnsToImprovement} {turns}".tr()) val isViewableToPlayer = UnCivGame.Current.gameInfo.getPlayerCivilization().getViewableTiles().contains(this) if (civilianUnit != null && isViewableToPlayer) SB.appendln(civilianUnit!!.name) if(militaryUnit!=null && isViewableToPlayer){ diff --git a/core/src/com/unciv/models/gamebasics/Building.kt b/core/src/com/unciv/models/gamebasics/Building.kt index 53ba9649e7..07a21a4317 100644 --- a/core/src/com/unciv/models/gamebasics/Building.kt +++ b/core/src/com/unciv/models/gamebasics/Building.kt @@ -48,7 +48,7 @@ class Building : NamedStats(), IConstruction{ val infoList= mutableListOf() val str = getStats(hashSetOf()).toString() if(str.isNotEmpty()) infoList += str - val improvedResources = GameBasics.TileResources.values.filter { it.building==name } + val improvedResources = GameBasics.TileResources.values.filter { it.building==name }.map { it.name.tr() } if(improvedResources.isNotEmpty()){ // buildings that improve resources infoList += resourceBonusStats.toString() +" from "+improvedResources.joinToString() @@ -99,7 +99,7 @@ class Building : NamedStats(), IConstruction{ if (!forBuildingPickerScreen) stringBuilder.appendln("Cost: $cost") if (isWonder) stringBuilder.appendln("Wonder") if (!forBuildingPickerScreen && requiredTech != null) - stringBuilder.appendln("Requires $requiredTech to be researched") + stringBuilder.appendln("Requires {$requiredTech} to be researched".tr()) if (!forBuildingPickerScreen && requiredBuilding != null) stringBuilder.appendln("Requires a $requiredBuilding to be built in this city") if (!forBuildingPickerScreen && requiredBuildingInAllCities != null) @@ -110,11 +110,11 @@ class Building : NamedStats(), IConstruction{ if (stats.toString() != "") stringBuilder.appendln(stats) if (this.percentStatBonus != null) { - if (this.percentStatBonus!!.production != 0f) stringBuilder.append("+" + this.percentStatBonus!!.production.toInt() + "% "+"Production".tr()+"\r\n") - if (this.percentStatBonus!!.gold != 0f) stringBuilder.append("+" + this.percentStatBonus!!.gold.toInt() + "% "+"Gold".tr()+"\r\n") - if (this.percentStatBonus!!.science != 0f) stringBuilder.append("+" + this.percentStatBonus!!.science.toInt() + "% "+"Science".tr()+"\r\n") - if (this.percentStatBonus!!.food != 0f) stringBuilder.append("+" + this.percentStatBonus!!.food.toInt() + "% "+"Food".tr()+"\r\n") - if (this.percentStatBonus!!.culture != 0f) stringBuilder.append("+" + this.percentStatBonus!!.culture.toInt() + "% "+"Culture".tr()+"\r\n") + if (this.percentStatBonus!!.production != 0f) stringBuilder.append("+" + this.percentStatBonus!!.production.toInt() + "% {Production}\n".tr()) + if (this.percentStatBonus!!.gold != 0f) stringBuilder.append("+" + this.percentStatBonus!!.gold.toInt() + "% {Gold}\n".tr()) + if (this.percentStatBonus!!.science != 0f) stringBuilder.append("+" + this.percentStatBonus!!.science.toInt() + "% {Science}\r\n".tr()) + if (this.percentStatBonus!!.food != 0f) stringBuilder.append("+" + this.percentStatBonus!!.food.toInt() + "% {Food}\n".tr()) + if (this.percentStatBonus!!.culture != 0f) stringBuilder.append("+" + this.percentStatBonus!!.culture.toInt() + "% {Culture}\r\n".tr()) } if (this.greatPersonPoints != null) { val gpp = this.greatPersonPoints!! @@ -124,14 +124,14 @@ class Building : NamedStats(), IConstruction{ if (gpp.culture != 0f) stringBuilder.appendln("+" + gpp.culture.toInt() + " Great Artist points") } if (resourceBonusStats != null) { - val resources = GameBasics.TileResources.values.filter { name == it.building }.joinToString { it.name } + val resources = GameBasics.TileResources.values.filter { name == it.building }.joinToString { it.name.tr() } stringBuilder.appendln("$resources provide $resourceBonusStats") } if(cityStrength!=0) stringBuilder.appendln("City strength +"+cityStrength) if(cityHealth!=0) stringBuilder.appendln("City health +"+cityHealth) if (maintenance != 0) - stringBuilder.appendln("Maintenance cost: $maintenance "+"Gold".tr()) + stringBuilder.appendln("Maintenance cost: $maintenance {Gold}".tr()) return stringBuilder.toString().trim() } diff --git a/core/src/com/unciv/models/gamebasics/Technology.kt b/core/src/com/unciv/models/gamebasics/Technology.kt index f82a04c5f0..384263106f 100644 --- a/core/src/com/unciv/models/gamebasics/Technology.kt +++ b/core/src/com/unciv/models/gamebasics/Technology.kt @@ -1,5 +1,6 @@ package com.unciv.models.gamebasics +import com.unciv.ui.utils.tr import java.util.* class Technology : ICivilopedia { @@ -9,9 +10,9 @@ class Technology : ICivilopedia { if(baseDescription!=null) SB.appendln(baseDescription) - val improvedImprovements = GameBasics.TileImprovements.values.filter { it.improvingTech==name }.groupBy { it.improvingTechStats.toString()!! } + val improvedImprovements = GameBasics.TileImprovements.values.filter { it.improvingTech==name }.groupBy { it.improvingTechStats.toString() } improvedImprovements.forEach{ - val impimpString = it.value.joinToString { it.name } +" provide" + (if(it.value.size==1) "s" else "") +" "+it.key + val impimpString = it.value.joinToString { it.name.tr() } +" provide" + (if(it.value.size==1) "s" else "") +" "+it.key SB.appendln(impimpString) } @@ -26,11 +27,11 @@ class Technology : ICivilopedia { val wonders = enabledBuildings.filter { it.isWonder } if(wonders.isNotEmpty()) SB.appendln("Wonders enabled: "+wonders.map { "\n * "+it.name+ " ("+it.getShortDescription()+")" }.joinToString()) - val revealedResource = GameBasics.TileResources.values.filter { it.revealedBy==name }.firstOrNull() // can only be one + val revealedResource = GameBasics.TileResources.values.filter { it.revealedBy==name }.map { it.name.tr() }.firstOrNull() // can only be one if(revealedResource!=null) SB.appendln("Reveals $revealedResource on map") val tileImprovements = GameBasics.TileImprovements.values.filter { it.techRequired==name } - if(tileImprovements.isNotEmpty()) SB.appendln("Tile improvements enabled: "+tileImprovements.map { it.name }.joinToString()) + if(tileImprovements.isNotEmpty()) SB.appendln("Tile improvements enabled: "+tileImprovements.map { it.name.tr() }.joinToString()) return SB.toString().trim() } diff --git a/core/src/com/unciv/models/gamebasics/unit/Unit.kt b/core/src/com/unciv/models/gamebasics/unit/Unit.kt index 9f8ca70398..0e292d2776 100644 --- a/core/src/com/unciv/models/gamebasics/unit/Unit.kt +++ b/core/src/com/unciv/models/gamebasics/unit/Unit.kt @@ -37,9 +37,9 @@ class Unit : INamed, IConstruction, ICivilopedia { fun getShortDescription(): String { val infoList= mutableListOf() if(baseDescription!=null) infoList+=baseDescription!! - if(strength!=0) infoList += "Strength".tr()+": $strength" - if(rangedStrength!=0) infoList += "Ranged strength".tr()+": $rangedStrength" - if(movement!=2) infoList+="Movement".tr()+": $movement" + if(strength!=0) infoList += "{Strength}: $strength".tr() + if(rangedStrength!=0) infoList += "{Ranged strength}: $rangedStrength".tr() + if(movement!=2) infoList+="{Movement}: $movement".tr() return infoList.joinToString() } @@ -49,12 +49,12 @@ class Unit : INamed, IConstruction, ICivilopedia { if(!forPickerScreen) { if (unbuildable) sb.appendln("Unbuildable") else sb.appendln("Cost: $cost") - if(requiredResource!=null) sb.appendln("Required resource: $requiredResource") - if(requiredTech!=null) sb.appendln("Required tech: $requiredTech") + if(requiredResource!=null) sb.appendln("Required resource: {$requiredResource}".tr()) + if(requiredTech!=null) sb.appendln("Required tech: {$requiredTech}".tr()) } if(strength!=0){ - sb.append("Strength".tr()+": $strength") - if(rangedStrength!=0) sb.append(", "+"Ranged strength".tr()+": $rangedStrength") + sb.append("{Strength} $strength".tr()) + if(rangedStrength!=0) sb.append(", {Ranged strength}: $rangedStrength".tr()) sb.appendln() } @@ -62,7 +62,7 @@ class Unit : INamed, IConstruction, ICivilopedia { for(unique in uniques!!) sb.appendln(unique) } - sb.appendln("Movement".tr()+": $movement") + sb.appendln("{Movement}: $movement".tr()) return sb.toString() } diff --git a/core/src/com/unciv/ui/cityscreen/CityStatsTable.kt b/core/src/com/unciv/ui/cityscreen/CityStatsTable.kt index c0727e484b..c3cad71e30 100644 --- a/core/src/com/unciv/ui/cityscreen/CityStatsTable.kt +++ b/core/src/com/unciv/ui/cityscreen/CityStatsTable.kt @@ -61,7 +61,7 @@ class CityStatsTable(val cityScreen: CityScreen) : Table(){ !(construction is Building && construction.isWonder)) { row() val buildingGoldCost = construction.getGoldCost(city.civInfo.policies.getAdoptedPolicies()) - val buildingBuyButton = TextButton("Buy for".tr()+"\r\n$buildingGoldCost "+"Gold".tr(), CameraStageBaseScreen.skin) + val buildingBuyButton = TextButton("{Buy for}\r\n$buildingGoldCost {Gold}".tr(), CameraStageBaseScreen.skin) buildingBuyButton.addClickListener { city.cityConstructions.purchaseBuilding(city.cityConstructions.currentConstruction) update() diff --git a/core/src/com/unciv/ui/pickerscreens/TechPickerScreen.kt b/core/src/com/unciv/ui/pickerscreens/TechPickerScreen.kt index a2c84d5c7f..e5413b8260 100644 --- a/core/src/com/unciv/ui/pickerscreens/TechPickerScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/TechPickerScreen.kt @@ -88,7 +88,7 @@ class TechPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen() } TB.isChecked = false - var text = techName + var text = techName.tr() if (techName == selectedTech?.name) { TB.isChecked = true diff --git a/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt b/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt index 5b8b2fae12..0ad971de56 100644 --- a/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt +++ b/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt @@ -127,7 +127,13 @@ fun Actor.centerY(parent:Stage){ y = parent.height/2- height/2} fun Actor.center(parent:Stage){ centerX(parent); centerY(parent)} fun Label.setFontColor(color:Color): Label {style=Label.LabelStyle(style).apply { fontColor=color }; return this} -fun String.tr(): String {return GameBasics.Translations.get(this,UnCivGame.Current.settings.language)} +fun String.tr(): String { + if(contains("{")){ // sentence + var toReturn = this + return Regex("\\{(.*)}").replace(this,{matchResult -> matchResult.groups[1]!!.value.tr() }) + } + else return GameBasics.Translations.get(this,UnCivGame.Current.settings.language) // single word +}