如何将所有XIB文件中的所有可本地化的字符串提取到一个文件中? [英] How can I extract all localizable strings from all XIB files into one file?

查看:88
本文介绍了如何将所有XIB文件中的所有可本地化的字符串提取到一个文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种从.xib文件中提取所有可本地化字符串并将它们保存在单个文件中的方法.

I am looking for a way of extracting all localizable strings from .xib files and have all of them saved in a single file.

可能这涉及到ibtool,但是我无法确定将所有这些合并到一个翻译词典中的方式(可能是.strings.plist或其他).

Probably this involves ibtool but I was not able to determine a way of merging all these in only one translation dictionary (could be .strings, .plist or something else).

推荐答案

打开终端,并cd到项目的根目录(或存储所有XIB文件的目录),然后键入以下命令:

Open terminal and cd to the root directory of the project (or directory where you store all XIB files) and type in this command:

find . -name \*.xib | xargs -t -I '{}' ibtool --generate-strings-file '{}'.txt '{}'

魔术是find和xargs命令一起工作. -I选项生成占位符. -t仅用于详细输出(您将看到已生成并执行了哪些命令). 它会生成与同一目录中的xib文件同名的txts文件. 可以改进此命令以将输出串联到一个文件中,但这仍然是一个很好的起点.

The magic is the find and xargs commands working together. -I option generates placeholder. -t is just for verbose output (you see what commands has been generated and executed). It generates txts files with the same name as xib files in the same directory. This command can be improved to concatenate output into one file but still is a good starting point.

将它们结合在一起:

您可以使用类似的终端命令将这些新创建的文件连接为一个文件:

You can concatenate those freshly created files into one using similar terminal command:

find . -name \*.xib.txt | xargs -t -I '{}' cat '{}' > ./xib-strings-concatenated.txt

此命令会将所有字符串放入根目录下的一个文件xib-strings-concatenated.txt.

This command will put all strings into one file xib-strings-concatenated.txt in root directory.

您可以再次使用find和xargs删除生成的部分文件(如果需要):

find . -name \*.xib.txt | xargs -t -I '{}' rm -f '{}'

这篇关于如何将所有XIB文件中的所有可本地化的字符串提取到一个文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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