简体   繁体   中英

How to localize iOS (iPhone/iPad) app using only single storyboard?

I was wondering if somebody could explain in the details how I can localize an iOS app using only 1 storyboard. I know how to localize by creating several storyboards(one storyboard for each used language), however I'd like to find out another solution. Thanks.

The tutorial on raywenderlich.com uses two forms of localization together. The reason is he also checks the storyboard when turning on localisation in image 3: ray教程中的图片 .

So then what?

NSLocalizedString is very useful, any text set programatically can (and should) be localised using this method. Ray's tutorial is still very useful. However, it's not very desirable to create a clone of the storyboard(s) to do translation, it's just not very maintainable in the long run.

And what about storyboards?

The magic happens using the Base Localization feature. Base localization uses the generated objectId's to 'map' different languages to the storyboard.

Do note that this feature is only available using SDK 6.0 and above. Running the app on a lower iOS version will not cause any errors, it'll simply won't work.

  • Go to your project, and select Base Localization, then add any other language. 本土化

  • Open your storyboard file and check the new language as well. Note the icon is not a storyboard icon, but a simple text file icon. That's a good thing; it won't copy the whole storyboard this time :). 在此处输入图片说明

  • Note how there is now another file 'under' the storyboard. Xcode automatically generates a file for every language you select.

You can se Localization feature for this. You need to add the Localizable.strings file for each supported language and use it for locaization.

You need to use : NSLocalizedString() for fetcing data corresponding to each key.

Check this tutorial for details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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