Proper initialisation of translations

This commit is contained in:
Olaf Leidinger 2013-10-31 10:46:02 +01:00
parent 35fb22f427
commit f2070f9725
3 changed files with 23 additions and 15 deletions

View File

@ -25,8 +25,7 @@ const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension(); const Me = ExtensionUtils.getCurrentExtension();
const Utils = Me.imports.utils; const Utils = Me.imports.utils;
Gettext.textdomain("TeaTime"); Utils.initTranslations("TeaTime");
Utils.bindTextDomain();
const _ = Gettext.gettext; const _ = Gettext.gettext;
const N_ = function(e) { return e; }; const N_ = function(e) { return e; };

View File

@ -20,8 +20,7 @@ const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension(); const Me = ExtensionUtils.getCurrentExtension();
const Utils = Me.imports.utils; const Utils = Me.imports.utils;
Gettext.textdomain("TeaTime"); Utils.initTranslations("TeaTime");
Utils.bindTextDomain();
const _ = Gettext.gettext; const _ = Gettext.gettext;
const N_ = function(e) { return e; }; const N_ = function(e) { return e; };

View File

@ -3,23 +3,33 @@
Thomas Liebetraut <thomas@tommie-lie.de> Thomas Liebetraut <thomas@tommie-lie.de>
*/ */
const Gio = imports.gi.Gio; const Gio = imports.gi.Gio;
const Lang = imports.lang; const Lang = imports.lang;
const Gettext = imports.gettext;
const ExtensionUtils = imports.misc.extensionUtils; 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'; const TEATIME_STEEP_TIMES_KEY = 'steep-times';
function bindTextDomain() { function initTranslations(domain) {
// Evil hack to check, if extension is globally installed. let extension = ExtensionUtils.getCurrentExtension();
// If it is, we may not bind to the text domain, as the translation won't
// be found domain = domain || extension.metadata['gettext-domain'];
if( Me.dir.get_path() != "/usr/share/gnome-shell/extensions/TeaTime@oleid.mescharet.de" ) {
Gettext.bindtextdomain("TeaTime", Me.dir.get_path() + "/locale"); 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) { function getSettings(schema) {
let extension = ExtensionUtils.getCurrentExtension(); let extension = ExtensionUtils.getCurrentExtension();