只需要 xgettext 生成的翻译字符串,而不是源文件中的所有字符串

发布于 2024-10-30 22:49:45 字数 1076 浏览 3 评论 0原文

真的很挣扎这个。

我最近设置了一个 bash shell 脚本来提取、连接和删除重复的字符串,以从整个网站的视图页面(使用的 MVC 框架)中翻译出来,它看起来像这样:

for x in *.php; do xgettext --no-wrap --language=PHP -e --flag=_:1:pass-c-format -a "$x" -o "${x%.php}.pot"; done
msgcat -u -s --output-file=$WEBSITENAME-concat.pot *.pot
msguniq -u --output-file=$WEBSITENAME-unique.pot $WEBSITENAME-concat.pot
msgmerge -s -v -U $WEBSITENAME.po $WEBSITENAME-unique.pot

除了这两件事之外,上面的工作绝对正常按照克服的难度排序:

  1. 在所有网站源代码中,我都非常小心地确保所有需要翻译的字符串都被函数 _( '要在此处翻译的字符串' ) 包围 ,但是 xgettext 命令从我所知的情况中提取了文件中的几乎每个字符串,而不仅仅是 _('') 函数包围的字符串。这意味着我生成的 .pot 文件包含变量名称、URL、格式字符串、函数参数、配置数据和其他不应传递给我们的翻译器的不适当字符串。由于网站的大小,手动删除这些内容是不切实际的 - 我们正在查看近 80,000 个字符串条目,这只是我需要在接下来的 6 年内以相同方式处理的第一个网站几周!如何将 xgettext 配置为仅提取要翻译的字符串?

  2. 提取的许多字符串中都有换行符,这些换行符会作为 \n 插入到字符串中。有没有办法配置 xgettext 不这样做,或者有一个简单的方法来删除这些?

我已经阅读文档并在网络上搜索了几个小时甚至几天,试图找到特别是问题号的解决方案。 1,并且非常感谢 gettext 专家的帮助!提前致谢..

really struggling with this one.

I've recently setup a bash shell script to extract, concat and deduplicate the strings to translate out of a whole webite's view pages (MVC framework in use), it looks something like this:

for x in *.php; do xgettext --no-wrap --language=PHP -e --flag=_:1:pass-c-format -a "$x" -o "${x%.php}.pot"; done
msgcat -u -s --output-file=$WEBSITENAME-concat.pot *.pot
msguniq -u --output-file=$WEBSITENAME-unique.pot $WEBSITENAME-concat.pot
msgmerge -s -v -U $WEBSITENAME.po $WEBSITENAME-unique.pot

The above is working absolutely fine apart from these 2 things in order of difficulty to overcome:

  1. Throughout all the website source code I've been careful to ensure all the strings which need translating are surrounded by the function _( 'string to translate here' ), but the xgettext command is extracting pretty much every string in the file from what I can tell, not just the ones surrounded by the _('') function. This means my resulting .pot file contains variable names, URL's, format strings, function parameters, configuration data and other inappropriate strings which should not be passed onto our translators. Due to the size of the website it isn't practical to manually remove these - we're looking at nearly 80,000 string entries and this is just the first website of a number I'll need to process in the same way within the next 6 weeks! How can xgettext be configured to only extract the strings intended for translation?

  2. A lot of the strings extracted have line breaks in them, which are inserted as \n within the strings. Is there some way to configure xgettext to not do this, or an easy way to remove these?

I've been reading through the documentation and searching the web for hours even days trying to find a solution particularly to problem no. 1, and would really appreciate some help from the gettext gurus! Thanks in advance..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

仅此而已 2024-11-06 22:49:45

只是在这里猜测,但您遇到的第一个问题可能是由 -a 选项引起的。来自 xgettext 手册

-a, --extract-all           extract all strings

作为旁注,您的xgettext 调用看起来相当复杂。当然,我并不确切知道你想做什么,但对我来说以下命令就足够了:

xgettext -L PHP --from-code=utf-8 *.php -o messages.pot

这会将所有 _() 包含的字符串保存到 messages.pot 中。

Just guessing here, but the first issue you are experiencing might be caused by the -a option. From the xgettext manual:

-a, --extract-all           extract all strings

As a side note, your xgettext invocation seems quite complex. I, of course, don't known exactly what you want to do, but for me the following command is sufficient:

xgettext -L PHP --from-code=utf-8 *.php -o messages.pot

This will save all _() enclosed strings into messages.pot.

花辞树 2024-11-06 22:49:45

第 1 点的可能答案。

我不知道您正在使用的版本,但是使用 Delphi 版本,您可以添加一个名为 ggexclude.cfg 的文件来排除某些组件。

# exclude all occurences of the specified class
# and property in all DFM files in or below the
# path where "ggexclude.cfg" is in
[exclude-form-class-property]
TField.FieldName
...

Possible answer to point 1.

I don't know about the version you are using, but with the Delphi one, you can add a file called ggexclude.cfg to exclude some components.

# exclude all occurences of the specified class
# and property in all DFM files in or below the
# path where "ggexclude.cfg" is in
[exclude-form-class-property]
TField.FieldName
...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文