如何在git中正确使用gettext?

编程入门 行业动态 更新时间:2024-10-28 16:16:08
本文介绍了如何在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.

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

  • 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目录: github/gflohr/libintl-perl/tree/master/sample/simplecal/po .您可能可以在项目中直接使用该Makefile.您只需修改所选编程语言的xgettext调用即可.

    The Perl binding for gettext libint-perl (disclaimer: I am the author) contains a sample po directory with a complete Makefile: github/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?

    本文发布于:2023-11-15 01:49:45,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1590070.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:正确   如何在   git   gettext

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!