From 41932879e963cbd488f139b09fb78e6c70f84ce7 Mon Sep 17 00:00:00 2001 From: Olaf Leidinger Date: Thu, 31 Oct 2013 10:25:41 +0100 Subject: [PATCH] Make use of the translations --- src/extension.js | 25 +++++++++++++++---------- src/prefs.js | 14 +++++++++----- src/utils.js | 9 +++++++++ 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/extension.js b/src/extension.js index a47a074..b7a2928 100644 --- a/src/extension.js +++ b/src/extension.js @@ -19,13 +19,18 @@ const PanelMenu = imports.ui.panelMenu; const PopupMenu = imports.ui.popupMenu; const Panel = imports.ui.panel; -const Gettext = imports.gettext.domain('gnome-shell-extensions'); -const _ = Gettext.gettext; + +const Gettext = imports.gettext; +const ExtensionUtils = imports.misc.extensionUtils; +const Me = ExtensionUtils.getCurrentExtension(); +const Utils = Me.imports.utils; + +Gettext.textdomain("TeaTime"); +Utils.bindTextDomain(); + +const _ = Gettext.gettext; const N_ = function(e) { return e; }; -const ExtensionUtils = imports.misc.extensionUtils; -const Me = ExtensionUtils.getCurrentExtension(); -const Utils = Me.imports.utils; const TeaTime = new Lang.Class({ @@ -72,7 +77,7 @@ const TeaTime = new Lang.Class({ for (let teaname in list) { let time = list[teaname].get_uint32(); - let menuItem = new PopupMenu.PopupMenuItem(teaname + ": " + Utils.formatTime(time)); + let menuItem = new PopupMenu.PopupMenuItem(_(teaname) + ": " + Utils.formatTime(time)); menuItem.connect('activate', Lang.bind(this, function() { this._initCountdown(time); })); @@ -80,7 +85,7 @@ const TeaTime = new Lang.Class({ } }, _showNotification : function(subject, text) { - let source = new MessageTray.Source("TeaTime applet", 'utilities-teatime'); + let source = new MessageTray.Source(_("TeaTime applet"), 'utilities-teatime'); Main.messageTray.add(source); let notification = new MessageTray.Notification(source, subject, text); @@ -97,7 +102,7 @@ const TeaTime = new Lang.Class({ this.actor.remove_actor(this._logo); // show timer instead of default icon this.actor.add_actor(this._timer); - this._showNotification("Timer set!", time + "s to go"); + this._showNotification(_("Timer set!"), time + _("s to go")); this._idleTimeout = Mainloop.timeout_add_seconds(this._dt, Lang.bind(this, this._doCountdown)); }, _getRemainingSec: function() { @@ -112,8 +117,8 @@ const TeaTime = new Lang.Class({ // count down finished, switch display again this.actor.remove_actor(this._timer); this.actor.add_actor(this._logo); - this._showNotification("Your tea is ready!", - "Drink it, while it is hot!"); + this._showNotification(_("Your tea is ready!"), + _("Drink it, while it is hot!")); this._idleTimeout = null; return false; } else { diff --git a/src/prefs.js b/src/prefs.js index 16b25ad..611c26b 100644 --- a/src/prefs.js +++ b/src/prefs.js @@ -15,13 +15,17 @@ const Lang = imports.lang; const Gtk = imports.gi.Gtk; const GObject = imports.gi.GObject; -const Gettext = imports.gettext.domain('gnome-shell-extensions'); -const _ = Gettext.gettext; +const Gettext = imports.gettext; +const ExtensionUtils = imports.misc.extensionUtils; +const Me = ExtensionUtils.getCurrentExtension(); +const Utils = Me.imports.utils; + +Gettext.textdomain("TeaTime"); +Utils.bindTextDomain(); + +const _ = Gettext.gettext; const N_ = function(e) { return e; }; -const ExtensionUtils = imports.misc.extensionUtils; -const Me = ExtensionUtils.getCurrentExtension(); -const Utils = Me.imports.utils; const Columns = { diff --git a/src/utils.js b/src/utils.js index 6c17606..0a94f4e 100644 --- a/src/utils.js +++ b/src/utils.js @@ -11,6 +11,15 @@ const Me = ExtensionUtils.getCurrentExtension(); 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 getSettings(schema) { let extension = ExtensionUtils.getCurrentExtension();