如何合并 2 个 .POT 文件(翻译文件)

发布于 2024-09-29 23:22:35 字数 731 浏览 4 评论 0原文

我遇到以下情况:

我想要翻译一种产品,该产品有两个独立的网站,一个用于管理员,一个用于客户。
代码库是 CakePHP。
两个站点彼此完全独立,它们是完整的 CakePHP 站点。
它们都有很多共同点。

因此,我使用 CakePHP 为每个站点生成 .pot 文件,但我很乐意为翻译人员提供一个文件,其中两个 .pot 文件中都有唯一的字符串。

他们会给我一个包含两个站点的字符串的 .po 文件,我只需将相同的文件复制到两个站点,因此我将拥有包含代码不会使用的额外字符串的 .po 文件,但是应该不是问题。

所以问题本质上是...如何合并两个 .pot 文件?

  • 我需要获取一个没有重复字符串的新文件。
  • 理想情况下,它会在 CakePHP 添加的每个字符串之前保留(对于重复的字符串,附加)注释,指定找到该字符串的位置,但如果没有这样做,那也没关系,没有它我也可以生活。 (请参阅下面的 .pot 文件摘录以了解对此的说明)

您知道有什么工具可以让我执行此操作吗?我真的很想避免自己编写。


这些是我上面谈论的评论:

#: \controllers\accounts_controller.php:118
#: \controllers\customer_documents_controller.php:75
msgid "Parent Customer not specified"
msgstr ""

I have the following situation:

One product which I want to translate, that has two separate websites, one for admins, one for customers.
The codebase is CakePHP.
Both sites are completely separate from each other, they are complete CakePHP sites.
And they both have A LOT of strings in common.

So, with CakePHP I generate the .pot files for each site, but I'd love to give translators ONE file, with the unique strings in both .pot files.

They'd give me back one .po file with the strings for both sites, and I'll just copy the same file to both sites, so I'll have .po files with extra strings that the code will not use, but that shouldn't be a problem.

So the question essentially is... How can I merge two .pot files?

  • I need to get a new file that has no duplicate strings.
  • Ideally, it'll keep (and for duplicate strings, append) the comments before each string that CakePHP adds, specifying where the string was found, but if this is not done, that's fine, I can live without it. (see below for an excerpt of the .pot file for a clarification on this)

Do you know of any tools that'd let me do this? I'd really like to avoid having to write my own.


These are the comments I'm talking about above:

#: \controllers\accounts_controller.php:118
#: \controllers\customer_documents_controller.php:75
msgid "Parent Customer not specified"
msgstr ""

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

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

发布评论

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

评论(4

生生漫 2024-10-06 23:22:35

好的,执行此操作的工具是 msgcat

msgcat *.pot > all.pot

如果您使用的是 Windows,请安装 cygwin,并确保您拥有 gettext-devel 包,因为 msgcat 不在常规 gettext 包

Ok, so the tool to do this is msgcat

msgcat *.pot > all.pot

If you're on Windows, install cygwin, and make sure you have the gettext-devel package, because msgcat is not in the regular gettext package.

小清晰的声音 2024-10-06 23:22:35

msgcat 不应该是正确的答案,msgcat 适用于 .po 文件,但它不适用于 .pot 文件,因为文档如下:

要连接 POT 文件,最好使用 xgettext,而不是 msgcat,因为
msgcat 会因指定 POT 中未定义的字符集而阻塞
文件。

正确的是:

xgettext input/*.pot -o out.pot

msgcat should not be the right answer, msgcat is good for .po file but it won't work well on .pot file due to document that:

To concatenate POT files, better use xgettext, not msgcat, because
msgcat would choke on the undefined charsets in the specified POT
files.

The right one is:

xgettext input/*.pot -o out.pot

甜`诱少女 2024-10-06 23:22:35

将两个 .pot 文件合并为一个:

msgcat --use-first -o Messages.pot csMessages.pot XamlMessages.pot

--use-first - 对每条消息使用第一个可用的翻译,不要合并多个翻译

-o - 将输出写入指定文件

Merge two .pot files into one:

msgcat --use-first -o Messages.pot csMessages.pot XamlMessages.pot

--use-first - use first available translation for each message, don't merge several translations

-o - write output to specified file

习惯成性 2024-10-06 23:22:35

命令是:

msgcat inputfile1 inputfile2 ... > outpo

the command is:

msgcat inputfile1 inputfile2 ... > outpo
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文