gpt4 book ai didi

ios - lproj 文件尚未加载

转载 作者:行者123 更新时间:2023-11-28 15:47:25 24 4
gpt4 key购买 nike

我创建了 3 个带有翻译的文件:

  • localizable.strings(英文)
  • localizable.strings(瑞典语)
  • localizable.strings(芬兰语)

我有这个方法来按键获取字符串:

static func localized(key: String) -> String? {
if let path = Bundle.main.path(forResource: currentLanguage, ofType: "lproj") {
if let bundle = Bundle(path: path) {
return NSLocalizedString(key, tableName: nil, bundle: bundle, value: "", comment: "")
}
}

return nil;
}

但我得到了 "NSBundle (not yet loaded)"

为什么加载不出来,问题出在哪里?

最佳答案

像这样进行扩展

extension String {
func localized(lang:String) -> String {

let path = Bundle.main.path(forResource: lang, ofType: "lproj")
let bundle = Bundle(path: path!)

return NSLocalizedString(self, tableName: nil, bundle: bundle!, value: "", comment: "")

}

let label: UILabel
var language: String?
label.text = “Hello”.localized(lang: self.language! )

关于ios - lproj 文件尚未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42807516/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com