Fputs (_ ("")), what does underscore indicate?

Finally, I started looking at some Linux code. I am looking at ls.c right now.

In the "usage ()" function below, I found many of these statements:

fputs (_("\ List information about the FILEs (the current directory by default).\n\ Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.\n\ \n\ "), stdout); 

What does _ (") mean? Is it something like L" string "or _T" string "or something completely new? I also have to admit that I don't know which words to use to search for something like that.

I hope you help me.

+8
c
source share
3 answers

This is the convention used by libintl aka gettext for translatable strings. When it starts, the gettext function (which _ is an alias) returns either the original or translated string, depending on the locale settings and the availability of the specified string.

+10
source share

_ is a macro often used with the GNU gettext package .

GNU gettext is a package that:

  • accepts lists of message lines intended for reading by people, and translations of these lines into other languages ​​and compiles them into databases;
  • provides a routine called gettext() to search for message strings in this database and return a translation for a message in a specific language.

If the program was asked to print the message in the language selected by the user in the environment variable and picked up by the setlocale() call, he would usually do something like

 fprintf(stderr, gettext("I cannot open the file named %s\n"), filename); 

gettext() will search for the appropriate line feed "I cannot find the file named %s\n" in the database and return the translated line.

However, this is a bit uncomfortable; as documentation for GNU gettext notes , many programs use a macro to make only the _( string ) alias for the gettext( ) string.

+4
source share

Function names may, of course, contain _ , and _ may begin with the name of the function. Thus, you can simply call the function _ .

All that happens is that the #define or real function is called _ .

+1
source share

All Articles