我可以自动更新 gettext 的 .po 文件中的 msgids 以进行微小的文本更改吗?

发布于 2024-12-18 04:39:34 字数 541 浏览 4 评论 0原文

使用 gettext,消息的原始文本(通常是英语)用作 翻译的消息键(“msgid”)。这意味着每次 原始文本发生更改时,必须更新所有 .po 文件中的 msgid。

对于文本的真正改变,这显然是不可避免的,因为 译者必须更新翻译。

然而,如果原文的改变没有改变其含义, 重新翻译是多余的(例如标点符号的变化,空格 更改,或更正拼写错误)。

在这种情况下有没有办法自动更新 .po 文件?

我尝试使用 xgettext & msgmerge(启用模糊匹配),但是 模糊匹配有时会失败,而且这会产生很多丑陋的结果 “#,模糊”标志。

注意:还有一个类似的问题: 如何对大文本值进行小幅编辑时,可以有效地使用 gettext PO 文件 然而,它涉及大字符串,因此涉及更具体的问题。

With gettext, the original (usually English) text of messages serves as
the message key ("msgid") for the translations. This means that every time the
original text changes, the msgid must be updated in all the .po files.

For real changes of the text, this is obviously unavoidable, as the
translator must update the translation.

However, if the change of the original does not change its meaning,
re-translation is superflous (e.g. change in punctation, whitespace
changes, or correction of a spelling mistake).

Is there a way to update the .po files automatically in that case?

I tried to use xgettext & msgmerge (with fuzzy matching turned on), but
fuzzy matching sometimes fails, plus this produces lots of ugly
"#,fuzzy" flags.

Note: There is a similar question:
How to efficiently work with gettext PO files when making small edits to large text values
However, it's about large strings, thus about a more specific problem.

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

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

发布评论

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

评论(2

深居我梦 2024-12-25 04:39:34

避免该问题的一种方法是保留 msgids,保留原始语言的 .po 文件并在其中进行修复。

但我总是觉得这更像是一种变通办法,而不是一个适当的解决方案。对于下一次迭代(肯定会有更多的 msgid 更改),msgid 会发生更改,翻译人员会在通常的更新中翻译它,或者在 msgid 更改时手动更新每种语言。

One way to avoid the problem is to leave the msgids alone, have a .po file for the original language and make the fix inside that.

It always strikes me as being more of a work around than a proper fix though. For the next iteration (where there will definitely be more msgid changes) the msgid is changed and either the translators translate it in their usual update or each language is updated by hand when the msgid is changed.

潇烟暮雨 2024-12-25 04:39:34

我在对 django 项目进行细微更改时遇到了这个问题。我所做的如下:

  1. 更改代码中的消息。
  2. 对所有翻译文件(“django.po”)运行查找和替换,用新消息替换旧消息(msgid)。
  3. 运行 django-admin makemessages。

如果我做对了,那么最后一步就是多余的(即,您已经对 gettext 进行了更改)。 django 使用 gettext 实用程序,因此如何创建消息文件并不重要。

我像这样查找并替换:
<代码>查找 . -名称“*.po”-打印| xargs sed -i 's/oldmessageid/newmessageid/g' 由 http://rushi.vishavadia.com/blog/find-replace-across-multiple-files-in-linux

I've had exactly this issue when doing minor changes to a django project. What I do is the following:

  1. Change message in code.
  2. Run find and replace on all translation files ("django.po"), replacing the old message (msgid) with the new one.
  3. Run django-admin makemessages.

If I have done things right, the last step is superflous (i.e, you have done the change for gettext). django uses the gettext utilities, so it shouldn't matter how you make your message files.

I find and replace like so:
find . -name "*.po" -print | xargs sed -i 's/oldmessageid/newmessageid/g' Courtesy of http://rushi.vishavadia.com/blog/find-replace-across-multiple-files-in-linux

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