Niklas Wenzel has proposed merging lp:~nikwen/ubuntu-terminal-app/layout-i18n into lp:ubuntu-terminal-app.
Commit message: Add the ability to translate strings from json profiles Requested reviews: Ubuntu Terminal Developers (ubuntu-terminal-dev) Related bugs: Bug #1464319 in Ubuntu Terminal App: "Terminal layout names should be translatable" https://bugs.launchpad.net/ubuntu-terminal-app/+bug/1464319 For more details, see: https://code.launchpad.net/~nikwen/ubuntu-terminal-app/layout-i18n/+merge/264620 Add the ability to translate strings from json profiles -- Your team Ubuntu Terminal Developers is requested to review the proposed merge of lp:~nikwen/ubuntu-terminal-app/layout-i18n into lp:ubuntu-terminal-app.
=== modified file 'po/com.ubuntu.terminal.pot' --- po/com.ubuntu.terminal.pot 2015-06-18 21:10:04 +0000 +++ po/com.ubuntu.terminal.pot 2015-07-13 17:22:19 +0000 @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2015-06-14 17:32+0200\n" +"POT-Creation-Date: 2015-07-10 16:35+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <[email protected]>\n" @@ -57,6 +57,98 @@ msgid "Change Keyboard" msgstr "" +#. TRANSLATORS: This a keyboard layout name +#: ../src/app/qml/KeyboardRows/JsonTranslator.qml:18 +msgid "Control Keys" +msgstr "" + +#. TRANSLATORS: This a keyboard layout name +#: ../src/app/qml/KeyboardRows/JsonTranslator.qml:21 +msgid "Function Keys" +msgstr "" + +#. TRANSLATORS: This a keyboard layout name +#: ../src/app/qml/KeyboardRows/JsonTranslator.qml:24 +msgid "Scroll Keys" +msgstr "" + +#. TRANSLATORS: This a keyboard layout name +#: ../src/app/qml/KeyboardRows/JsonTranslator.qml:27 +msgid "Command Keys" +msgstr "" + +#. TRANSLATORS: This the short display name of a keyboard layout. It should be no longer than 4 characters! +#. TRANSLATORS: This is the name of the Control key. All letters should be uppercase! +#: ../src/app/qml/KeyboardRows/JsonTranslator.qml:35 +#: ../src/app/qml/KeyboardRows/JsonTranslator.qml:61 +msgid "CTRL" +msgstr "" + +#. TRANSLATORS: This the short display name of a keyboard layout. It should be no longer than 4 characters! +#: ../src/app/qml/KeyboardRows/JsonTranslator.qml:38 +msgid "FNS" +msgstr "" + +#. TRANSLATORS: This the short display name of a keyboard layout. It should be no longer than 4 characters! +#: ../src/app/qml/KeyboardRows/JsonTranslator.qml:41 +msgid "SCR" +msgstr "" + +#. TRANSLATORS: This the short display name of a keyboard layout. It should be no longer than 4 characters! +#: ../src/app/qml/KeyboardRows/JsonTranslator.qml:44 +msgid "CMD" +msgstr "" + +#. TRANSLATORS: This is the name of the Alt key. All letters should be uppercase! +#: ../src/app/qml/KeyboardRows/JsonTranslator.qml:64 +msgid "ALT" +msgstr "" + +#. TRANSLATORS: This is the name of the Shift key. All letters should be uppercase! +#: ../src/app/qml/KeyboardRows/JsonTranslator.qml:67 +msgid "SHIFT" +msgstr "" + +#. TRANSLATORS: This is the name of the Escape key. All letters should be uppercase! +#: ../src/app/qml/KeyboardRows/JsonTranslator.qml:80 +msgid "ESC" +msgstr "" + +#. TRANSLATORS: This is the name of the Page Up key. All letters should be uppercase! +#: ../src/app/qml/KeyboardRows/JsonTranslator.qml:83 +msgid "PG_UP" +msgstr "" + +#. TRANSLATORS: This is the name of the Page Down key. All letters should be uppercase! +#: ../src/app/qml/KeyboardRows/JsonTranslator.qml:86 +msgid "PG_DN" +msgstr "" + +#. TRANSLATORS: This is the name of the Delete key. All letters should be uppercase! +#: ../src/app/qml/KeyboardRows/JsonTranslator.qml:89 +msgid "DEL" +msgstr "" + +#. TRANSLATORS: This is the name of the Home key. All letters should be uppercase! +#: ../src/app/qml/KeyboardRows/JsonTranslator.qml:92 +msgid "HOME" +msgstr "" + +#. TRANSLATORS: This is the name of the End key. All letters should be uppercase! +#: ../src/app/qml/KeyboardRows/JsonTranslator.qml:95 +msgid "END" +msgstr "" + +#. TRANSLATORS: This is the name of the Tab key. All letters should be uppercase! +#: ../src/app/qml/KeyboardRows/JsonTranslator.qml:98 +msgid "TAB" +msgstr "" + +#. TRANSLATORS: This is the name of the Enter key. All letters should be uppercase! +#: ../src/app/qml/KeyboardRows/JsonTranslator.qml:101 +msgid "ENTER" +msgstr "" + #: ../src/app/qml/LayoutsPage.qml:27 ../src/app/qml/SettingsPage.qml:36 msgid "Layouts" msgstr "" @@ -85,7 +177,7 @@ msgid "New tab" msgstr "" -#: ../src/app/qml/TerminalPage.qml:166 +#: ../src/app/qml/TerminalPage.qml:164 msgid "Selection Mode" msgstr "" === added file 'src/app/qml/KeyboardRows/JsonTranslator.qml' --- src/app/qml/KeyboardRows/JsonTranslator.qml 1970-01-01 00:00:00 +0000 +++ src/app/qml/KeyboardRows/JsonTranslator.qml 2015-07-13 17:22:19 +0000 @@ -0,0 +1,115 @@ +import QtQuick 2.0 +import Ubuntu.Components 1.1 + +Item { + + // Enum for translation types + readonly property int name: 0 + readonly property int shortName: 1 + readonly property int modifier: 2 + readonly property int key: 3 + + // The first parameter has to be one of the readonly properties above + function getTranslatedNameById(type, id) { + switch(type) { + case name: + if (id === "ctrl_keys") { + // TRANSLATORS: This a keyboard layout name + return i18n.tr("Control Keys"); + } else if (id === "fn_keys") { + // TRANSLATORS: This a keyboard layout name + return i18n.tr("Function Keys"); + } else if (id === "scroll_keys") { + // TRANSLATORS: This a keyboard layout name + return i18n.tr("Scroll Keys"); + } else if (id === "simple_cmds") { + // TRANSLATORS: This a keyboard layout name + return i18n.tr("Command Keys"); + } + + return ""; + case shortName: + var translation = ""; + if (id === "ctrl_keys") { + // TRANSLATORS: This the short display name of a keyboard layout. It should be no longer than 4 characters! + translation = i18n.tr("CTRL"); + } else if (id === "fn_keys") { + // TRANSLATORS: This the short display name of a keyboard layout. It should be no longer than 4 characters! + translation = i18n.tr("FNS"); + } else if (id === "scroll_keys") { + // TRANSLATORS: This the short display name of a keyboard layout. It should be no longer than 4 characters! + translation = i18n.tr("SCR"); + } else if (id === "simple_cmds") { + // TRANSLATORS: This the short display name of a keyboard layout. It should be no longer than 4 characters! + translation = i18n.tr("CMD"); + } + + if (translation !== "") { + // Shorten the string if the translation is longer than 4 characters + if (translation.length <= 4) { + return translation; + } else { + return translation.substring(0, 4); + } + } + + return ""; + case modifier: + var translation = ""; + if (id === "Control") { + // TRANSLATORS: This is the name of the Control key. All letters should be uppercase! + translation = i18n.tr("CTRL"); + } else if (id === "Alt") { + // TRANSLATORS: This is the name of the Alt key. All letters should be uppercase! + translation = i18n.tr("ALT"); + } else if (id === "Shift") { + // TRANSLATORS: This is the name of the Shift key. All letters should be uppercase! + translation = i18n.tr("SHIFT"); + } + + if (translation !== "") { + // Always return the translation in uppercase letters + return translation.toUpperCase(); + } + + return id; + case key: + var translation = ""; + if (id === "esc_key") { + // TRANSLATORS: This is the name of the Escape key. All letters should be uppercase! + translation = i18n.tr("ESC"); + } else if (id === "pg_up_key") { + // TRANSLATORS: This is the name of the Page Up key. All letters should be uppercase! + translation = i18n.tr("PG_UP"); + } else if (id === "pg_dn_key") { + // TRANSLATORS: This is the name of the Page Down key. All letters should be uppercase! + translation = i18n.tr("PG_DN"); + } else if (id === "del_key") { + // TRANSLATORS: This is the name of the Delete key. All letters should be uppercase! + translation = i18n.tr("DEL"); + } else if (id === "home_key") { + // TRANSLATORS: This is the name of the Home key. All letters should be uppercase! + translation = i18n.tr("HOME"); + } else if (id === "end_key") { + // TRANSLATORS: This is the name of the End key. All letters should be uppercase! + translation = i18n.tr("END"); + } else if (id === "tab_key") { + // TRANSLATORS: This is the name of the Tab key. All letters should be uppercase! + translation = i18n.tr("TAB"); + } else if (id === "enter_key") { + // TRANSLATORS: This is the name of the Enter key. All letters should be uppercase! + translation = i18n.tr("ENTER"); + } + + if (translation !== "") { + // Always return the translation in uppercase letters + return translation.toUpperCase(); + } + + return id; + default: + return ""; + } + } + +} === modified file 'src/app/qml/KeyboardRows/KeyboardLayout.qml' --- src/app/qml/KeyboardRows/KeyboardLayout.qml 2015-04-01 22:01:44 +0000 +++ src/app/qml/KeyboardRows/KeyboardLayout.qml 2015-07-13 17:22:19 +0000 @@ -7,6 +7,8 @@ id: keyboardRow keyWidth: units.gu(5) + readonly property variant modifiers: ["Control", "Alt", "Shift"] + // This label is used to compute the maximum width of all the controls. Label { id: hiddenLabel @@ -23,7 +25,7 @@ function createActionString(action) { switch(action.type){ case "key": - return createKeyActionString(action.key, action.mod, action.text); + return createKeyActionString(action.key, action.mod, action.text, action.id); case "string": return createStringActionString(action.string, action.text); } @@ -42,12 +44,11 @@ return result + "]"; } - function createKeyActionString(key, mod, text) { - if (["Control", "Alt", "Shift"].indexOf(mod) === -1) + function createKeyActionString(key, mod, text, id) { + if (modifiers.indexOf(mod) === -1) mod = "No"; - var textString = text ? "text: \"" + text + "\";" : ""; - return "Action { " + textString + " onTriggered: simulateKey(Qt.Key_"+ key + ", Qt." + mod + "Modifier); }"; + return "Action { text: \"" + createKeyText(key, mod, text, id) + "\"; onTriggered: simulateKey(Qt.Key_"+ key + ", Qt." + mod + "Modifier); }"; } function createStringActionString(string, text) { @@ -68,6 +69,17 @@ return objectString; } + function createKeyText(key, mod, text, id) { + if (id) { + return translator.getTranslatedNameById(translator.key, id); + } else if (text) { + return text; + } else if (key) { + return ((mod && modifiers.indexOf(mod) !== -1) ? translator.getTranslatedNameById(translator.modifier, mod) + "+" : "") + key; + } else + return ""; + } + function loadProfile(profileObject) { dropProfile(); @@ -76,28 +88,38 @@ // This function might raise exceptions which are handled in KeyboardBar.qml var profile = profileObject; - name = profile.name; - short_name = profile.short_name; + var name = ""; + var shortName = ""; + if (profile.id) { + name = translator.getTranslatedNameById(translator.name, profile.id); + short_name = translator.getTranslatedNameById(translator.shortName, profile.id); + } + if (name === "") + name = profile.name; + if (short_name === "") + short_name = profile.short_name; var layoutModel = [] for (var i = 0; i < profile.buttons.length; i++) { var button = profile.buttons[i]; + var keyText = createKeyText(button.main_action.key, button.main_action.mod, button.main_action.text, button.main_action.id); var mainActionString = createActionString(button.main_action); var otherActionsString = button.other_actions ? createOtherActionsString(button.other_actions) : "[]"; - var entryString = createEntryString(button.main_action.text, mainActionString, otherActionsString); + var entryString = createEntryString(keyText, mainActionString, otherActionsString); layoutModel.push(Qt.createQmlObject(entryString, keyboardRow)); - hiddenLabel.text = button.main_action.text; + hiddenLabel.text = keyText; maxWidth = Math.max(hiddenLabel.width, maxWidth); } keyWidth = maxWidth + units.gu(3); model = layoutModel; } + Component.onDestruction: dropProfile(); } === modified file 'src/app/qml/KeyboardRows/Layouts/ControlKeys.json' --- src/app/qml/KeyboardRows/Layouts/ControlKeys.json 2015-04-21 09:44:54 +0000 +++ src/app/qml/KeyboardRows/Layouts/ControlKeys.json 2015-07-13 17:22:19 +0000 @@ -1,12 +1,10 @@ { - "name" : "Control Keys", - "short_name" : "CTRL", + "id" : "ctrl_keys", "buttons": [ { "main_action" : { "type": "key", - "text" : "CTRL+R", "key" : "R", "mod" : "Control" } @@ -14,7 +12,6 @@ { "main_action" : { "type": "key", - "text" : "CTRL+C", "key" : "C", "mod" : "Control" } @@ -22,7 +19,6 @@ { "main_action" : { "type": "key", - "text" : "CTRL+A", "key" : "A", "mod" : "Control" } @@ -30,7 +26,6 @@ { "main_action" : { "type": "key", - "text" : "CTRL+Z", "key" : "Z", "mod" : "Control" } @@ -38,7 +33,6 @@ { "main_action" : { "type": "key", - "text" : "CTRL+D", "key" : "D", "mod" : "Control" } === modified file 'src/app/qml/KeyboardRows/Layouts/FunctionKeys.json' --- src/app/qml/KeyboardRows/Layouts/FunctionKeys.json 2015-02-03 21:43:38 +0000 +++ src/app/qml/KeyboardRows/Layouts/FunctionKeys.json 2015-07-13 17:22:19 +0000 @@ -1,96 +1,83 @@ { - "name" : "Function Keys", - "short_name" : "FNS", + "id" : "fn_keys", "buttons": [ { "main_action" : { "type": "key", - "text" : "ESC", + "id" : "esc_key", "key" : "Escape" } }, { "main_action" : { "type": "key", - "text" : "F1", "key" : "F1" } }, { "main_action" : { "type": "key", - "text" : "F2", "key" : "F2" } }, { "main_action" : { "type": "key", - "text" : "F3", "key" : "F3" } }, { "main_action" : { "type": "key", - "text" : "F4", "key" : "F4" } }, { "main_action" : { "type": "key", - "text" : "F5", "key" : "F5" } }, { "main_action" : { "type": "key", - "text" : "F6", "key" : "F6" } }, { "main_action" : { "type": "key", - "text" : "F7", "key" : "F7" } }, { "main_action" : { "type": "key", - "text" : "F8", "key" : "F8" } }, { "main_action" : { "type": "key", - "text" : "F9", "key" : "F9" } }, { "main_action" : { "type": "key", - "text" : "F10", - "key" : "F10" - } - }, - { - "main_action" : { - "type": "key", - "text" : "F10", - "key" : "F10" - } - }, - { - "main_action" : { - "type": "key", - "text" : "F11", + "key" : "F10" + } + }, + { + "main_action" : { + "type": "key", + "key" : "F10" + } + }, + { + "main_action" : { + "type": "key", "key" : "F11" } } === modified file 'src/app/qml/KeyboardRows/Layouts/Nano.json' --- src/app/qml/KeyboardRows/Layouts/Nano.json 2015-03-25 21:08:22 +0000 +++ src/app/qml/KeyboardRows/Layouts/Nano.json 2015-07-13 17:22:19 +0000 @@ -6,7 +6,6 @@ { "main_action" : { "type": "key", - "text" : "CTRL+G", "key" : "G", "mod" : "Control" } @@ -14,7 +13,6 @@ { "main_action" : { "type": "key", - "text" : "CTRL+O", "key" : "O", "mod" : "Control" } @@ -22,7 +20,6 @@ { "main_action" : { "type": "key", - "text" : "CTRL+R", "key" : "R", "mod" : "Control" } @@ -30,7 +27,6 @@ { "main_action" : { "type": "key", - "text" : "CTRL+Y", "key" : "Y", "mod" : "Control" } @@ -38,7 +34,6 @@ { "main_action" : { "type": "key", - "text" : "CTRL+K", "key" : "K", "mod" : "Control" } @@ -46,7 +41,6 @@ { "main_action" : { "type": "key", - "text" : "CTRL+C", "key" : "C", "mod" : "Control" } @@ -55,7 +49,6 @@ { "main_action" : { "type": "key", - "text" : "CTRL+X", "key" : "X", "mod" : "Control" } @@ -63,7 +56,6 @@ { "main_action" : { "type": "key", - "text" : "CTRL+J", "key" : "J", "mod" : "Control" } @@ -71,7 +63,6 @@ { "main_action" : { "type": "key", - "text" : "CTRL+W", "key" : "W", "mod" : "Control" } @@ -79,7 +70,6 @@ { "main_action" : { "type": "key", - "text" : "CTRL+V", "key" : "V", "mod" : "Control" } @@ -87,7 +77,6 @@ { "main_action" : { "type": "key", - "text" : "CTRL+U", "key" : "U", "mod" : "Control" } @@ -95,7 +84,6 @@ { "main_action" : { "type": "key", - "text" : "CTRL+T", "key" : "T", "mod" : "Control" } === modified file 'src/app/qml/KeyboardRows/Layouts/ScrollKeys.json' --- src/app/qml/KeyboardRows/Layouts/ScrollKeys.json 2015-06-02 09:49:00 +0000 +++ src/app/qml/KeyboardRows/Layouts/ScrollKeys.json 2015-07-13 17:22:19 +0000 @@ -1,54 +1,53 @@ { - "name" : "Scroll Keys", - "short_name" : "SCR", + "id" : "scroll_keys", "buttons": [ { "main_action" : { "type": "key", - "text" : "PG_UP", + "id" : "pg_up_key", "key" : "PageUp" } }, { "main_action" : { "type": "key", - "text" : "PG_DN", + "id" : "pg_dn_key", "key" : "PageDown" } }, { "main_action" : { "type": "key", - "text" : "DEL", + "id" : "del_key", "key" : "Delete" } }, { "main_action" : { "type": "key", - "text" : "HOME", + "id" : "home_key", "key" : "Home" } }, { "main_action" : { "type": "key", - "text" : "END", + "id" : "end_key", "key" : "End" } }, { "main_action" : { "type": "key", - "text" : "TAB", + "id" : "tab_key", "key" : "Tab" } }, { "main_action" : { "type": "key", - "text" : "ENTER", + "id" : "enter_key", "key" : "Enter" } }, === modified file 'src/app/qml/KeyboardRows/Layouts/SimpleCommands.json' --- src/app/qml/KeyboardRows/Layouts/SimpleCommands.json 2015-03-06 11:05:22 +0000 +++ src/app/qml/KeyboardRows/Layouts/SimpleCommands.json 2015-07-13 17:22:19 +0000 @@ -1,6 +1,5 @@ { - "name" : "Commands Key", - "short_name" : "CMD", + "id" : "simple_cmds", "buttons": [ { === modified file 'src/app/qml/KeyboardRows/jsonParser.js' --- src/app/qml/KeyboardRows/jsonParser.js 2015-02-14 12:46:38 +0000 +++ src/app/qml/KeyboardRows/jsonParser.js 2015-07-13 17:22:19 +0000 @@ -27,8 +27,8 @@ raiseException("type is missing in", actionObject); if (!isAllowed(actionObject.type, ["key", "string"])) raiseException("type must be either key or string in", actionObject); - if (!actionObject.text) - raiseException("text is missing in", actionObject); + if (actionObject.id && actionObject.text) + raiseException("Should not define id and text together in ", layoutObject); switch (actionObject.type) { case "key": @@ -58,10 +58,18 @@ } function validateLayout(layoutObject) { - if (!layoutObject.name) - raiseException("name is missing in ", layoutObject); - if (!layoutObject.short_name) - raiseException("short_name is missing in", layoutObject); + if (!layoutObject.id) { + if (!layoutObject.name) + raiseException("name or id is missing in ", layoutObject); + if (!layoutObject.short_name) + raiseException("short_name or id is missing in", layoutObject); + } else { + if (layoutObject.name) + raiseException("Should not define id and name together in ", layoutObject); + if (layoutObject.short_name) + raiseException("Should not define id and short_name together in ", layoutObject); + } + if (!layoutObject.buttons) raiseException("buttons is missing in", layoutObject); === modified file 'src/app/qml/TerminalSettings.qml' --- src/app/qml/TerminalSettings.qml 2015-06-11 22:10:24 +0000 +++ src/app/qml/TerminalSettings.qml 2015-07-13 17:22:19 +0000 @@ -50,7 +50,7 @@ } catch (e) {} function isProfileVisible(profilePath) { - return !(visibleProfiles[profilePath] == false); + return !(visibleProfiles[profilePath] === false); } for (var i = 0; i < keyboardLayouts.length; i++) { @@ -60,12 +60,18 @@ try { var profileObject = Parser.parseJson(fileIO.read(filePath)); + var name = ""; + if (profileObject.id) + name = translator.getTranslatedNameById(translator.name, profileObject.id); + if (name === "") + name = profileObject.name; + profilesList.append( { file: filePath, profileVisible: isVisible, object: profileObject, - name: profileObject.name + name: name }); } catch (e) { console.error("Error in profile", filePath); === modified file 'src/app/qml/ubuntu-terminal-app.qml' --- src/app/qml/ubuntu-terminal-app.qml 2015-03-26 22:32:38 +0000 +++ src/app/qml/ubuntu-terminal-app.qml 2015-07-13 17:22:19 +0000 @@ -1,6 +1,7 @@ import QtQuick 2.3 import QtGraphicalEffects 1.0 import Ubuntu.Components 1.1 +import "KeyboardRows" import QMLTermWidget 1.0 @@ -32,6 +33,10 @@ Component.onCompleted: addTab(); } + JsonTranslator { + id: translator + } + PageStack { id: pageStack Component.onCompleted: push(terminalPage)
-- Mailing list: https://launchpad.net/~ubuntu-touch-coreapps-reviewers Post to : [email protected] Unsubscribe : https://launchpad.net/~ubuntu-touch-coreapps-reviewers More help : https://help.launchpad.net/ListHelp

