extensions: Add static defineTranslationFunctions() method

The method can be used to define a set of gettext functions that
call the corresponding method of an extension.

Those functions are very similar to the gettext functions we are
exporting, except that:

 - looking up the extension is delegated to the
   Extension/Preferences class
 - it is possible to avoid examining the stack
   when called with `import.meta.url`

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2838>
This commit is contained in:
Florian Müllner
2023-07-10 07:06:17 +02:00
parent cd99fbae50
commit f59d523694
3 changed files with 105 additions and 2 deletions

View File

@ -1,4 +1,4 @@
import {ExtensionBase, setExtensionManager} from './sharedInternals.js';
import {ExtensionBase, GettextWrapper, setExtensionManager} from './sharedInternals.js';
export {gettext, ngettext, pgettext} from './sharedInternals.js';
@ -6,6 +6,11 @@ const {extensionManager} = imports.ui.main;
setExtensionManager(extensionManager);
export class Extension extends ExtensionBase {
static defineTranslationFunctions(url) {
const wrapper = new GettextWrapper(this, url);
return wrapper.defineTranslationFunctions();
}
enable() {
}