Our iOS app is translated into 19 languages, and recently I found an issue where two buttons on a screen had the same title - which mean that users couldn't tell which to press!
I want to write a unit test that will check two NSLocalizedString
keys in a particular locale, and make sure they don't collide.
How can I lookup the value of an NSLocalizedString in an arbitrary locale?
(For example, let's say I want to find the translated versions of "Delete" and "Remove", or something like that, and make sure those two translated strings aren't the same.)
(I'm guessing that the answer is going to involve something with Bundle
?)
Here's the pseudocode of what I'm looking for:
class TranslationTest: XCTest {
func testNoTranslationCollision() {
let allLocales = // list of all supported locales in the app
allLocales.forEach { locale in
let translatedStringA = "Remove".asTranslatedIn(locale)
let translatedStringB = "Delete".asTranslatedIn(locale)
XCTAssertNotEqual(
translatedStringA,
translatedStringB,
"The translations for these different strings shouldn't be identical!"
)
}
}
}