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

查看:13
本文介绍了如何将所有 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天全站免登陆