Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Underscore `_` before the format string

I'm here looking at some C source code and I've found this:

fprintf(stderr, _("Try `%s --help' for more information.\n"), command);

I already saw the underscore when I had a look at wxWidget, and I read it's used for internationalization. I found it really horrible (the least intutive name ever), but I tought it's just another weird wxWidget convention.

Now I find it again in some Alsa source. Does anyone know where it comes from?

like image 239
Dacav Avatar asked Jul 26 '10 14:07

Dacav


2 Answers

It comes from GNU gettext, a package designed to ease the internationalization process. The _() function is simply a string wrapper. This function basically replaces the given string on runtime with a translation in the system's language, if available (i.e. if they shipped a .mo file for this language with the program).

like image 127
RWS Avatar answered Oct 21 '22 14:10

RWS


It comes from gettext. Originally thought out, internationalization was too long to type each time you needed a string internationalized. So programmers created the shortcut i18n (because there are 18 letters in between the 'i' and the 'n' in internationalization) and you may see source code out there using that. Apparently though i18n was still too long, so now its just an underscore.

like image 41
Icemanind Avatar answered Oct 21 '22 15:10

Icemanind