| 1 |
/* |
| 2 |
* Copyright (C) 2015 Canonical Ltd |
| 3 |
* |
| 4 |
* This program is free software: you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License version 3 as |
| 6 |
* published by the Free Software Foundation. |
| 7 |
* |
| 8 |
* This program is distributed in the hope that it will be useful, |
| 9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
* GNU General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU General Public License |
| 14 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 |
* |
| 16 |
* Author: Niklas Wenzel <[email protected]> |
| 17 |
*/ |
| 18 |
import QtQuick 2.4 |
| 19 |
import Lomiri.Components 1.3 |
| 20 |
|
| 21 |
QtObject { |
| 22 |
|
| 23 |
// Enum for translation types |
| 24 |
readonly property int name: 0 |
| 25 |
readonly property int shortName: 1 |
| 26 |
readonly property int modifier: 2 |
| 27 |
readonly property int key: 3 |
| 28 |
|
| 29 |
// The first parameter has to be one of the readonly properties above |
| 30 |
function getTranslatedNameById(type, id) { |
| 31 |
switch(type) { |
| 32 |
case name: |
| 33 |
if (id === "ctrl_keys") { |
| 34 |
// TRANSLATORS: This a keyboard layout name |
| 35 |
return i18n.tr("Control Keys"); |
| 36 |
} else if (id === "fn_keys") { |
| 37 |
// TRANSLATORS: This a keyboard layout name |
| 38 |
return i18n.tr("Function Keys"); |
| 39 |
} else if (id === "scroll_keys") { |
| 40 |
// TRANSLATORS: This a keyboard layout name |
| 41 |
return i18n.tr("Scroll Keys"); |
| 42 |
} else if (id === "simple_cmds") { |
| 43 |
// TRANSLATORS: This a keyboard layout name |
| 44 |
return i18n.tr("Command Keys"); |
| 45 |
} |
| 46 |
|
| 47 |
return ""; |
| 48 |
case shortName: |
| 49 |
var translation = ""; |
| 50 |
if (id === "ctrl_keys") { |
| 51 |
// TRANSLATORS: This the short display name of a keyboard layout. It should be no longer than 4 characters! |
| 52 |
translation = i18n.tr("Ctrl"); |
| 53 |
} else if (id === "fn_keys") { |
| 54 |
// TRANSLATORS: This the short display name of a keyboard layout. It should be no longer than 4 characters! |
| 55 |
translation = i18n.tr("Fn"); |
| 56 |
} else if (id === "scroll_keys") { |
| 57 |
// TRANSLATORS: This the short display name of a keyboard layout. It should be no longer than 4 characters! |
| 58 |
translation = i18n.tr("Scr"); |
| 59 |
} else if (id === "simple_cmds") { |
| 60 |
// TRANSLATORS: This the short display name of a keyboard layout. It should be no longer than 4 characters! |
| 61 |
translation = i18n.tr("Cmd"); |
| 62 |
} |
| 63 |
|
| 64 |
if (translation !== "") { |
| 65 |
// Shorten the string if the translation is longer than 4 characters |
| 66 |
if (translation.length <= 4) { |
| 67 |
return translation; |
| 68 |
} else { |
| 69 |
return translation.substring(0, 4); |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
return ""; |
| 74 |
case modifier: |
| 75 |
var translation = ""; |
| 76 |
if (id === "Control") { |
| 77 |
// TRANSLATORS: This is the name of the Control key. |
| 78 |
translation = i18n.tr("CTRL"); |
| 79 |
} else if (id === "Alt") { |
| 80 |
// TRANSLATORS: This is the name of the Alt key. |
| 81 |
translation = i18n.tr("Alt"); |
| 82 |
} else if (id === "Shift") { |
| 83 |
// TRANSLATORS: This is the name of the Shift key. |
| 84 |
translation = i18n.tr("Shift"); |
| 85 |
} |
| 86 |
|
| 87 |
if (translation !== "") { |
| 88 |
// Always return the translation in uppercase letters |
| 89 |
return translation.toUpperCase(); |
| 90 |
} |
| 91 |
|
| 92 |
return id; |
| 93 |
case key: |
| 94 |
var translation = ""; |
| 95 |
if (id === "esc_key") { |
| 96 |
// TRANSLATORS: This is the name of the Escape key. |
| 97 |
translation = i18n.tr("Esc"); |
| 98 |
} else if (id === "pg_up_key") { |
| 99 |
// TRANSLATORS: This is the name of the Page Up key. |
| 100 |
translation = i18n.tr("PgUp"); |
| 101 |
} else if (id === "pg_dn_key") { |
| 102 |
// TRANSLATORS: This is the name of the Page Down key. |
| 103 |
translation = i18n.tr("PgDn"); |
| 104 |
} else if (id === "del_key") { |
| 105 |
// TRANSLATORS: This is the name of the Delete key. |
| 106 |
translation = i18n.tr("Del"); |
| 107 |
} else if (id === "home_key") { |
| 108 |
// TRANSLATORS: This is the name of the Home key. |
| 109 |
translation = i18n.tr("Home"); |
| 110 |
} else if (id === "end_key") { |
| 111 |
// TRANSLATORS: This is the name of the End key. |
| 112 |
translation = i18n.tr("End"); |
| 113 |
} else if (id === "tab_key") { |
| 114 |
// TRANSLATORS: This is the name of the Tab key. |
| 115 |
translation = i18n.tr("Tab"); |
| 116 |
} else if (id === "enter_key") { |
| 117 |
// TRANSLATORS: This is the name of the Enter key. |
| 118 |
translation = i18n.tr("Enter"); |
| 119 |
} |
| 120 |
|
| 121 |
return id; |
| 122 |
default: |
| 123 |
return ""; |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
} |