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

Posted

技术标签:

【中文标题】如何在我的应用程序中添加泰米尔语。我的 Xcode 版本是 9.2【英文标题】:How to add Tamil Language in my app. My Xcode Version is 9.2 【发布时间】:2018-04-11 07:41:25 【问题描述】:

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

【问题讨论】:

试试这个oneskyapp.com/academy/learn-ios-localization 嗨 Abhirajsinh Thakore 如何在编辑方案选项中选择泰米尔语 泰米尔语没有选项。怎么选?? 【参考方案1】:

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

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

从这里进入项目变量。

作为一种应用语言,您需要实现语言选择器按钮。查看 cmets 中的链接或执行以下操作,添加一个函数:

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)
    

【讨论】:

嗨 Zyntx 在编辑方案选项中没有其他选项 转到主项目并单击信息。我会再发一张图片。 @mouni:不能在方案中添加的原因是这些是iOS系统语言。泰米尔语不是 iOS 的可选系统语言,但您仍然可以在本地化中使用它。您需要在应用中实现语言选择器。 @mouni 并实现语言切换器查看此链接中提出的帮助程序类:change language programmatically

以上是关于如何在我的应用程序中添加泰米尔语。我的 Xcode 版本是 9.2的主要内容,如果未能解决你的问题,请参考以下文章

在我的应用程序中添加设置页面(Xcode 和 Swift)

在我的 OpenGL C++ 项目中究竟应该在哪里添加我的 BMP 文件?在 Mac 上使用 Xcode

如何在 Xcode 9.2 和 iPhone XS max 中添加模拟器 iPhone XS

如何使用相机谷歌地图 xcode 移动标记(图钉)

如何在我的 podfile 中为我的 Xcode 项目指定多个目标?

为啥我添加到我的 xcode 项目的音频文件在模拟器中可用,但在我在 iPhone 上部署应用程序时不可用