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

标签 ios swift localization xcode9.2

我在我的应用中实现本地化。添加泰米尔语我点击以下链接 enter link description here 如何在编辑方案选项中选择泰米尔语。我没有看到泰米尔语。查看屏幕截图 [![在此处输入图片描述][2]][2] 如何在我的应用程序中添加泰米尔语。任何人帮助我。

最佳答案

之所以不能添加到方案中是因为这些仅适用于 iOS 系统语言。泰米尔语不是 iOS 的可选系统语言,但您仍然可以在本地化中使用它。在项目本地化中:

转到建议列表的底部并选择“其他”。将打开一个新列表,您可以在那里选择泰米尔语。

enter image description here

在项目变量中。

enter image description here

作为应用程序语言,您需要实现语言选择器按钮。看评论里的链接或者做下面的,添加一个函数:

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)
    }

关于ios - 如何在我的应用程序中添加泰米尔语。我的 Xcode 版本是 9.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49769241/

相关文章:

c# - asp.net 从其他本地资源读取

html - iOS设备上的CSS填充/边距问题

ios - 并行运行测试时 UI 测试的输出

ios - 数组!当我使用 NSString 时与 UInt8 不同

ios - 在 ios swift 中实现 Google Analytics

c# - 国家不可知的学术水平代表

ios - 从 iCloud 驱动器获取文件而不下载?

ios - Swift:无法在 SplitViewController 中调整 collectionViewCells 的大小

swift - 在本地保存整型变量

Android 中的 Java DateFormat.SHORT 未按预期工作