gnomegjs

What is the role of underscore in gjs?


In gjs docs I found that underscore is used to denote private variables, but what does it do when creating objects with new or calling methods? For example in default code that gets generated when creating extension:

...
let item = new PopupMenu.PopupMenuItem(_('Show Notification'));
    item.connect('activate', () => {
        Main.notify(_('Whatʼs up, folks?'));
    });
    this.menu.addMenuItem(item);
...

Solution

  • What you see there is the _() function, which is a shorthand for gettext(). In other words, it marks a string as translatable, and will load the translated string (if available) when it's run by the user.