Make use of the translations

This commit is contained in:
Olaf Leidinger 2013-10-31 10:25:41 +01:00
parent 1caa47a232
commit 41932879e9
3 changed files with 33 additions and 15 deletions

View File

@ -19,14 +19,19 @@ const PanelMenu = imports.ui.panelMenu;
const PopupMenu = imports.ui.popupMenu; const PopupMenu = imports.ui.popupMenu;
const Panel = imports.ui.panel; const Panel = imports.ui.panel;
const Gettext = imports.gettext.domain('gnome-shell-extensions');
const _ = Gettext.gettext;
const N_ = function(e) { return e; };
const Gettext = imports.gettext;
const ExtensionUtils = imports.misc.extensionUtils; 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.bindTextDomain();
const _ = Gettext.gettext;
const N_ = function(e) { return e; };
const TeaTime = new Lang.Class({ const TeaTime = new Lang.Class({
Name : 'TeaTime', Name : 'TeaTime',
@ -72,7 +77,7 @@ const TeaTime = new Lang.Class({
for (let teaname in list) { for (let teaname in list) {
let time = list[teaname].get_uint32(); 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() { menuItem.connect('activate', Lang.bind(this, function() {
this._initCountdown(time); this._initCountdown(time);
})); }));
@ -80,7 +85,7 @@ const TeaTime = new Lang.Class({
} }
}, },
_showNotification : function(subject, text) { _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); Main.messageTray.add(source);
let notification = new MessageTray.Notification(source, subject, text); 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.remove_actor(this._logo); // show timer instead of default icon
this.actor.add_actor(this._timer); 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)); this._idleTimeout = Mainloop.timeout_add_seconds(this._dt, Lang.bind(this, this._doCountdown));
}, },
_getRemainingSec: function() { _getRemainingSec: function() {
@ -112,8 +117,8 @@ const TeaTime = new Lang.Class({
// count down finished, switch display again // count down finished, switch display again
this.actor.remove_actor(this._timer); this.actor.remove_actor(this._timer);
this.actor.add_actor(this._logo); this.actor.add_actor(this._logo);
this._showNotification("Your tea is ready!", this._showNotification(_("Your tea is ready!"),
"Drink it, while it is hot!"); _("Drink it, while it is hot!"));
this._idleTimeout = null; this._idleTimeout = null;
return false; return false;
} else { } else {

View File

@ -15,14 +15,18 @@ const Lang = imports.lang;
const Gtk = imports.gi.Gtk; const Gtk = imports.gi.Gtk;
const GObject = imports.gi.GObject; const GObject = imports.gi.GObject;
const Gettext = imports.gettext.domain('gnome-shell-extensions'); const Gettext = imports.gettext;
const _ = Gettext.gettext;
const N_ = function(e) { return e; };
const ExtensionUtils = imports.misc.extensionUtils; 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.bindTextDomain();
const _ = Gettext.gettext;
const N_ = function(e) { return e; };
const Columns = { const Columns = {
TEA_NAME: 0, TEA_NAME: 0,

View File

@ -11,6 +11,15 @@ const Me = ExtensionUtils.getCurrentExtension();
const TEATIME_STEEP_TIMES_KEY = 'steep-times'; 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) { function getSettings(schema) {
let extension = ExtensionUtils.getCurrentExtension(); let extension = ExtensionUtils.getCurrentExtension();