首页 > 解决方案 > 如何使用gettext?

问题描述

我正在尝试了解如何使用 gettext。以下工作流程无法正确检索法语文本。谁能告诉我如何让它工作?

$ cat po/fr/hello.po
msgid "Hello World\n"
msgstr "Bonjour le monde\n"
$ msgfmt -o po/fr/hello.mo po/fr/hello.po
$ cp po/fr/hello.mo fr/LC_MESSAGES/hello.mo
$ cat hello.c
#include <stdio.h>
#include <stdlib.h>

#include <libintl.h>
#include <locale.h>

#define _(STRING) gettext(STRING)

int main() {
  /* Setting the i18n environment */
  setlocale (LC_ALL, "");
  bindtextdomain ("hello", "/usr/share/locale/");
  textdomain ("hello");

  /* Example of i18n usage */
  printf(_("Hello World\n"));

  return EXIT_SUCCESS;
}
$ gcc -o hello.exe hello.c
$ LANG=fr_FR ./hello.exe
Hello World

标签: gettext

解决方案


推荐阅读