mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-03 12:54:43 +07:00
Unit test against unmatched placeholders in a translation (#10863)
This commit is contained in:
parent
6b469cb25b
commit
975b2ba165
@ -117,6 +117,33 @@ class TranslationTests {
|
||||
)
|
||||
}
|
||||
|
||||
/** For every translatable string and all translations check if all translated placeholders are present in the key */
|
||||
@Test
|
||||
fun allTranslationsHaveNoExtraPlaceholders() {
|
||||
var allTranslationsHaveNoExtraPlaceholders = true
|
||||
val languages = translations.getLanguages()
|
||||
for ((key, translation) in translations) {
|
||||
val translationEntry = translation.entry
|
||||
val placeholders = squareBraceRegex.findAll(translationEntry)
|
||||
.map { it.value }.toSet()
|
||||
for (language in languages) {
|
||||
val output = translations.getText(key, language)
|
||||
if (output == key) continue // the language doesn't have the required translation, so we got back the key
|
||||
val translatedPlaceholders = squareBraceRegex.findAll(output)
|
||||
.map { it.value }.toSet()
|
||||
val extras = translatedPlaceholders - placeholders
|
||||
for (placeholder in extras) {
|
||||
allTranslationsHaveNoExtraPlaceholders = false
|
||||
println("Extra placeholder `$placeholder` in `$language` for entry `$translationEntry`")
|
||||
}
|
||||
}
|
||||
}
|
||||
Assert.assertTrue(
|
||||
"This test will only pass when all placeholders in all translations are present in the key",
|
||||
allTranslationsHaveNoExtraPlaceholders
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun allPlaceholderKeysMatchEntry() {
|
||||
var allPlaceholderKeysMatchEntry = true
|
||||
|
Loading…
Reference in New Issue
Block a user