Files
gnome-shell-extensions/lib/convenience.js
Giovanni Campagna 7517d8ab6a convenience: update for the new extension API
Extension helper and metadata are now different objects, so the
first needs be retrieved from ExtensionUtils.
Also, reduce the number of required arguments (by using the new
metadata keys) and make generic enough for usage by other extensions.
Includes documentation.
2012-02-09 18:43:25 +01:00

46 lines
1.5 KiB
JavaScript

/* -*- mode: js; js-basic-offset: 4; indent-tabs-mode: nil -*- */
const Gettext = imports.gettext;
const Gio = imports.gi.Gio;
const ExtensionUtils = imports.misc.extensionUtils;
/**
* initTranslations:
* @domain: (optional): the gettext domain to use
*
* Initialize Gettext to load translations from extensionsdir/locale.
* If @domain is not provided, it will be taken from metadata['gettext-domain']
*/
function initTranslations(domain) {
let extension = ExtensionUtils.getCurrentExtension();
domain = domain || extension.metadata['gettext-domain'];
let localeDir = extension.dir.get_child('locale').get_path();
Gettext.bindtextdomain(domain, localeDir);
}
/**
* getSettings:
* @schema: (optional): the GSettings schema id
*
* Builds and return a GSettings schema for @schema, using schema files
* in extensionsdir/schemas. If @schema is not provided, it is taken from
* metadata['settings-schema'].
*/
function getSettings(schema) {
let extension = ExtensionUtils.getCurrentExtension();
schema = schema || extension.metadata['settings-schema'];
let schemaDir = extension.dir.get_child('schemas').get_path();
let schemaSource = Gio.SettingsSchemaSource.new_from_directory(schemaDir,
Gio.SettingsSchemaSource.get_default(),
false);
let schemaObj = schemaSource.lookup(schema, false);
return new Gio.Settings({ settings_schema: schemaObj });
}