我在我的应用程序中实现了本地化。添加泰米尔语我遵循下面的链接在这里输入链接描述如何选择泰米尔语在编辑方案选项。我没看到泰米尔语。见截图如何在我的应用程序中添加泰米尔语。任何人都可以帮我。
发布于 2018-04-11 08:26:20
不能将其添加到方案中的原因是,它们只适用于iOS系统语言。泰米尔语不是iOS的可选系统语言,但您仍然可以在本地化中使用它。在项目本地化方面:
转到提议列表的底部,并选择“other”。一个新的名单将打开,你可以选择泰米尔语在那里。
从这里开始在项目变量中。
作为一种应用程序语言,您需要实现语言选择器按钮。请参阅注释中的链接或执行以下操作,添加一个函数:
func changeToLanguage(_ langCode: String) {
if Bundle.main.preferredLocalizations.first != langCode {
let message = NSLocalizedString("In order to change the language, the App must be closed and reopened by you.", comment: "")
let confirmAlertCtrl = UIAlertController(title: NSLocalizedString("App restart required", comment: ""), message: message, preferredStyle: .alert)
let confirmAction = UIAlertAction(title: NSLocalizedString("Close now", comment: ""), style: .destructive) { _ in
UserDefaults.standard.set([langCode], forKey: "AppleLanguages")
UserDefaults.standard.synchronize()
exit(EXIT_SUCCESS)
}
confirmAlertCtrl.addAction(confirmAction)
let cancelAction = UIAlertAction(title: NSLocalizedString("Cancel", comment: ""), style: .cancel, handler: nil)
confirmAlertCtrl.addAction(cancelAction)
present(confirmAlertCtrl, animated: true, completion: nil)
}
}
从一个按钮上呼叫:
@IBAction func didPressChangeLanguageButton() {
let message = NSLocalizedString("Change language of this app including its content.", comment: "")
let sheetCtrl = UIAlertController(title: NSLocalizedString("Choose language", comment: ""), message: message, preferredStyle: .actionSheet)
for languageCode in Bundle.main.localizations.filter({ $0 != "Base" }) {
let langName = Locale.current.localizedString(forLanguageCode: languageCode)
if languageCode != "(null)" {
let action = UIAlertAction(title: NSLocalizedString(langName!, comment: ""), style: .default) { _ in
self.changeToLanguage(languageCode) // see step #2
}
sheetCtrl.addAction(action)
}
}
let cancelAction = UIAlertAction(title: NSLocalizedString("Cancel", comment: ""), style: .cancel, handler: nil)
sheetCtrl.addAction(cancelAction)
sheetCtrl.popoverPresentationController?.sourceView = self.view
sheetCtrl.popoverPresentationController?.sourceRect = self.changeLanguageButton.frame
present(sheetCtrl, animated: true, completion: nil)
}
https://stackoverflow.com/questions/49769241
复制相似问题