.lproj and Localizable.strings : project with localized text?

梦想的初衷 提交于 2019-12-09 04:28:00

问题


i was reading the doc about localization and internationalization , but it's not really clear for me : can you explain me the link between the .lproj files, and/or the Localizable.strings file (if those are connected) ?

Or by any chance, if you know where i could see/download an example of an app using localized text?

I've seen the Localizable.strings file with the sample code 'NavBar' (from the doc), but nothing yet about a sample code using .lproj files.

Thanks for your help


回答1:


It's very simple: create a folder for each localization, with the localization name followed by ".lproj", there you put any localizable file (you can also localize images) and your Localizable.strings (which contains the text returned by the obj-c API for localization). Don't forget to add the files in your resources, in Xcode.

For exemple, if you have 3 localizations, you could have this structure:

PROJECT_DIR/
    - en.lproj/
        Localizable.strings
    - it.lproj/
        Localizable.strings
    - pt.lproj/
        Localizable.strings

en.lproj/Localizable.strings have the english strings, and so on. Add the three Localizable.strings on your Xcode (it will be smart enough to group then) and it's done.

To use the localized strings just call NSLocalizedString(NSString *key, NSString *comment), it will automatically look for the key in your Localizable.strings file for the current locale and return the value associated with the key. For more information about NSLocalizedString see NSLocalizedString.



来源:https://stackoverflow.com/questions/7381461/lproj-and-localizable-strings-project-with-localized-text

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