2

I've seen that some projects used _ function that takes string as an argument, like _("Hello World"). But I couldn't find any manuals or articles about what is it and how to use it.

I guess this has something to do with i18n and l10n (it was mentioned in some article I found on the internet), but can you explain to me how it works and how to use it?

serge1peshcoff
  • 4,342
  • 11
  • 45
  • 76
  • I don't know anything about Vala... but some programmers use the _ to denote unused variables in lambda expressions and anonymous methods. Vala seems to support that, maybe it is used in this case. If you're looking at I18n you might be also on the right path... it is used to mark strings (makro) for the gnu gettext library in c(++). Maybe Vala has some binding to gettext. – Beachwalker Feb 23 '15 at 19:53
  • possible duplicate of [Mercurial/Python - What Does The Underscore Function Do?](http://stackoverflow.com/questions/3077227/mercurial-python-what-does-the-underscore-function-do) – ptomato Feb 24 '15 at 06:47

3 Answers3

3

That is the GNU gettext localization function. You can provide language specific alternate strings for the one specified in the function call.

There is the xgettext tool, which generates a .pot file (abbreviation for portable object template) from your application code, then translators can make .po localization files for it. Then, you can bundle these with your application, and deliver a more widely usable piece of software.

meskobalazs
  • 15,741
  • 2
  • 40
  • 63
0

Also found some info about what exactly this function do, it seems to be the macro for Glib.dgettext() function in Vala, this is from 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.
serge1peshcoff
  • 4,342
  • 11
  • 45
  • 76