用于XIB文件的iOS Localizable.strings文件? [英] iOS Localizable.strings file for XIB files?

查看:160
本文介绍了用于XIB文件的iOS Localizable.strings文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将iOS项目翻译成葡萄牙语,我创建了一个pt.lproj / Localizable.strings文件,并在源代码中添加了NSLocalizedString()。一切正常!有一个小问题 - XIB文件中的字符串不会被翻译...我知道这是设计的。



我看到ibtool命令可以用于从名为x的XIB文件中翻录字符串并将其放入名为x.strings的文件...但我的问题是,有没有办法从所有xib文件中提取字符串并将它们全部放入一个.strings文件(例如Localizable.strings?或者甚至是另一个名为XIBs.strings的文章会没问题?)

解决方案

你有两个选择翻译xib文件。一种是将UI元素连接到outlet,并使用 NSLocalizedString 宏在viewDidLoad方法中设置字符串。



第二个选项是为您的应用支持的每种语言提供单独的xib。您不必手动创建它们,您可以使用 ibtool 命令(我假设您的源语言是英语,目标是葡萄牙语):

  ibtool --strings-file pt.lproj / Example.strings en.lproj / Example.xib -write pt.lproj / Example.xib 

要收集项目中找到的字符串,您可以使用 genstrings 命令 - 但我建议使用这个 python脚本来收集所有字符串 - 它可以很好地处理这种情况当您需要在应用中添加/删除字符串而无需翻译和/或手动合并所有以前的字符串



编辑



哦,我找到了文章我从
中学到了这个技巧

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?)

解决方案

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):

ibtool --strings-file pt.lproj/Example.strings en.lproj/Example.xib –write pt.lproj/Example.xib

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 strings

Edit

Oh and i found the article that i learned this trick from

这篇关于用于XIB文件的iOS Localizable.strings文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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