xcode 如何在多个目录中使用 genstrings?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2744401/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 03:23:11  来源:igfitidea点击:

How to use genstrings across multiple directories?

xcodelocalization

提问by dontWatchMyProfile

I have an directory, which has a lot of subdirectories. those subdirs sometimes even have subdirs. there are source files inside.

我有一个目录,里面有很多子目录。这些子目录有时甚至有子目录。里面有源文件。

How could I use genstrings to go across all these dirs and subdirs?

我如何使用 genstrings 来遍历所有这些目录和子目录?

Let's say I cd to my root dir in Terminal, and then I would type this:

假设我在终端中 cd 到我的根目录,然后我会输入:

genstrings -o en.lproj *.m

How could I tell it now to look into all these directories? Or would I have to add a lot of relative paths comma separated? how?

我现在怎么能告诉它查看所有这些目录?或者我是否必须添加很多逗号分隔的相对路径?如何?

回答by Brian King

One method would be:

一种方法是:

find ./ -name "*.m" -print0 | xargs -0 genstrings -o en.lproj

xargs is a nice chunk of shell-foo. It will take strings on standard in and convert them into arguments for the next function. This will populate your genstrings command with every .m file beneath the current directory.

xargs 是一个不错的 shell-foo 块。它将采用标准输入中的字符串并将它们转换为下一个函数的参数。这将使用当前目录下的每个 .m 文件填充您的 genstrings 命令。

This answer handels spaces in the used path so it is more robust. You should use it to avoid skipping files when processing your source files.

这个答案处理使用的路径中的空格,因此它更健壮。您应该使用它来避免在处理源文件时跳过文件。

Edit: as said in the comments and in other answers, *.m should be quoted.

编辑:如评论和其他答案中所述,应该引用 *.m 。

回答by Jonathan Zhan

I don't know exactly why, but Brian's command didn't work for me. This did:

我不知道确切的原因,但布赖恩的命令对我不起作用。这做到了:

find . -name \*.m | xargs genstrings -o en.lproj

EDIT: Well, when I originally wrote this I was in a hurry and just needed something that worked. The issue that was occurring for me when using the accepted answer above was that "*.m" has to be quoted (and the curious can find an explanation as to why this is the case in the comments on Brian King's answer). I think that the best solution is to use that original answer with the appropriate bit quoted, which would then read:

编辑:嗯,当我最初写这篇文章时,我很匆忙,只需要一些有用的东西。在使用上面接受的答案时,我遇到的问题是必须引用“*.m”(好奇的人可以在对布赖恩金的答案的评论中找到解释为什么会出现这种情况)。我认为最好的解决方案是使用原始答案并引用适当的位,然后阅读:

find ./ -name "*.m" -print0 | xargs -0 genstrings -o en.lproj

I'm leaving my original reply intact above though, in case it still helps anybody for whatever reason.

不过,我将上面的原始回复原封不动,以防万一它仍然对任何人有帮助。

回答by SEG

This works for me:

这对我有用:

find ./ -name \*.m -print0 | xargs -0 genstrings -o en.lproj

Thanks to Brian and Uberhamster.

感谢布赖恩和 Uberhamster。

回答by Ashishail

Not sure if anyone noticed it or the option came later on, but now there is an -aoption is genstrings. None of the above options worked for me. Below is my solution.

不确定是否有人注意到它或该选项稍后出现,但现在有一个-a选项是 genstrings。以上选项都不适合我。下面是我的解决方案。

find ./ -name "*.m" -exec echo {} \; -exec genstrings -a -o en.lproj {} \;

This will also print the name of the files read.

这还将打印读取的文件的名称。

Though above command works fine, it was not exactly for me, because in my project folder there are many files which are lying in folder but not included in xcode project. So what I did was, created a list of files used in my project by parsing pbxproj file. Added the list in filelist.txt, and fired below command

虽然上面的命令工作正常,但它并不完全适合我,因为在我的项目文件夹中有很多文件位于文件夹中但不包含在 xcode 项目中。所以我所做的是,通过解析 pbxproj 文件创建了一个在我的项目中使用的文件列表。在 filelist.txt 中添加了列表,并在命令下方触发

while read f; do find ./ -name "$f" -exec echo {} \; -exec genstrings -a -o en.lproj {} \; ; done < filelist.txt

回答by Matt

Since no one has posted a solution with both Objective-C and Swift, I though I'd share how I do it.

由于没有人发布了同时使用 Objective-C 和 Swift 的解决方案,我想分享一下我是如何做到的。

find ./ -name "*.swift" -print0 -or -name "*.m" -print0 | xargs -0 genstrings -o en.lproj

By using this your localizable strings file will be replaced with strings from both the swift and objective-c files.

通过使用它,您的本地化字符串文件将被 swift 和 Objective-c 文件中的字符串替换。

Edit: You need to cdto the directory with all your subdirectories.

编辑:您需要进入cd包含所有子目录的目录。

回答by Rok Jarc

I a have a lot of code in .mm files so i have to use:

我在 .mm 文件中有很多代码,所以我必须使用:

find . -name \*.m -or -name \*.mm | xargs genstrings

or other variants, such as

或其他变体,例如

find . -name \*.m -or -name \*.mm | xargs -0 genstrings -o en.lproj

回答by Emmanuel Ay

I just added another path to the genstrings command, like this:

我刚刚为 genstrings 命令添加了另一个路径,如下所示:

genstrings -o en.lproj *.m Classes/*.m

..and it worked out fine!

..结果很好!

Btw. a handy thing about genstrings. When you continue developing your app, genstrings has a -a switch that appends new strings to the localized string file.

顺便提一句。关于 genstrings 的一个方便的事情。当您继续开发您的应用程序时,genstrings 有一个 -a 开关,用于将新字符串附加到本地化的字符串文件中。

回答by cbartel

The following improves on the earlier answers, this will find both .h and .m files:

以下改进了之前的答案,这将找到 .h 和 .m 文件:

find ./ -name *.h -print0 -o -name *.m -print0 | xargs -0 genstrings -o en.lproj

回答by raliz

I had problems generating the strings file for a folder structure where some of the folders had spaces in their names.

我在为文件夹结构生成字符串文件时遇到问题,其中某些文件夹的名称中有空格。

I found a nice solution on this site: http://riveroften.com/generate-localizable-strings-file-with-genstrings/

我在这个网站上找到了一个很好的解决方案:http: //riveroften.com/generate-localizable-strings-file-with-genstrings/

find . -name "*.m" -print0 | xargs -0 genstrings -o "en.lproj"

回答by anoop4real

Swift

迅速

find ./ -name \*.swift -print0 | xargs -0 genstrings -o .en.lproj

If you need the file in same folder

如果您需要同一文件夹中的文件

find ./ -name \*.swift -print0 | xargs -0 genstrings -o .