简体   繁体   English

使用Xib和Swift的iOS本地化:有人可以帮助我使用XIB(不是Storyboard)和Swift制作多语言应用程序吗?

[英]iOS Localization using Xib & Swift: Can someone help me to make an multilingual app using XIB (not Storyboard) and Swift?

I searched for tutorials for localization but all are for storyboard, my app is made up in xib. 我搜索了本地化的教程,但所有的教程都是故事板,我的应用程序是用xib编写的。 I also want to make the language change option inside my app using buttons, instead of changing it from Settings. 我也想使用按钮在我的应用程序中进行语言更改选项,而不是通过“设置”进行更改。

You can use XMLParser for this feature. 您可以将XMLParser用于此功能。

  • Place all your string inside an XML file and then read data from a file for the selected language. 将所有字符串放在XML文件中,然后从文件中读取所选语言的数据。
  • In delegate get a dictionary or key-value pair for string and then assign it to the label. 在委托中,获取字符串的字典或键值对,然后将其分配给标签。

在此处输入图片说明

Ex: 例如:

    let xmlParser: XMLParser = XMLParser()
    xmlParser.delegate = self
    xmlParser.parseXml(withLanguageIndex: baseIndex)

// In delegate XMLParserDelegate //在委托XMLParserDelegate中

func getValues(_ valueDict: [AnyHashable: Any]) {
    stringsXMLDict = valueDict
}

Hope it will help you. 希望对您有帮助。 Happy Coddling:) 快乐的拥抱:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM