【问题标题】:What does the "_" function in Vala do?Vala 中的“_”函数有什么作用?
【发布时间】:2015-02-23 19:47:40
【问题描述】:

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

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

【问题讨论】:

  • 我对 Vala 一无所知...但是一些程序员使用 _ 来表示 lambda 表达式和匿名方法中未使用的变量。 Vala 似乎支持这一点,也许在这种情况下使用它。如果您正在查看 I18n,您可能也走在了正确的道路上……它用于在 c(++) 中为 gnu gettext 库标记字符串 (makro)。也许 Vala 对 gettext 有一些绑定。

标签: function vala


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:
    【解决方案3】:

    还找到了一些关于这个函数具体做什么的信息,它似乎是 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.
    

    【讨论】:

      猜你喜欢
      • 2012-02-29
      • 1970-01-01
      • 1970-01-01
      • 2011-12-15
      • 2015-10-08
      • 2012-10-14
      • 2016-04-16
      • 2010-12-05
      • 2019-06-07
      相关资源
      最近更新 更多