首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在我的应用程序中添加泰米尔语。我的Xcode版本是9.2

如何在我的应用程序中添加泰米尔语。我的Xcode版本是9.2
EN

Stack Overflow用户
提问于 2018-04-11 07:41:25
回答 1查看 634关注 0票数 0

我在我的应用程序中实现了本地化。添加泰米尔语我遵循下面的链接在这里输入链接描述如何选择泰米尔语在编辑方案选项。我没看到泰米尔语。见截图如何在我的应用程序中添加泰米尔语。任何人都可以帮我。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-11 08:26:20

不能将其添加到方案中的原因是,它们只适用于iOS系统语言。泰米尔语不是iOS的可选系统语言,但您仍然可以在本地化中使用它。在项目本地化方面:

转到提议列表的底部,并选择“other”。一个新的名单将打开,你可以选择泰米尔语在那里。

从这里开始在项目变量中。

作为一种应用程序语言,您需要实现语言选择器按钮。请参阅注释中的链接或执行以下操作,添加一个函数:

代码语言:javascript
运行
复制
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)
    }
} 

从一个按钮上呼叫:

代码语言:javascript
运行
复制
@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)
    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49769241

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档