我在我的应用中实施了本地化。添加泰米尔语我按照以下链接 enter link description here 如何在编辑方案选项中选择泰米尔语。我没有看到泰米尔语。查看截图[![在此输入图像说明] [2]] [2] 如何在我的应用程序中添加泰米尔语言。任何人都帮助我。
答案 0 :(得分:1)
您无法在方案中添加它的原因是这些仅适用于iOS系统语言。泰米尔语不是iOS的可选系统语言,但您仍可以在本地化中使用它。在项目本地化中:
转到建议列表的底部,然后选择其他'。将打开一个新列表,您可以在那里选择泰米尔语。
从这里开始的项目变量。
作为应用语言,您需要实现语言选择器按钮。请参阅注释中的链接或执行以下操作,添加功能:
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)
}