按Localizable.strings中的值获取键



我在语言1中得到一个输入字符串,我想在Localizable.strings中找到它对应的键。稍后我将使用这个键在语言2中检索它的值。

如何按值查找密钥?

let stringsPath = Bundle.main.path(forResource: "Localizable", ofType: "strings")
var dictionary = NSDictionary (contentsOfFile: stringsPath ?? "")
if let temp = dictionary?.allValues.filter({$0 as? String == "Your Value to be searched"}), temp.count > 0 {
print("nice found")
}

使用上述代码进行检查。

最新更新