Standard (or Best) Method for Localizing Long Strings for iOS

China☆狼群 提交于 2019-12-14 03:15:42

问题


I have a couple of help menus associated with the app I'm building for iPhone. Frankly, it's a lot of text, some of it courtesy of attorneys! I'm wrestling with several methods to implement this and wonder if there is a standard or best way. Here are the options I've been considering:

  1. Put all of the text in a database and load the text at runtime based on the language selected.
  2. Build several different ViewControllers with the text for each language and then switch which segue gets called based on the language selected.
  3. Do something unbelievably cumbersome with NSLocalizedStringFromTable
  4. Teach the whole world to speak English... only slightly harder than idea #3.

I don't need a step-by-step here, but a pointer to a common or best practice would be terrific.


回答1:


You must have Localizable.strings file for each language that your app supports. And in that Localizable.strings files do your localization:

And in your code just write:

self.welcomeLabel.text = NSLocalizedString(@"welcome_text",nil);

No database needed.




回答2:


Unless you have a reason not to, use .strings files and the NSLocalizedString functions.

I have only seen one instance where somebody implemented a means of managing thousands of strings in an SQLite DB. They did this because of the volume of strings and frequency of change as well as to enable a particular strings localization workflow and deployment model. It was clever though inelegant. It took a long time to work out kinks. Mostly in the maintenance and deployment system. It is still in use in an enterprise CRM. The point is unless you have reached a point where the standard mechanisms are not sufficient, don't try to build something more clever. There really isn't an easy way. What Apple provides, they actually use. The processes in getting things into place are the part you have to work out independently.



来源:https://stackoverflow.com/questions/23725483/standard-or-best-method-for-localizing-long-strings-for-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!