mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 13:55:54 -04: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
|
@Test
|
||||||
fun allPlaceholderKeysMatchEntry() {
|
fun allPlaceholderKeysMatchEntry() {
|
||||||
var allPlaceholderKeysMatchEntry = true
|
var allPlaceholderKeysMatchEntry = true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user