mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-09 07:18:57 +07:00
Fix translation issues caused by nested brackets and braces (#7242)
* Fix translation issues * Readd comment * Reviews * Update translation line
This commit is contained in:

committed by
GitHub

parent
f9d150d28a
commit
b3cd36c70e
@ -86,7 +86,6 @@ Requires a [buildingName] in all cities =
|
||||
[buildingName] required: =
|
||||
Requires a [buildingName] in this city =
|
||||
Cannot be built with [buildingName] =
|
||||
Consumes 1 [resource] =
|
||||
Consumes [amount] [resource] =
|
||||
[amount] available =
|
||||
Required tech: [requiredTech] =
|
||||
@ -1186,7 +1185,7 @@ Number of your cities\ndemanding this resource for\n'We Love The King Day' =
|
||||
|
||||
[victoryType] Victory =
|
||||
Built [building] =
|
||||
Add all spaceship parts in capital =
|
||||
Add all [comment] in capital =
|
||||
Destroy all players =
|
||||
Capture all capitals =
|
||||
Complete [amount] Policy branches =
|
||||
|
@ -350,8 +350,15 @@ fun String.tr(): String {
|
||||
return fullyTranslatedString
|
||||
}
|
||||
|
||||
// curly and square brackets can be nested inside of each other so find the leftmost curly/square
|
||||
// bracket then process that first
|
||||
val indexSquare = this.indexOf('[')
|
||||
val indexCurly = this.indexOf('{')
|
||||
val processSquare = indexSquare >= 0 && (indexCurly < 0 || indexSquare < indexCurly)
|
||||
val processCurly = indexCurly >= 0 && (indexSquare < 0 || indexCurly < indexSquare)
|
||||
|
||||
// There might still be optimization potential here!
|
||||
if (contains('[')) { // Placeholders!
|
||||
if (processSquare) { // Placeholders!
|
||||
/**
|
||||
* I'm SURE there's an easier way to do this but I can't think of it =\
|
||||
* So what's all this then?
|
||||
@ -399,12 +406,10 @@ fun String.tr(): String {
|
||||
return languageSpecificPlaceholder // every component is already translated
|
||||
}
|
||||
|
||||
|
||||
if (contains('{')) { // Translating partial sentences
|
||||
if (processCurly) { // Translating partial sentences
|
||||
return curlyBraceRegex.replace(this) { it.groups[1]!!.value.tr() }
|
||||
}
|
||||
|
||||
|
||||
if (Stats.isStats(this)) return Stats.parse(this).toString()
|
||||
|
||||
val translation = UncivGame.Current.translations.getText(this, language, TranslationActiveModsCache.activeMods)
|
||||
|
@ -15,9 +15,8 @@ fun Int.toPercent() = toFloat().toPercent()
|
||||
/** Translate a percentage number - e.g. 25 - to the multiplication value - e.g. 1.25f */
|
||||
fun Float.toPercent() = 1 + this/100
|
||||
|
||||
/** 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]"
|
||||
/** Convert a [resource name][this] into "Consumes [amount] $resource" string (untranslated) */
|
||||
fun String.getConsumesAmountString(amount: Int) = "Consumes [$amount] [$this]"
|
||||
|
||||
/** Formats the [Duration] into a translated string */
|
||||
fun Duration.format(): String {
|
||||
|
Reference in New Issue
Block a user