.lproj和Localizable.strings:具有本地化文本的项目? [英] .lproj and Localizable.strings : project with localized text?

查看:58
本文介绍了.lproj和Localizable.strings:具有本地化文本的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读有关本地化和国际化的文档,但是对我来说还不是很清楚:您能否解释一下.lproj文件和/或Localizable.strings文件(如果已连接)之间的链接?

或者有机会,如果您知道我可以在哪里看到/下载使用本地化文本的应用示例?

我已经看到了带有示例代码"NavBar"(来自doc)的Localizable.strings文件,但是关于使用.lproj文件的示例代码,却一无所获.

感谢您的帮助

解决方案

这很简单:为每个本地化创建一个文件夹,本地化名称后跟".lproj",您可以在其中放置任何可本地化的文件(也可以本地化图片)和Localizable.strings(包含obj-c API返回的用于本地化的文本).不要忘记在Xcode中将文件添加到资源中.

例如,如果您有3个本地化版本,则可以采用以下结构:

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

en.lproj/Localizable.strings具有英文字符串,依此类推.在您的Xcode上添加三个Localizable.strings(它将足够聪明地进行分组),然后完成.

要使用本地化的字符串,只需调用NSLocalizedString(NSString * key,NSString * comment),它将在您的Localizable.strings文件中自动查找当前语言环境的键,并返回与该键关联的值.有关NSLocalizedString的更多信息,请参见 解决方案

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.

这篇关于.lproj和Localizable.strings:具有本地化文本的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆