我们的iOS应用程序被翻译成19种语言,最近我发现一个问题,一个屏幕上的两个按钮有相同的标题--这意味着用户无法分辨该按哪个按钮!
我想要编写一个单元测试,它将在一个特定的地区检查两个NSLocalizedString键,并确保它们不会碰撞。
如何在任意地区查找NSLocalizedString的值?
(例如,假设我希望找到"Delete“和"Remove”的翻译版本,或者类似的内容,并确保这两个已翻译的字符串不相同。)
(我猜答案将涉及到Bundle?)
这是我要找的伪码:
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!"
)
}
}
}发布于 2020-08-28 13:18:18
现在,在Xcode 11中,您可以用测试计划为每个测试定义不同的配置。因此,定义不同的配置,每一个启动应用程序与特定语言。如果应用程序语言中没有显示波斯语这样的特定语言,则在启动时传递的参数中添加其语言代码,如下所示:
-AppleLanguages (en)在您的情况下,首先需要创建支持的语言代码数组,遍历数组,设置语言并比较字符串。
let stringA = NSLocalizedString("Remove",comment: "stringA")
let stringB = NSLocalizedString("Delete",comment: "stringB")
XCTAssertNotEqual(
stringA,
stringB,
"The translations for these different strings shouldn't be identical!"
)https://stackoverflow.com/questions/63626886
复制相似问题