XIB 文件的 iOS Localized.strings 文件?
我正在将一个 iOS 项目翻译成葡萄牙语,并创建了一个 pt.lproj/Localized.strings 文件,并将 NSLocalizedString() 添加到源代码中。一切正常!有一个小问题 - XIB 文件中的字符串没有被翻译......不过我知道这是设计使然。
我已经看到 ibtool 命令可用于从名为 x 的 XIB 文件中提取字符串并将其放入名为 x.strings 的文件中...但我的问题是,有没有办法从所有 xib 中提取字符串文件并将它们全部放入一个 .strings 文件中(例如 Localized.strings?或者甚至另一个名为 XIBs.strings 的文件也可以吗?)
I'm translating an iOS project into Portuguese and I've created a pt.lproj/Localizable.strings file, and I've added NSLocalizedString() into the source code. It all works! With one slight problem - the strings within XIB files don't get translated... I know this is by design though.
I've seen that the ibtool command can be used to rip strings from an XIB file called x and put it into a file called x.strings... but my question is, is there a way to pull the strings from ALL the xib files and put them all into one .strings file (e.g. Localizable.strings? or even another one called XIBs.strings would be fine?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如何翻译 xib 文件有两种选择。一种是将 UI 元素连接到插座,并使用 NSLocalizedString 宏在 viewDidLoad 方法中设置字符串。
第二个选项是为您的应用程序支持的每种语言提供单独的 xib。您不必手动创建它们,您可以使用 ibtool 命令(我假设您的源语言是英语,目标语言是葡萄牙语):
要收集在项目中找到的字符串,您可以使用
genstrings
命令 - 但是我建议使用这个 python 脚本 来收集所有字符串 -当您需要向应用程序添加/删除字符串时,它可以很好地处理这种情况,而无需翻译和/或手动合并所有以前的字符串编辑
哦,我发现了文章 我从中学到了这个技巧
You have two options how to translate xib files. One is you connect the UI elements to outlets and set your strings in your viewDidLoad method using the
NSLocalizedString
macros.The second option is to provide a separate xib for each language your app supports. You don't have to create them manually, you can use the
ibtool
command (i assume your source language is English and target is Portugese):To collect strings found in your project you can use
genstrings
command - however i recommend using this python script to collect all your strings - it can nicely handle the situation when you need to add/remove strings to your app without having to translate and/or manually merge all previous stringsEdit
Oh and i found the article that i learned this trick from
我创建了一个类别来执行此操作:
然后在您的视图中:
您需要添加对其他 UI 元素的支持(textField.placeholder = NSLocal...blah blah),但这对于 UILabel 和子元素来说是有用的。
性能方面可能不是很好,但可以完成工作。
I made a category to do this:
Then in your views:
You'll need to add support for other UI elements (textField.placeholder = NSLocal...blah blah), but that'll do the trick for UILabel and children.
Probably not great performance-wise but does the job.
这将取决于应用程序和本地化的数量,但一般来说,我更喜欢单独的 .xib 文件,因为布局可能会改变。将本地化文件放在 pt.lproj/ 中。
It's going to depend on the app and the number of localizations, but in general I prefer separate .xib files, because layout may change. Put the localized files in pt.lproj/.