如何在git中正确使用gettext? [英] How to use correctly gettext with git?

查看:108
本文介绍了如何在git中正确使用gettext?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小型应用程序正在开发并正在分发;现在,我想使用gettext为它添加i18n支持.我看到gettext需要运行几个命令并生成各种文件(并在源代码中包含新字符串时更新它们).

I have a small application that I develop and I am distributing; now I would like to add i18n support to it with gettext. I see that gettext requires running several commands and generating various files (and updating them when new strings are included in the source code).

使gettext与典型的git工作流程交互的通常方法是什么?我应该自己生成.pot文件并将其包含在存储库中,还是应该在生成时由Makefile自动生成?那.mo文件呢?同样,我是否需要在构建脚本中包含msgmerge,还是将其结果添加到版本控制的文件中?

What is the usual way to have gettext interact with a typical git workflow? Should I generate my .pot file myself and include it in the repository, or should it be generated automatically at build time by my Makefile? What about .mo files? Similarly, do I need to include msgmerge in my build script, or do I just add its result to the version-controlled files?

我正在使用C ++,一个手写的Makefile(没有automake)和github,以防万一.

I am using C++, a hand-written Makefile (no automake) and github, in case it matters.

推荐答案

这里涉及三种类型的文件,并且它们都是生成的,至少是一种.

Three types of files are involved here, and all of them are generated, at least kind of.

  1. 包含主消息目录的.pot PO模板文件.尽管严格说来,这是我所知道的每个项目的版本控制,但是它是重复生成的.

  1. The .pot PO Template file that contains the master message catalog. This is under version control in every project I know although it is strictly spoken generated and redundant.

具有单独翻译的.po文件.它们有时是生成的,有时不是.当您将新字符串与msgmerge合并时,将生成它们.但是,当您的翻译人员发回新的翻译时,他们却没有.您必须将它们置于版本控制下,因为它们包含翻译.

The .po files with the individual translations. They are sometimes generated, sometimes not. When you merge in new strings with msgmerge, they are generated. But when your translators send back a new translation, they are not. You have to put them under version control because they contain the translations.

.po文件编译到的.mo文件.不要将它们置于版本控制之下,而应随发行版一起发布(源代码和二进制文件).

The .mo files that the .po files compile to. Do not put them under version control but ship them with releases (source and binary).

更重要的是Makefile中的逻辑.上述文件均不应自动生成,而只能按需生成.否则,每当您编辑源文件时,您的po/目录将是脏的.

More important is the logic in your Makefile. None of the above mentioned files should be generated automatically but only on demand. Otherwise your po/ directory will be dirty, whenever you edit a source file.

恕我直言,最佳实践是确保无需安装gettext工具(xgettext,msgmerge,msgfmt)就可以构建git克隆.确保仅按需调用它们.

IMHO it is best practice to ensure that a git clone can be built without having the gettext tools (xgettext, msgmerge, msgfmt) installed. Make sure that they are only invoked on demand.

gettext libint-perl的Perl绑定(免责声明:我是作者)包含带有完整Makefile的示例po目录:

The Perl binding for gettext libint-perl (disclaimer: I am the author) contains a sample po directory with a complete Makefile: https://github.com/gflohr/libintl-perl/tree/master/sample/simplecal/po. You can probably use that Makefile directly in your project. You only have to modify the xgettext invocation for the programming language of your choice.

这篇关于如何在git中正确使用gettext?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆