Fix broken translation (#7580)

This commit is contained in:
OptimizedForDensity 2022-08-02 11:23:37 -04:00 committed by GitHub
parent a3e7d5ccb6
commit 30e1dcbcdd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,7 +8,6 @@ import com.unciv.models.stats.Stat
import com.unciv.models.stats.Stats import com.unciv.models.stats.Stats
import com.unciv.utils.Log import com.unciv.utils.Log
import com.unciv.utils.debug import com.unciv.utils.debug
import java.time.temporal.ChronoUnit
import java.util.* import java.util.*
/** /**
@ -391,15 +390,14 @@ 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.getPlaceholderParametersIgnoringLowerLevelBraces() val termsInMessage = this.getPlaceholderParametersIgnoringLowerLevelBraces()
// Take the term from the placeholder, INCLUDING the square brackets // Take the terms from the placeholder
val termsInTranslationPlaceholder = val termsInTranslationPlaceholder = originalEntry.getPlaceholderParametersIgnoringLowerLevelBraces()
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( languageSpecificPlaceholder = languageSpecificPlaceholder.replace(
termsInTranslationPlaceholder[i], "[${termsInTranslationPlaceholder[i]}]", // re-add square brackets to placeholder terms
termsInMessage[i].tr() termsInMessage[i].tr()
) )
} }