递归xgettext?
如何使用 xgettext 和 PHP 文件通过单个命令递归编译 .po
文件?
我的 PHP 文件存在于层次结构中,直接的 xgettext 命令似乎无法递归地向下挖掘。
How can I compile a .po
file using xgettext with PHP files with a single command recursively?
My PHP files exist in a hierarchy, and the straight xgettext
command doesn't seem to dig down recursively.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
明白了:
我之前尝试使用 -exec ,但一次只能运行一个文件。这使他们在一堆上运行。
谷歌呀!
Got it:
I was trying to use
-exec
before, but that would only run one file at a time. This runs them on the bunch.Yay Google!
对于 WINDOWS 命令行,一个简单的解决方案是:
For WINDOWS command line a simpe solution is:
您无法通过一个命令来实现这一目标。 xgettext 选项
--files-from
是你的朋友。如果您确定您没有太多源文件,您还可以将
find
与xargs
一起使用:但是,如果您有太多源文件,
xargs< /code> 将多次调用
xgettext
,以便不超过平台的最大命令行长度。为了保护自己免受这种情况的影响,您必须使用 xgettext 选项-j
、--join-existing
,首先删除过时的消息文件,然后从一个空的消息文件开始一个这样 xgettext 就不会退出:将其与首先给出的简单解决方案与 POTFILES 中的源文件列表进行比较!
将
find
与--exec
一起使用的效率非常低,因为它会为每个源文件调用一次xgettext -j
来搜索可翻译的字符串。在 xgettext -j 的特定情况下,效率甚至更低,因为 xgettext 必须在每次调用(即每个输入源)时读取不断增长的现有输出文件messages.po
文件)。You cannot achieve this with one single command. The xgettext option
--files-from
is your friend.If you are positive that you do not have too many source files you can also use
find
withxargs
:However, if you have too many source files,
xargs
will invokexgettext
multiple times so that the maximum command-line length of your platform is not exceeded. In order to protect yourself against that case you have to use the xgettext option-j
,--join-existing
, remove the stale messages file first, and start with an empty one so that xgettext does not bail out:Compare that with the simple solution given first with the list of source files in
POTFILES
!Using
find
with--exec
is very inefficient because it will invokexgettext -j
once for every source file to search for translatable strings. In the particular case ofxgettext -j
it is even more inefficient because xgettext has to read the evergrowing existing output filemessages.po
with every invocation (that is with every input source file).这是 Windows 的解决方案。首先,安装 gettext 并从 GnuWin32 工具集中查找。
您可以随后运行以下命令:
输出文件在运行该命令之前必须存在,以便新定义可以与其合并。
Here's a solution for Windows. At first, install gettext and find from the GnuWin32 tools collection.
You can run the following command afterwards:
The output file has to exist prior to running the command, so the new definitions can be merged with it.
这是我在 Mac 上找到的递归搜索解决方案:
在扩展名为 php 的文件(包括子文件夹)中生成所有使用 gettext 方法的条目,并将它们插入到 Translations/messages.pot 中。
This is the solution I found for recursive search on Mac:
Generates entries for all uses of method gettext in files whose extension is php, including subfolders and inserts them in translations/messages.pot .