diff --git a/src/extension.js b/src/extension.js index b7a2928..c87df68 100644 --- a/src/extension.js +++ b/src/extension.js @@ -25,8 +25,7 @@ const ExtensionUtils = imports.misc.extensionUtils; const Me = ExtensionUtils.getCurrentExtension(); const Utils = Me.imports.utils; -Gettext.textdomain("TeaTime"); -Utils.bindTextDomain(); +Utils.initTranslations("TeaTime"); const _ = Gettext.gettext; const N_ = function(e) { return e; }; diff --git a/src/prefs.js b/src/prefs.js index 611c26b..2766166 100644 --- a/src/prefs.js +++ b/src/prefs.js @@ -20,8 +20,7 @@ const ExtensionUtils = imports.misc.extensionUtils; const Me = ExtensionUtils.getCurrentExtension(); const Utils = Me.imports.utils; -Gettext.textdomain("TeaTime"); -Utils.bindTextDomain(); +Utils.initTranslations("TeaTime"); const _ = Gettext.gettext; const N_ = function(e) { return e; }; diff --git a/src/utils.js b/src/utils.js index 0a94f4e..f497b89 100644 --- a/src/utils.js +++ b/src/utils.js @@ -3,23 +3,33 @@ Thomas Liebetraut */ -const Gio = imports.gi.Gio; -const Lang = imports.lang; - +const Gio = imports.gi.Gio; +const Lang = imports.lang; +const Gettext = imports.gettext; const ExtensionUtils = imports.misc.extensionUtils; -const Me = ExtensionUtils.getCurrentExtension(); +const Me = ExtensionUtils.getCurrentExtension(); +const Config = imports.misc.config; const TEATIME_STEEP_TIMES_KEY = 'steep-times'; -function bindTextDomain() { - // Evil hack to check, if extension is globally installed. - // If it is, we may not bind to the text domain, as the translation won't - // be found - if( Me.dir.get_path() != "/usr/share/gnome-shell/extensions/TeaTime@oleid.mescharet.de" ) { - Gettext.bindtextdomain("TeaTime", Me.dir.get_path() + "/locale"); - } +function initTranslations(domain) { + let extension = ExtensionUtils.getCurrentExtension(); + + domain = domain || extension.metadata['gettext-domain']; + + Gettext.textdomain(domain); + // check if this extension was built with "make zip-file", and thus + // has the locale files in a subfolder + // otherwise assume that extension has been installed in the + // same prefix as gnome-shell + let localeDir = extension.dir.get_child('locale'); + if (localeDir.query_exists(null)) + Gettext.bindtextdomain(domain, localeDir.get_path()); + else + Gettext.bindtextdomain(domain, Config.LOCALEDIR); } + function getSettings(schema) { let extension = ExtensionUtils.getCurrentExtension();