开发者

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

开发者 https://www.devze.com 2023-04-04 07:55 出处:网络
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 th

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 a开发者_运维技巧pp 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号