2015-02-23 95 views
2

我看到有些項目使用_函數,它將字符串作爲參數,如_("Hello World")。但是我找不到有關它是什麼以及如何使用它的手冊或文章。Vala中的「_」函數有什麼作用?

我想這與i18n和l10n有關(它在我在網上找到的一些文章中提到過),但是你能向我解釋它是如何工作的以及如何使用它?

+0

我什麼都不知道關於Vala ...但是一些程序員使用_來表示lambda表達式和匿名方法中未使用的變量。 Vala似乎支持,也許它在這種情況下使用。如果您正在查看I18n,您可能也在正確的路徑上......它用於標記c(++)中的gnu gettext庫的字符串(makro)。也許Vala對gettext有一些約束。 – Beachwalker 2015-02-23 19:53:47

+0

[Mercurial/Python - 下劃線功能的作用是什麼?](http://stackoverflow.com/questions/3077227/mercurial-python-what-does-the-underscore-function-do) – ptomato 2015-02-24 06:47:39

回答

3

這就是GNU gettext的本地化功能。您可以爲函數調用中指定的字符串提供特定於語言的備用字符串。

還有就是xgettext工具,它生成一個.pot文件(簡稱爲便攜式對象模板)從應用程序代碼,然後翻譯可以讓.po本地化文件吧。然後,您可以將這些與您的應用程序捆綁在一起,並提供更加廣泛的可用軟件。

0

還發現約究竟這個功能做的,這似乎是在瓦拉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. 
相關問題