【发布时间】:2026-02-11 00:10:02
【问题描述】:
在我的应用程序中,我有 3 个数组,一个用于基本语言(英语),另外两个用于本地化。我可以根据用户设备上设置的语言选择特定的数组吗?例如,如果设备设置为使用德语,我想将短语翻译成德语。
这是我创建的变量
var enQuotes:[String] = []
var itQuotes:[String] = []
var deQuotes:[String] = []
这是从文件中获取引号的方法
enQuotes = quotes_en.getEnQuotes()
itQuotes = quotes_it.getItQuotes()
deQuotes = quotes_de.getDeQuotes()
这是我用来设置随机短语的代码
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
if let firstTouch = touches.first {
let hitView = self.view.hitTest(firstTouch.location(in: self.view), with: event)
if hitView === backgroundView {
let randomArray = Int(arc4random_uniform(UInt32(enQuotes.count)))
phraseLbl.text = (enQuotes[randomArray])
print("touch is inside")
} else {
print("touch is outside")
}
}
}
【问题讨论】:
-
如何使用
LocalizedString()。您为每个引号设置键/值,然后构造一个数组?
标签: ios arrays iphone swift translate