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 Utils = Me.imports.utils;
Gettext.textdomain("TeaTime");
Utils.bindTextDomain();
Utils.initTranslations("TeaTime");
const _ = Gettext.gettext;
const N_ = function(e) { return e; };

View File

@ -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; };

View File

@ -5,21 +5,31 @@
const Gio = imports.gi.Gio;
const Lang = imports.lang;
const Gettext = imports.gettext;
const ExtensionUtils = imports.misc.extensionUtils;
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();