mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-22 13:49:54 +07:00
Resolved #5188 - stat names also include the stat icon :)
This commit is contained in:
@ -3,6 +3,7 @@ package com.unciv.models.translations
|
|||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
import com.unciv.UncivGame
|
import com.unciv.UncivGame
|
||||||
import com.unciv.models.ruleset.unique.Unique
|
import com.unciv.models.ruleset.unique.Unique
|
||||||
|
import com.unciv.models.stats.Stat
|
||||||
import com.unciv.models.stats.Stats
|
import com.unciv.models.stats.Stats
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.collections.HashMap
|
import kotlin.collections.HashMap
|
||||||
@ -289,7 +290,8 @@ fun String.tr(): String {
|
|||||||
// translated conditionals, removing the <> surrounding them, and removing param values
|
// translated conditionals, removing the <> surrounding them, and removing param values
|
||||||
// where it exists.
|
// where it exists.
|
||||||
val conditionalOrdering = UncivGame.Current.translations.getConditionalOrder(language)
|
val conditionalOrdering = UncivGame.Current.translations.getConditionalOrder(language)
|
||||||
for (placedConditional in pointyBraceRegex.findAll(conditionalOrdering).map { it.value.substring(1, it.value.length-1).getPlaceholderText() }) {
|
for (placedConditional in pointyBraceRegex.findAll(conditionalOrdering)
|
||||||
|
.map { it.value.substring(1, it.value.length - 1).getPlaceholderText() }) {
|
||||||
if (placedConditional in conditionals) {
|
if (placedConditional in conditionals) {
|
||||||
translatedConditionals.add(conditionsWithTranslation[placedConditional]!!)
|
translatedConditionals.add(conditionsWithTranslation[placedConditional]!!)
|
||||||
conditionsWithTranslation.remove(placedConditional)
|
conditionsWithTranslation.remove(placedConditional)
|
||||||
@ -310,7 +312,9 @@ fun String.tr(): String {
|
|||||||
translatedConditionals.add(translatedBaseUnique)
|
translatedConditionals.add(translatedBaseUnique)
|
||||||
}
|
}
|
||||||
|
|
||||||
var fullyTranslatedString = translatedConditionals.joinToString(UncivGame.Current.translations.getSpaceEquivalent(language))
|
var fullyTranslatedString = translatedConditionals.joinToString(
|
||||||
|
UncivGame.Current.translations.getSpaceEquivalent(language)
|
||||||
|
)
|
||||||
if (UncivGame.Current.translations.shouldCapitalize(language))
|
if (UncivGame.Current.translations.shouldCapitalize(language))
|
||||||
fullyTranslatedString = fullyTranslatedString.replaceFirstChar { it.uppercase() }
|
fullyTranslatedString = fullyTranslatedString.replaceFirstChar { it.uppercase() }
|
||||||
return fullyTranslatedString
|
return fullyTranslatedString
|
||||||
@ -335,7 +339,7 @@ fun String.tr(): String {
|
|||||||
val translationStringWithSquareBracketsOnly = this.getPlaceholderText()
|
val translationStringWithSquareBracketsOnly = this.getPlaceholderText()
|
||||||
// That is now the key into the translation HashMap!
|
// That is now the key into the translation HashMap!
|
||||||
val translationEntry = UncivGame.Current.translations
|
val translationEntry = UncivGame.Current.translations
|
||||||
.get(translationStringWithSquareBracketsOnly, language, activeMods)
|
.get(translationStringWithSquareBracketsOnly, language, activeMods)
|
||||||
|
|
||||||
var languageSpecificPlaceholder: String
|
var languageSpecificPlaceholder: String
|
||||||
val originalEntry: String
|
val originalEntry: String
|
||||||
@ -351,12 +355,16 @@ fun String.tr(): String {
|
|||||||
// Take the terms in the message, WITHOUT square brackets
|
// Take the terms in the message, WITHOUT square brackets
|
||||||
val termsInMessage = this.getPlaceholderParameters()
|
val termsInMessage = this.getPlaceholderParameters()
|
||||||
// Take the term from the placeholder, INCLUDING the square brackets
|
// Take the term from the placeholder, INCLUDING the square brackets
|
||||||
val termsInTranslationPlaceholder = squareBraceRegex.findAll(originalEntry).map { it.value }.toList()
|
val termsInTranslationPlaceholder =
|
||||||
|
squareBraceRegex.findAll(originalEntry).map { it.value }.toList()
|
||||||
if (termsInMessage.size != termsInTranslationPlaceholder.size)
|
if (termsInMessage.size != termsInTranslationPlaceholder.size)
|
||||||
throw Exception("Message $this has a different number of terms than the placeholder $translationEntry!")
|
throw Exception("Message $this has a different number of terms than the placeholder $translationEntry!")
|
||||||
|
|
||||||
for (i in termsInMessage.indices) {
|
for (i in termsInMessage.indices) {
|
||||||
languageSpecificPlaceholder = languageSpecificPlaceholder.replace(termsInTranslationPlaceholder[i], termsInMessage[i].tr())
|
languageSpecificPlaceholder = languageSpecificPlaceholder.replace(
|
||||||
|
termsInTranslationPlaceholder[i],
|
||||||
|
termsInMessage[i].tr()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
return languageSpecificPlaceholder // every component is already translated
|
return languageSpecificPlaceholder // every component is already translated
|
||||||
}
|
}
|
||||||
@ -367,7 +375,12 @@ fun String.tr(): String {
|
|||||||
|
|
||||||
if (Stats.isStats(this)) return Stats.parse(this).toString()
|
if (Stats.isStats(this)) return Stats.parse(this).toString()
|
||||||
|
|
||||||
return UncivGame.Current.translations.getText(this, language, activeMods)
|
val translation = UncivGame.Current.translations.getText(this, language, activeMods)
|
||||||
|
|
||||||
|
val stat = Stat.values().firstOrNull { it.name == this }
|
||||||
|
if (stat != null) return stat.character + translation
|
||||||
|
|
||||||
|
return translation
|
||||||
}
|
}
|
||||||
|
|
||||||
fun String.getPlaceholderText() = this
|
fun String.getPlaceholderText() = this
|
||||||
|
Reference in New Issue
Block a user