Port "import" into Gnome Shell 45 format

I’m porting an extension to the new Gnome Shell format, and I don’t know how to migrate these statements:

const ByteArray = imports.byteArray;

const Signals = imports.signals;

const Gettext = imports.gettext.domain(‘ding’);

const ByteArray = imports.byteArray; // legacy module without ESM equivalent
const Signals = imports.signals; // Ditto

import {domain as gettextDomain} from 'gettext';
const Gettext = gettextDomain('ding');

Alternatively, you can include the gettext-domain in the metadata and use the extensions convenience API:

import {Extension, gettext as _} from 'resource:///org/gnome/shell/extensions/extension.js';

export default class DingExtension extends Extension {
    enable() {
        // enable stuff
    }

    disable() {
        // disable stuff
    }
}

The imported gettext() function has to determine the calling extension every time when called. The overhead should be negligible, but if you want to avoid it nonetheless, you can use the slightly less magic

import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js';
const {gettext: _} = Extension.defineTranslationFunctions(import.meta.url);
1 Like

I’m porting an extension to the new Gnome Shell format

I’ll also note that “GNOME Shell format” is misleading. The whole point of the transition is to not use something that is specific to gjs/GNOME, but a widely supported standard feature.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.