when I'm doing localizable, Bundle just not yet loaded,path should be right, coz when i print(fm.fileExists(atPath: path!)), it returns me true
Here's func initUserLanguage()
string = string.replacingOccurrences(of: "-CN", with: "")
.replacingOccurrences(of: "-US", with: "")
.replacingOccurrences(of: "-SG", with: "")
var path = Bundle.main.path(forResource: string, ofType: "lproj")
print("path 1 = \(String(describing: path))")
if path == nil {
def.set("en", forKey: UserLanguage)
def.synchronize()
path = Bundle.main.path(forResource: "en", ofType: "lproj")
print("path 2 = \(String(describing: path))")
}
bundle = Bundle(path: path!)
print(bundle!)
let fm = FileManager()
print(fm.fileExists(atPath: path!))
Here's the log
// ==== 1-1 - haven't change system language(Chinese), path exist,the Bundle(path)just not yet loaded string -> zh-Hans-SG
#####UserLanguage! -> zh-Hans-SG = zh-Hans-SGLanguageHelper - is guest LanguageHelper - loadData_Language - zh-Hans //when system language is Chinese, i send to server that i need Chinese API path 1 = Optional("/var/containers/Bundle/Application/0142208A-EC53-46C1-B6D8-276A5C5D87F7/DiningButlerSG.app/zh-Hans.lproj") bundle = Optional(NSBundle (not yet loaded)) true
// ==== 1-2 - after change system language(Chinese to English), path exist,the Bundle(path)just not yet loaded string -> zh-Hans-SG
#####UserLanguage! -> zh-Hans-SG = en-SGLanguageHelper - is guest LanguageHelper - loadData_Language - en //when system language is English, i send to server that i need English API path 1 = Optional("/var/containers/Bundle/Application/F185F1E3-0F34-4208-8D8A-F9362978BD9C/DiningButlerSG.app/en.lproj") bundle = Optional(NSBundle (not yet loaded)) true
// ==== 2 - after change system language(English to Japanese), path not exist,the Bundle(path)also not yet loaded string -> en-SG
#####UserLanguage! -> en-SG = ja-SGLanguageHelper - is guest LanguageHelper - loadData_Language - en ////when system language is Japanese(anyothers), i send to server that i need English API path 1 = nil path 2 = Optional("/var/containers/Bundle/Application/DDFACBDA-7AFA-4DD6-828E-E69F56B624BE/DiningButlerSG.app/en.lproj") bundle = Optional(NSBundle (not yet loaded)) true
However, the Localizable.strings and storyboard can work when switch system language between Chinese and English (but from log, actually path also not yet loaded)
i deleted and removed localizable file before, I'm afraid the path may messed so i clear all and recreate the localizable.strings again, is something wrong because of this?
答案 0 :(得分:0)
您无法从代码中加载有关语言更改的故事板。如果要为不同语言使用两个故事板,则必须重新启动代码。但您可以使用相同的故事板直接从代码中使用Localizable字符串进行语言更改。意味着您可以通过连接每个元素的出口来使用Langauge_Helper类更改文本。您将始终收到错误(尚未加载),但它适用于localizable.strings但您无法在不重新启动应用程序的情况下加载故事板。
希望有所帮助......