Vala 中的“_”函数是做什么的?

What does the "_" function in Vala do?

我看到一些项目使用 _ 函数,它以字符串作为参数,例如 _("Hello World")。但是我找不到任何关于它是什么以及如何使用它的手册或文章。

我猜这与 i18n 和 l10n 有关系(我在网上找到的一些文章中提到了它),但是你能给我解释一下它是如何工作的以及如何使用它吗?

那就是GNU gettext本地化功能。您可以为函数调用中指定的字符串提供语言特定的备用字符串。

xgettext工具,可以从您的应用程序代码生成.pot文件(可移植对象模板的缩写),然后翻译人员可以制作.po 个本地化文件。然后,您可以将它们与您的应用程序捆绑在一起,并提供更广泛使用的软件。

I18n。请参阅此处的 gettext 示例:https://ewgeny.wordpress.com/2012/05/10/supporting-multiple-languages-in-your-application-a-simple-gettext-step-by-step-example/

还找到了一些关于这个函数具体作用的信息,它似乎是 Vala 中 Glib.dgettext() 函数的宏,来自 valadoc.org:

dgettext
public unowned string dgettext (string? domain, string msgid)

This function is a wrapper of dgettext which does not translate the message if the default domain as set with textdomain has no translations for the current locale.

...
Applications should normally not use this function directly, but use the _ macro for translations.