key label translations

Get key label translations by using Gtk.
This commit is contained in:
abakkk 2020-06-08 14:30:47 +02:00
parent 95f54f0576
commit b4eb418c89
4 changed files with 76 additions and 49 deletions

44
draw.js
View File

@ -401,7 +401,7 @@ var DrawingArea = new Lang.Class({
if (this.currentShape == Shapes.POLYGON || this.currentShape == Shapes.POLYLINE) { if (this.currentShape == Shapes.POLYGON || this.currentShape == Shapes.POLYLINE) {
this.currentElement.points.push([startX, startY]); this.currentElement.points.push([startX, startY]);
this.emit('show-osd', null, _("Press <i>Enter</i>\nto mark vertices"), "", -1); this.emit('show-osd', null, _("Press <i>%s</i>\nto mark vertices").format(Gtk.accelerator_get_label(Clutter.KEY_Return, 0)), "", -1);
} }
this.motionHandler = this.connect('motion-event', (actor, event) => { this.motionHandler = this.connect('motion-event', (actor, event) => {
@ -444,7 +444,7 @@ var DrawingArea = new Lang.Class({
// start writing // start writing
this.currentElement.state = TextState.WRITING; this.currentElement.state = TextState.WRITING;
this.currentElement.text = ''; this.currentElement.text = '';
this.emit('show-osd', null, _("Type your text\nand press <i>Escape</i>"), "", -1); this.emit('show-osd', null, _("Type your text\nand press <i>%s</i>").format(Gtk.accelerator_get_label(Clutter.KEY_Escape, 0)), "", -1);
this._updateTextCursorTimeout(); this._updateTextCursorTimeout();
this.textHasCursor = true; this.textHasCursor = true;
this._redisplay(); this._redisplay();
@ -1238,6 +1238,32 @@ var DrawingHelper = new Lang.Class({
this.parent(params); this.parent(params);
this.monitor = monitor; this.monitor = monitor;
this.hide(); this.hide();
this.settings = Convenience.getSettings();
this.settingHandler = this.settings.connect('changed', this._onSettingChanged.bind(this));
this.connect('destroy', () => this.settings.disconnect(this.settingHandler));
},
_onSettingChanged: function(settings, key) {
if (key == 'toggle-help')
this._updateHelpKeyLabel();
if (this.vbox) {
this.vbox.destroy();
this.vbox = null;
}
},
_updateHelpKeyLabel: function() {
let [keyval, mods] = Gtk.accelerator_parse(this.settings.get_strv('toggle-help')[0]);
this._helpKeyLabel = Gtk.accelerator_get_label(keyval, mods);
},
get helpKeyLabel() {
if (!this._helpKeyLabel)
this._updateHelpKeyLabel();
return this._helpKeyLabel;
}, },
_populate: function() { _populate: function() {
@ -1245,17 +1271,15 @@ var DrawingHelper = new Lang.Class({
this.add_actor(this.vbox); this.add_actor(this.vbox);
this.vbox.add_child(new St.Label({ text: _("Global") })); this.vbox.add_child(new St.Label({ text: _("Global") }));
let settings = Convenience.getSettings();
for (let settingKey in Prefs.GLOBAL_KEYBINDINGS) { for (let settingKey in Prefs.GLOBAL_KEYBINDINGS) {
let hbox = new St.BoxLayout({ vertical: false }); let hbox = new St.BoxLayout({ vertical: false });
if (settingKey.indexOf('-separator-') != -1) { if (settingKey.indexOf('-separator-') != -1) {
this.vbox.add_child(hbox); this.vbox.add_child(hbox);
continue; continue;
} }
if (!settings.get_strv(settingKey)[0]) if (!this.settings.get_strv(settingKey)[0])
continue; continue;
let [keyval, mods] = Gtk.accelerator_parse(settings.get_strv(settingKey)[0]); let [keyval, mods] = Gtk.accelerator_parse(this.settings.get_strv(settingKey)[0]);
hbox.add_child(new St.Label({ text: _(Prefs.GLOBAL_KEYBINDINGS[settingKey]) })); hbox.add_child(new St.Label({ text: _(Prefs.GLOBAL_KEYBINDINGS[settingKey]) }));
hbox.add_child(new St.Label({ text: Gtk.accelerator_get_label(keyval, mods), x_expand: true })); hbox.add_child(new St.Label({ text: Gtk.accelerator_get_label(keyval, mods), x_expand: true }));
this.vbox.add_child(hbox); this.vbox.add_child(hbox);
@ -1270,7 +1294,7 @@ var DrawingHelper = new Lang.Class({
} }
let hbox = new St.BoxLayout({ vertical: false }); let hbox = new St.BoxLayout({ vertical: false });
hbox.add_child(new St.Label({ text: _(Prefs.OTHER_SHORTCUTS[i].desc) })); hbox.add_child(new St.Label({ text: _(Prefs.OTHER_SHORTCUTS[i].desc) }));
hbox.add_child(new St.Label({ text: _(Prefs.OTHER_SHORTCUTS[i].shortcut), x_expand: true })); hbox.add_child(new St.Label({ text: Prefs.OTHER_SHORTCUTS[i].shortcut, x_expand: true }));
this.vbox.add_child(hbox); this.vbox.add_child(hbox);
} }
@ -1282,9 +1306,9 @@ var DrawingHelper = new Lang.Class({
continue; continue;
} }
let hbox = new St.BoxLayout({ vertical: false }); let hbox = new St.BoxLayout({ vertical: false });
if (!settings.get_strv(settingKey)[0]) if (!this.settings.get_strv(settingKey)[0])
continue; continue;
let [keyval, mods] = Gtk.accelerator_parse(settings.get_strv(settingKey)[0]); let [keyval, mods] = Gtk.accelerator_parse(this.settings.get_strv(settingKey)[0]);
hbox.add_child(new St.Label({ text: _(Prefs.INTERNAL_KEYBINDINGS[settingKey]) })); hbox.add_child(new St.Label({ text: _(Prefs.INTERNAL_KEYBINDINGS[settingKey]) }));
hbox.add_child(new St.Label({ text: Gtk.accelerator_get_label(keyval, mods), x_expand: true })); hbox.add_child(new St.Label({ text: Gtk.accelerator_get_label(keyval, mods), x_expand: true }));
this.vbox.add_child(hbox); this.vbox.add_child(hbox);
@ -1339,7 +1363,7 @@ var DrawingHelper = new Lang.Class({
transition: 'easeOutQuad', transition: 'easeOutQuad',
onComplete: this.hide.bind(this) }); onComplete: this.hide.bind(this) });
}, }
}); });
const getActor = function(object) { const getActor = function(object) {

View File

@ -336,7 +336,9 @@ var AreaManager = new Lang.Class({
// increase OSD display time // increase OSD display time
let hideTimeoutSave = OsdWindow.HIDE_TIMEOUT; let hideTimeoutSave = OsdWindow.HIDE_TIMEOUT;
try { OsdWindow.HIDE_TIMEOUT = 2000; } catch(e) { /* HIDE_TIMEOUT is not exported with 'var' */ } try { OsdWindow.HIDE_TIMEOUT = 2000; } catch(e) { /* HIDE_TIMEOUT is not exported with 'var' */ }
Main.osdWindowManager.show(currentIndex, this.enterGicon, _("Press Ctrl + F1 for help") + "\n\n" + _("Entering drawing mode"), null); let label = _("<small>Press <i>%s</i> for help</small>").format(this.activeArea.helper.helpKeyLabel) + "\n\n" + _("Entering drawing mode");
Main.osdWindowManager.show(currentIndex, this.enterGicon, label, null);
Main.osdWindowManager._osdWindows[this.areas.indexOf(this.activeArea)]._label.get_clutter_text().set_use_markup(true);
try { OsdWindow.HIDE_TIMEOUT = hideTimeoutSave; } catch(e) {} try { OsdWindow.HIDE_TIMEOUT = hideTimeoutSave; } catch(e) {}
} }
} }

View File

@ -36,7 +36,8 @@ msgstr ""
msgid "Leaving drawing mode" msgid "Leaving drawing mode"
msgstr "" msgstr ""
msgid "Press Ctrl + F1 for help" # %s is a key label
msgid "<small>Press <i>%s</i> for help</small>"
msgstr "" msgstr ""
msgid "Entering drawing mode" msgid "Entering drawing mode"
@ -76,14 +77,16 @@ msgstr ""
msgid "Full line" msgid "Full line"
msgstr "" msgstr ""
# %s is a key label
msgid "" msgid ""
"Press <i>Enter</i>\n" "Press <i>%s</i>\n"
"to mark vertices" "to mark vertices"
msgstr "" msgstr ""
# %s is a key label
msgid "" msgid ""
"Type your text\n" "Type your text\n"
"and press <i>Escape</i>" "and press <i>%s</i>"
msgstr "" msgstr ""
msgid "Screenshot" msgid "Screenshot"
@ -133,7 +136,7 @@ msgstr ""
msgid "About" msgid "About"
msgstr "" msgstr ""
# GLOBAL_KEYBINDINGS #: GLOBAL_KEYBINDINGS
msgid "Enter/leave drawing mode" msgid "Enter/leave drawing mode"
msgstr "" msgstr ""
@ -141,7 +144,7 @@ msgstr ""
msgid "Erase all drawings" msgid "Erase all drawings"
msgstr "" msgstr ""
# INTERNAL_KEYBINDINGS #: INTERNAL_KEYBINDINGS
msgid "Undo last brushstroke" msgid "Undo last brushstroke"
msgstr "" msgstr ""
@ -197,9 +200,9 @@ msgstr ""
msgid "Change linecap" msgid "Change linecap"
msgstr "" msgstr ""
# already in draw.js #: already in draw.js
#msgid "Dashed line" #:msgid "Dashed line"
#msgstr "" #:msgstr ""
msgid "Change font family (generic name)" msgid "Change font family (generic name)"
msgstr "" msgstr ""
@ -228,9 +231,9 @@ msgstr ""
msgid "Open next drawing" msgid "Open next drawing"
msgstr "" msgstr ""
# already in draw.js #: already in draw.js
#msgid "Save drawing" #:msgid "Save drawing"
#msgstr "" #:msgstr ""
msgid "Save drawing as a SVG file" msgid "Save drawing as a SVG file"
msgstr "" msgstr ""
@ -241,7 +244,7 @@ msgstr ""
msgid "Show help" msgid "Show help"
msgstr "" msgstr ""
# OTHER_SHORTCUTS #: OTHER_SHORTCUTS
msgid "Draw" msgid "Draw"
msgstr "" msgstr ""
@ -261,9 +264,6 @@ msgstr ""
msgid "Transform shape (when drawing)" msgid "Transform shape (when drawing)"
msgstr "" msgstr ""
msgid "Ctrl key"
msgstr ""
msgid "Increment/decrement line width" msgid "Increment/decrement line width"
msgstr "" msgstr ""
@ -273,40 +273,36 @@ msgstr ""
msgid "Select color" msgid "Select color"
msgstr "" msgstr ""
msgid "Ctrl+1...9" # %s are key labels (Ctrl+F1 and Ctrl+F9)
msgid "%s … %s"
msgstr "" msgstr ""
msgid "Select eraser" msgid "Select eraser"
msgstr "" msgstr ""
msgid "Shift key held" # %s is a key label
msgid "%s held"
msgstr "" msgstr ""
msgid "Ignore pointer movement" msgid "Ignore pointer movement"
msgstr "" msgstr ""
msgid "Space key held"
msgstr ""
msgid "Leave" msgid "Leave"
msgstr "" msgstr ""
msgid "Escape key" #: About page
# You are free to translate the extension name, that is displayed in About page, or not.
msgid "Draw On You Screen"
msgstr "" msgstr ""
# About page
# you are free to translate the extension name
#msgid "Draw On You Screen"
#msgstr ""
msgid "Version %d" msgid "Version %d"
msgstr "" msgstr ""
msgid "Start drawing with Super+Alt+D and save your beautiful work by taking a screenshot" msgid "Start drawing with Super+Alt+D and save your beautiful work by taking a screenshot"
msgstr "" msgstr ""
# Prefs page #: Prefs page
msgid "Global" msgid "Global"
msgstr "" msgstr ""

View File

@ -77,16 +77,21 @@ var INTERNAL_KEYBINDINGS = {
'toggle-help': "Show help" 'toggle-help': "Show help"
}; };
function getKeyLabel(accel) {
let [keyval, mods] = Gtk.accelerator_parse(accel);
return Gtk.accelerator_get_label(keyval, mods);
}
var OTHER_SHORTCUTS = [ var OTHER_SHORTCUTS = [
{ desc: "Draw", shortcut: "Left click" }, { desc: "Draw", get shortcut() { return _("Left click"); } },
{ desc: "Menu", shortcut: "Right click" }, { desc: "Menu", get shortcut() { return _("Right click"); } },
{ desc: "Toggle fill/stroke", shortcut: "Center click" }, { desc: "Toggle fill/stroke", get shortcut() { return _("Center click"); } },
{ desc: "Transform shape (when drawing)", shortcut: "Ctrl key" }, { desc: "Transform shape (when drawing)", shortcut: getKeyLabel('<Primary>') },
{ desc: "Increment/decrement line width", shortcut: "Scroll" }, { desc: "Increment/decrement line width", get shortcut() { return _("Scroll"); } },
{ desc: "Select color", shortcut: "Ctrl+1...9" }, { desc: "Select color", get shortcut() { return _("%s … %s").format(getKeyLabel('<Primary>1'), getKeyLabel('<Primary>9')); } },
{ desc: "Select eraser", shortcut: "Shift key held" }, { desc: "Select eraser", get shortcut() { return _("%s held").format(getKeyLabel('<Shift>')); } },
{ desc: "Ignore pointer movement", shortcut: "Space key held" }, { desc: "Ignore pointer movement", get shortcut() { return _("%s held").format(getKeyLabel('space')); } },
{ desc: "Leave", shortcut: "Escape key" } { desc: "Leave", shortcut: getKeyLabel('Escape') }
]; ];
function init() { function init() {
@ -270,7 +275,7 @@ const PrefsPage = new GObject.Class({
let otherBox = new Gtk.Box({ margin_left: MARGIN, margin_right: MARGIN }); let otherBox = new Gtk.Box({ margin_left: MARGIN, margin_right: MARGIN });
let otherLabel = new Gtk.Label({ label: _(OTHER_SHORTCUTS[i].desc) }); let otherLabel = new Gtk.Label({ label: _(OTHER_SHORTCUTS[i].desc) });
otherLabel.set_halign(1); otherLabel.set_halign(1);
let otherLabel2 = new Gtk.Label({ label: _(OTHER_SHORTCUTS[i].shortcut) }); let otherLabel2 = new Gtk.Label({ label: OTHER_SHORTCUTS[i].shortcut });
otherBox.pack_start(otherLabel, true, true, 4); otherBox.pack_start(otherLabel, true, true, 4);
otherBox.pack_start(otherLabel2, false, false, 4); otherBox.pack_start(otherLabel2, false, false, 4);
listBox.add(otherBox); listBox.add(otherBox);