Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing translatables again #6705

Merged
merged 1 commit into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/assets/jsons/translations/template.properties
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ No problems found. =
Autoupdate mod uniques =
Uniques updated! =

Max zoom out =
Show experimental world wrap for maps =
HIGHLY EXPERIMENTAL - YOU HAVE BEEN WARNED! =
Enable portrait orientation =
Expand Down Expand Up @@ -781,7 +782,6 @@ Our [name] took [tileDamage] tile damage and was destroyed =
Our [name] took [tileDamage] tile damage =
[civName] has adopted the [policyName] policy =
An unknown civilization has adopted the [policyName] policy =
Our influence with City-States has started dropping faster! =
You gained [Stats] as your religion was spread to [cityName] =
You gained [Stats] as your religion was spread to an unknown city =
Your city [cityName] was converted to [religionName]! =
Expand Down
11 changes: 6 additions & 5 deletions core/src/com/unciv/models/ruleset/Building.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.unciv.models.translations.fillPlaceholders
import com.unciv.models.translations.tr
import com.unciv.ui.civilopedia.FormattedLine
import com.unciv.ui.utils.Fonts
import com.unciv.ui.utils.getConsumesAmountString
import com.unciv.ui.utils.toPercent
import kotlin.math.pow

Expand Down Expand Up @@ -109,13 +110,13 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction {
if (isWonder) lines += "Wonder"
if (isNationalWonder) lines += "National Wonder"
if (!isFree) {
val availableResources = if(!showAdditionalInfo) emptyMap()
val availableResources = if (!showAdditionalInfo) emptyMap()
else cityInfo.civInfo.getCivResources().associate { it.resource.name to it.amount }
for ((resource, amount) in getResourceRequirements()) {
val available = availableResources[resource] ?: 0
lines += if (showAdditionalInfo)
"{Consumes [$amount] [$resource]} ({[$available] available})"
else "Consumes [$amount] [$resource]"
"{${resource.getConsumesAmountString(amount)}} ({[$available] available})"
else resource.getConsumesAmountString(amount)
}
}

Expand Down Expand Up @@ -244,7 +245,7 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction {
for ((resource, amount) in resourceRequirements) {
textList += FormattedLine(
// the 1 variant should deprecate some time
if (amount == 1) "Consumes 1 [$resource]" else "Consumes [$amount] [$resource]",
resource.getConsumesAmountString(amount),
link="Resources/$resource", color="#F42" )
}
}
Expand Down Expand Up @@ -650,7 +651,7 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction {

for ((resource, amount) in getResourceRequirements())
if (civInfo.getCivResourcesByName()[resource]!! < amount) {
rejectionReasons.add(RejectionReason.ConsumesResources.toInstance("Consumes [$amount] [$resource]" ))
rejectionReasons.add(RejectionReason.ConsumesResources.toInstance(resource.getConsumesAmountString(amount)))
}

if (requiredNearbyImprovedResources != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,8 @@ enum class UniqueParameterType(
override fun getTranslationWriterStringsForOutput() = scanExistingValues(this)
},

/** We don't know anything about this parameter - this needs to return
* [isTranslationWriterGuess]() == `true` for all inputs or TranslationFileWriter will have a problem! */
Unknown("param", "Unknown") {
override fun getErrorSeverity(parameterText: String, ruleset: Ruleset):
UniqueType.UniqueComplianceErrorSeverity? = null
Expand Down
7 changes: 4 additions & 3 deletions core/src/com/unciv/models/ruleset/unit/BaseUnit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.unciv.models.translations.tr
import com.unciv.ui.civilopedia.FormattedLine
import com.unciv.ui.utils.Fonts
import com.unciv.ui.utils.filterAndLogic
import com.unciv.ui.utils.getConsumesAmountString
import com.unciv.ui.utils.toPercent
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
Expand Down Expand Up @@ -78,7 +79,7 @@ class BaseUnit : RulesetObject(), INonPerpetualConstruction {
val availableResources = cityInfo.civInfo.getCivResources().associate { it.resource.name to it.amount }
for ((resource, amount) in getResourceRequirements()) {
val available = availableResources[resource] ?: 0
lines += "Consumes ${if (amount == 1) "1" else "[$amount]"} [$resource] ({[$available] available})".tr()
lines += "{${resource.getConsumesAmountString(amount)}} ({[$available] available})".tr()
}
var strengthLine = ""
if (strength != 0) {
Expand Down Expand Up @@ -147,7 +148,7 @@ class BaseUnit : RulesetObject(), INonPerpetualConstruction {
textList += FormattedLine()
for ((resource, amount) in resourceRequirements) {
textList += FormattedLine(
if (amount == 1) "Consumes 1 [$resource]" else "Consumes [$amount] [$resource]",
resource.getConsumesAmountString(amount),
link = "Resource/$resource", color = "#F42"
)
}
Expand Down Expand Up @@ -441,7 +442,7 @@ class BaseUnit : RulesetObject(), INonPerpetualConstruction {
if (!civInfo.isBarbarian()) { // Barbarians don't need resources
for ((resource, amount) in getResourceRequirements())
if (civInfo.getCivResourcesByName()[resource]!! < amount) {
rejectionReasons.add(RejectionReason.ConsumesResources.toInstance("Consumes [$amount] [$resource]"))
rejectionReasons.add(RejectionReason.ConsumesResources.toInstance(resource.getConsumesAmountString(amount)))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ object TranslationFileWriter {
UniqueParameterType.guessTypeForTranslationWriter(parameter, ruleset).parameterName
}
parameterNames.addNumberedParameter(parameterName)
if (parameterName == UniqueParameterType.Unknown.parameterName)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it (also) be UniqueParameterType.Comment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the guessing order doesn't consider that one. Predetermined guessing order (in UniqueParameterType.Companion) was an evil I didn't like but after testing seemed necessary.

resultStrings.add("$parameter = ") // Unknown parameter contents better be offered to translators too
}
resultStrings.add("${stringToTranslate.fillPlaceholders(*parameterNames.toTypedArray())} = ")
}
Expand Down
8 changes: 2 additions & 6 deletions core/src/com/unciv/ui/cityscreen/CityConstructionsTable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,7 @@ class CityConstructionsTable(private val cityScreen: CityScreen) {
val useStoredProduction = entry is Building || !cityConstructions.isBeingConstructedOrEnqueued(entry.name)
var buttonText = entry.name.tr() + cityConstructions.getTurnsToConstructionString(entry.name, useStoredProduction)
for ((resource, amount) in entry.getResourceRequirements()) {
buttonText += "\n" + (
if (amount == 1) "Consumes 1 [$resource]"
else "Consumes [$amount] [$resource]"
).tr()
buttonText += "\n" + resource.getConsumesAmountString(amount).tr()
}

constructionButtonDTOList.add(
Expand Down Expand Up @@ -277,8 +274,7 @@ class CityConstructionsTable(private val cityScreen: CityScreen) {

val constructionResource = cityConstructions.getConstruction(constructionName).getResourceRequirements()
for ((resource, amount) in constructionResource)
text += if (amount == 1) "\n" + "Consumes 1 [$resource]".tr()
else "\n" + "Consumes [$amount] [$resource]".tr()
text += "\n" + resource.getConsumesAmountString(amount).tr()

table.defaults().pad(2f).minWidth(40f)
if (isFirstConstructionOfItsKind) table.add(getProgressBar(constructionName)).minWidth(5f)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class ReligionOverviewTab(
val manager = religion.getFounder().religionManager
statsTable.add("Cities following this religion:".toLabel())
statsTable.add(manager.numberOfCitiesFollowingThisReligion().toLabel()).right().row()
statsTable.add("{Followers of this religion}:".toLabel())
statsTable.add("Followers of this religion:".toLabel())
statsTable.add(manager.numberOfFollowersFollowingThisReligion("in all cities").toLabel()).right().row()

val minWidth = max(statsTable.minWidth, beliefsTable.minWidth) + 5
Expand Down
4 changes: 2 additions & 2 deletions core/src/com/unciv/ui/trade/DiplomacyScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -930,9 +930,9 @@ class DiplomacyScreen(
rightSideTable.clear()
rightSideTable.add(diplomacyTable)
}

private fun getGoToOnMapButton(civilization: CivilizationInfo): TextButton {
val goToOnMapButton = TextButton("Go to on map", skin)
val goToOnMapButton = "Go to on map".toTextButton()
goToOnMapButton.onClick {
UncivGame.Current.setWorldScreen()
UncivGame.Current.worldScreen.mapHolder.setCenterPosition(civilization.getCapital().location, selectUnit = false)
Expand Down
8 changes: 8 additions & 0 deletions core/src/com/unciv/ui/utils/ExtensionFunctions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -372,3 +372,11 @@ fun <T> String.filterCompositeLogic(predicate: (String) -> T?, operation: (T, T)
* otherwise return `null` for Elvis chaining of the individual filter. */
fun String.filterAndLogic(predicate: (String) -> Boolean): Boolean? =
if (contains('{')) filterCompositeLogic(predicate) { a, b -> a && b } else null


/** Convert a [resource name][this] into "Consumes [amount] $resource" string (untranslated, using separate templates for 1 and other amounts) */
//todo some day... remove and use just one translatable where this is called
fun String.getConsumesAmountString(amount: Int) = (
if (amount == 1) "Consumes 1 [$this]"
else "Consumes [$amount] [$this]"
)