问题
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:
- Put all of the text in a database and load the text at runtime based on the language selected.
- Build several different ViewControllers with the text for each language and then switch which segue gets called based on the language selected.
- Do something unbelievably cumbersome with NSLocalizedStringFromTable
- 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