germanfr germanfr - 2 months ago 7
Linux Question

String with underscore Javascript meaning

I've seen in some places that strings are surrounded by _() like

_('some string')
.

For example in a desktop program with these imports:

const Applet = imports.ui.applet;
const St = imports.gi.St;
const Gdk = imports.gi.Gdk;
const Gtk = imports.gi.Gtk;
const Keymap = Gdk.Keymap.get_default();
const Caribou = imports.gi.Caribou;
const PopupMenu = imports.ui.popupMenu;
const Lang = imports.lang;
const Gio = imports.gi.Gio;
const Main = imports.ui.main;
const MessageTray = imports.ui.messageTray;


What is the use of that function?

Answer

I'll answer myself based on comments I got. (I already knew _ is not anything special but a normal function name, that wasn't the question).

Based on those imports, it seems to be part of a system library. Concretely this:

const Lang = imports.lang;

It is used to translate strings into other languages automatically. For example:

_('Hello') //Hola
Comments