From 86aa31920c379bb6ae691154cd2df469410ea243 Mon Sep 17 00:00:00 2001 From: precondition <57645186+precondition@users.noreply.github.com> Date: Sat, 13 Aug 2022 00:00:49 +0200 Subject: [PATCH] Add support for intl key legends based on the host keyboard layout This is the main commit of PR #1161. --- src/components/SettingsPanel.vue | 59 ++++++++++++------- src/i18n/de.csv | 8 ++- src/i18n/en.csv | 8 ++- src/i18n/es.csv | 8 ++- src/i18n/fr.csv | 8 ++- src/i18n/it.csv | 8 ++- src/i18n/ja.csv | 8 ++- src/i18n/ms.csv | 8 ++- src/i18n/pl-PL.csv | 8 ++- src/i18n/pt-BR.csv | 8 ++- src/i18n/ru.csv | 8 ++- src/i18n/zh-CN.csv | 8 ++- src/i18n/zh.csv | 8 ++- src/store/modules/app/actions.js | 7 ++- src/store/modules/app/mutations.js | 3 + src/store/modules/app/state.js | 10 +++- src/store/modules/keycodes/index.js | 88 +++++++++++++++++++++-------- 17 files changed, 192 insertions(+), 71 deletions(-) diff --git a/src/components/SettingsPanel.vue b/src/components/SettingsPanel.vue index 569f659f8c..8ecfaf1ef0 100644 --- a/src/components/SettingsPanel.vue +++ b/src/components/SettingsPanel.vue @@ -91,6 +91,28 @@ +
+ +
+
+ +
-
- -
-
- -
{{ helpText }}
@@ -157,7 +161,8 @@ export default { ...mapState('app', [ 'tutorialEnabled', 'configuratorSettings', - 'languages' + 'languages', + 'osKeyboardLayouts' ]), language: { get() { @@ -166,6 +171,14 @@ export default { async set(value) { await this.changeLanguage(value); } + }, + osKeyboardLayout: { + get() { + return this.configuratorSettings.osKeyboardLayout; + }, + async set(value) { + await this.changeOSKeyboardLayout(value); + } } }, methods: { @@ -174,6 +187,7 @@ export default { ...mapActions('app', [ 'toggleDarkMode', 'changeLanguage', + 'changeOSKeyboardLayout', 'toggleClearLayerDefault', 'toggleIso' ]), @@ -203,12 +217,15 @@ export default { case 'language': this.helpText = this.$t('settingsPanel.language.help'); break; - case 'clearLayer': - this.helpText = this.$t('settingsPanel.clearLayer.help'); + case 'osKeyboardLayout': + this.helpText = this.$t('settingsPanel.osKeyboardLayout.help'); break; case 'iso': this.helpText = this.$t('settingsPanel.iso.help'); break; + case 'clearLayer': + this.helpText = this.$t('settingsPanel.clearLayer.help'); + break; } if (this.clearTextTimer) { diff --git a/src/i18n/de.csv b/src/i18n/de.csv index 2fc0d6cd1a..eed9e8c086 100644 --- a/src/i18n/de.csv +++ b/src/i18n/de.csv @@ -111,8 +111,12 @@ settingsPanel:displaySizes:title,strg + alt + u settingsPanel:fastInput:help,"Gib die Tasten über die Tastatur ein, ohne auf die einzelnen Positionen zu klicken" settingsPanel:fastInput:label,Schnelle Eingabe settingsPanel:fastInput:title,strg + alt + f -settingsPanel:iso:help,ISO-Legenden standardmäßig anzeigen -settingsPanel:iso:label,Verwenden Sie ISO-Schlüssellegenden +settingsPanel:osKeyboardLayout:help, +settingsPanel:osKeyboardLayout:label:keymap_german,Deutsch (Deutschland & Österreich) +settingsPanel:osKeyboardLayout:label:keymap_russian,Russisch +settingsPanel:osKeyboardLayout:label:keymap_uk,Englisch (UK) +settingsPanel:osKeyboardLayout:label:keymap_us,Englisch (US) +settingsPanel:osKeyboardLayout:title, settingsPanel:kcno:label,KC_NO settingsPanel:kctrns:label,KC_TRNS settingsPanel:language:help, diff --git a/src/i18n/en.csv b/src/i18n/en.csv index b57f040b41..08a9def2b5 100644 --- a/src/i18n/en.csv +++ b/src/i18n/en.csv @@ -111,8 +111,12 @@ settingsPanel:displaySizes:title,ctrl + alt + u settingsPanel:fastInput:help,Input keys via keyboard without clicking each position. settingsPanel:fastInput:label,Fast Input settingsPanel:fastInput:title,ctrl + alt + f -settingsPanel:iso:help,Display ISO legends by default -settingsPanel:iso:label,Use ISO key legends +settingsPanel:osKeyboardLayout:title,Host Keyboard Layout +settingsPanel:osKeyboardLayout:help,Change the key legends to match with your host keyboard layout. +settingsPanel:osKeyboardLayout:label:keymap_us,English (US) +settingsPanel:osKeyboardLayout:label:keymap_uk,English (UK) +settingsPanel:osKeyboardLayout:label:keymap_german,German (Germany & Austria) +settingsPanel:osKeyboardLayout:label:keymap_russian,Russian settingsPanel:kcno:label,KC_NO settingsPanel:kctrns:label,KC_TRNS settingsPanel:language:help,Change the language of the user interface diff --git a/src/i18n/es.csv b/src/i18n/es.csv index 422614a178..3574956c08 100644 --- a/src/i18n/es.csv +++ b/src/i18n/es.csv @@ -111,8 +111,12 @@ settingsPanel:displaySizes:title,ctrl + alt + u settingsPanel:fastInput:help,Ingresar teclas por medio del teclado sin hacer click en cada posición. settingsPanel:fastInput:label,Entrada rápida settingsPanel:fastInput:title,ctrl + alt + f -settingsPanel:iso:help,Mostrar leyendas ISO de forma predeterminada -settingsPanel:iso:label,Utilice leyendas clave ISO +settingsPanel:osKeyboardLayout:title, +settingsPanel:osKeyboardLayout:help, +settingsPanel:osKeyboardLayout:label:keymap_german,Alemán (Alemania y Austria) +settingsPanel:osKeyboardLayout:label:keymap_russian,Ruso +settingsPanel:osKeyboardLayout:label:keymap_uk,Inglés (Reino Unido) +settingsPanel:osKeyboardLayout:label:keymap_us,Inglés (Estados Unidos) settingsPanel:kcno:label,KC_NO settingsPanel:kctrns:label,KC_TRNS settingsPanel:language:help, diff --git a/src/i18n/fr.csv b/src/i18n/fr.csv index b530b2dcf4..6bf78f8d7a 100644 --- a/src/i18n/fr.csv +++ b/src/i18n/fr.csv @@ -111,8 +111,12 @@ settingsPanel:displaySizes:title,ctrl + alt + u settingsPanel:fastInput:help,Permet d'entrer les touches via votre clavier sans cliquer sur chaque position. settingsPanel:fastInput:label,Entrée Rapide settingsPanel:fastInput:title,ctrl + alt + f -settingsPanel:iso:help,Afficher les légendes ISO par défaut -settingsPanel:iso:label,Utiliser les légendes des clés ISO +settingsPanel:osKeyboardLayout:title,Disposition des touches du système d'opération +settingsPanel:osKeyboardLayout:help,Change les légendes des touches pour qu'elles collent avec la disposition des touches du système. +settingsPanel:osKeyboardLayout:label:keymap_german,Allemand (Allemagne & Autriche) +settingsPanel:osKeyboardLayout:label:keymap_russian,Russe +settingsPanel:osKeyboardLayout:label:keymap_uk,Anglais (Royaume-Uni) +settingsPanel:osKeyboardLayout:label:keymap_us,Anglais (États-Unis) settingsPanel:kcno:label,KC_NO settingsPanel:kctrns:label,KC_TRNS settingsPanel:language:help, diff --git a/src/i18n/it.csv b/src/i18n/it.csv index 2f1a6830da..2729b07938 100644 --- a/src/i18n/it.csv +++ b/src/i18n/it.csv @@ -111,8 +111,12 @@ settingsPanel:displaySizes:title,Ctrl + Alt + U settingsPanel:fastInput:help,Inserire i tasti tramite la tastiera senza fare clic su ogni posizione. settingsPanel:fastInput:label,Ingresso rapido settingsPanel:fastInput:title,Ctrl + Alt + F -settingsPanel:iso:help,Visualizza le legende ISO automaticamente -settingsPanel:iso:label,Usa le legende delle chiavi ISO +settingsPanel:osKeyboardLayout:title, +settingsPanel:osKeyboardLayout:help, +settingsPanel:osKeyboardLayout:label:keymap_german,Tedesco (Germania e Austria) +settingsPanel:osKeyboardLayout:label:keymap_russian,Russo +settingsPanel:osKeyboardLayout:label:keymap_uk,Inglese (Regno Unito) +settingsPanel:osKeyboardLayout:label:keymap_us,Inglese (US) settingsPanel:kcno:label,KC_NO settingsPanel:kctrns:label,KC_TRNS settingsPanel:language:help,Cambia lingua dell'interfaccia utente diff --git a/src/i18n/ja.csv b/src/i18n/ja.csv index 3ea4da19db..cf9977ab6c 100644 --- a/src/i18n/ja.csv +++ b/src/i18n/ja.csv @@ -111,8 +111,12 @@ settingsPanel:displaySizes:title,ctrl + alt + u settingsPanel:fastInput:help,各位置をクリックせずキーボードでキーを入力する settingsPanel:fastInput:label,高速入力 settingsPanel:fastInput:title,ctrl + alt + f -settingsPanel:iso:help,デフォルトでISO凡例を表示 -settingsPanel:iso:label,ISOキーの凡例を使用する +settingsPanel:osKeyboardLayout:title, +settingsPanel:osKeyboardLayout:help, +settingsPanel:osKeyboardLayout:label:keymap_german,ドイツ語(ドイツ・オーストリア) +settingsPanel:osKeyboardLayout:label:keymap_russian,ロシア語 +settingsPanel:osKeyboardLayout:label:keymap_uk,英語 (UK) +settingsPanel:osKeyboardLayout:label:keymap_us,英語 (US) settingsPanel:kcno:label,KC_NO settingsPanel:kctrns:label,KC_TRNS settingsPanel:language:help,ユーザインタフェースの言語を変更する diff --git a/src/i18n/ms.csv b/src/i18n/ms.csv index fd7360d627..54d1c50bd0 100644 --- a/src/i18n/ms.csv +++ b/src/i18n/ms.csv @@ -111,8 +111,12 @@ settingsPanel:displaySizes:title,ctrl + alt + u settingsPanel:fastInput:help,Masukkan kekunci melalui papan kekunci tanpa klik setiap posisi. settingsPanel:fastInput:label,Input cepat settingsPanel:fastInput:title,ctrl + alt + f -settingsPanel:iso:help,Paparkan lagenda ISO secara lalai -settingsPanel:iso:label,Gunakan lagenda kunci ISO +settingsPanel:osKeyboardLayout:title, +settingsPanel:osKeyboardLayout:help, +settingsPanel:osKeyboardLayout:label:keymap_german, +settingsPanel:osKeyboardLayout:label:keymap_russian, +settingsPanel:osKeyboardLayout:label:keymap_uk, +settingsPanel:osKeyboardLayout:label:keymap_us, settingsPanel:kcno:label,KC_NO settingsPanel:kctrns:label,KC_TRNS settingsPanel:language:help, diff --git a/src/i18n/pl-PL.csv b/src/i18n/pl-PL.csv index 1c38d04365..56fb745ddd 100644 --- a/src/i18n/pl-PL.csv +++ b/src/i18n/pl-PL.csv @@ -111,8 +111,12 @@ settingsPanel:displaySizes:title,Ctrl + Alt + U settingsPanel:fastInput:help,Autmatyczne podświetlanie kolejnego klawisza po zdefiniowaniu funkcji poprzedniego. settingsPanel:fastInput:label,Szybkie wprowadzanie settingsPanel:fastInput:title,Ctrl + Alt + F -settingsPanel:iso:help,Domyślnie wyświetlaj legendy ISO -settingsPanel:iso:label,Użyj legendy kluczy ISO +settingsPanel:osKeyboardLayout:title, +settingsPanel:osKeyboardLayout:help, +settingsPanel:osKeyboardLayout:label:keymap_german,Niemiecki (Niemcy i Austria) +settingsPanel:osKeyboardLayout:label:keymap_russian,Rosyjski +settingsPanel:osKeyboardLayout:label:keymap_uk,Angielski (UK) +settingsPanel:osKeyboardLayout:label:keymap_us,Angielski (US) settingsPanel:kcno:label,KC_NO settingsPanel:kctrns:label,KC_TRNS settingsPanel:language:help, diff --git a/src/i18n/pt-BR.csv b/src/i18n/pt-BR.csv index c1a8790b48..9faf29ce8e 100644 --- a/src/i18n/pt-BR.csv +++ b/src/i18n/pt-BR.csv @@ -111,8 +111,12 @@ settingsPanel:displaySizes:title,ctrl + alt + u settingsPanel:fastInput:help,Entrada de comandos a partir do teclado sem clicar em outra posição. settingsPanel:fastInput:label,Entrada rápida settingsPanel:fastInput:title,ctrl + alt + f -settingsPanel:iso:help,Exibir legendas ISO por padrão -settingsPanel:iso:label,Use as legendas da chave ISO +settingsPanel:osKeyboardLayout:title, +settingsPanel:osKeyboardLayout:help, +settingsPanel:osKeyboardLayout:label:keymap_german,Alemão (Alemanha e Áustria) +settingsPanel:osKeyboardLayout:label:keymap_russian,Russo +settingsPanel:osKeyboardLayout:label:keymap_uk,Inglês (Reino Unido) +settingsPanel:osKeyboardLayout:label:keymap_us,Inglês (EUA) settingsPanel:kcno:label,KC_NO settingsPanel:kctrns:label,KC_TRNS settingsPanel:language:help, diff --git a/src/i18n/ru.csv b/src/i18n/ru.csv index 97616c9fbf..853caea030 100644 --- a/src/i18n/ru.csv +++ b/src/i18n/ru.csv @@ -111,8 +111,12 @@ settingsPanel:displaySizes:title,ctrl + alt + u settingsPanel:fastInput:help,Ввод клавиш через клавиатуру без необходимости нажимать на каждую позицию settingsPanel:fastInput:label,Быстрый ввод settingsPanel:fastInput:title,ctrl + alt + f -settingsPanel:iso:help,Отображать легенды ISO по умолчанию -settingsPanel:iso:label,Используйте ключевые легенды ISO +settingsPanel:osKeyboardLayout:title,Раскладка клавиатуры операционной системы +settingsPanel:osKeyboardLayout:help,Изменяет легенды клавиш в соответствии с раскладкой клавиатуры операционной системы. +settingsPanel:osKeyboardLayout:label:keymap_german,Немецкий (Германия и Австрия) +settingsPanel:osKeyboardLayout:label:keymap_russian,Русский +settingsPanel:osKeyboardLayout:label:keymap_uk,Английский (Великобритания) +settingsPanel:osKeyboardLayout:label:keymap_us,Английский (США) settingsPanel:kcno:label,KC_NO settingsPanel:kctrns:label,KC_TRNS settingsPanel:language:help, diff --git a/src/i18n/zh-CN.csv b/src/i18n/zh-CN.csv index 056b56bdad..b8fbf8eac4 100644 --- a/src/i18n/zh-CN.csv +++ b/src/i18n/zh-CN.csv @@ -111,8 +111,12 @@ settingsPanel:displaySizes:title,ctrl + alt + u settingsPanel:fastInput:help,直接通过键盘输入键位 settingsPanel:fastInput:label,快速输入 settingsPanel:fastInput:title,ctrl + alt + f -settingsPanel:iso:help,默认显示 ISO 图例 -settingsPanel:iso:label,使用 ISO 密钥图例 +settingsPanel:osKeyboardLayout:title, +settingsPanel:osKeyboardLayout:help, +settingsPanel:osKeyboardLayout:label:keymap_german,德语(德国和奥地利) +settingsPanel:osKeyboardLayout:label:keymap_russian,俄语 +settingsPanel:osKeyboardLayout:label:keymap_uk,英语(英国) +settingsPanel:osKeyboardLayout:label:keymap_us,英语(美国) settingsPanel:kcno:label, settingsPanel:kctrns:label, settingsPanel:language:help,更改用户界面语言 diff --git a/src/i18n/zh.csv b/src/i18n/zh.csv index bbfede5992..2f83561f32 100644 --- a/src/i18n/zh.csv +++ b/src/i18n/zh.csv @@ -109,8 +109,12 @@ settingsPanel:displaySizes:title, settingsPanel:fastInput:help, settingsPanel:fastInput:label, settingsPanel:fastInput:title, -settingsPanel:iso:help, -settingsPanel:iso:label, +settingsPanel:osKeyboardLayout:title, +settingsPanel:osKeyboardLayout:help, +settingsPanel:osKeyboardLayout:label:keymap_german, +settingsPanel:osKeyboardLayout:label:keymap_russian, +settingsPanel:osKeyboardLayout:label:keymap_uk, +settingsPanel:osKeyboardLayout:label:keymap_us, settingsPanel:kcno:label,KC_NO settingsPanel:kctrns:label,KC_TRNS settingsPanel:language:help, diff --git a/src/store/modules/app/actions.js b/src/store/modules/app/actions.js index 8516043dff..fec1804841 100644 --- a/src/store/modules/app/actions.js +++ b/src/store/modules/app/actions.js @@ -140,6 +140,11 @@ const actions = { commit('setCurrentLanguage', lang); await dispatch('saveConfiguratorSettings'); }, + async changeOSKeyboardLayout({ dispatch, commit }, osLayout) { + commit('setOSKeyboardLayout', osLayout); + this.commit('keycodes/changeKeyLegends'); + await dispatch('saveConfiguratorSettings'); + }, // if init state we just load and not toggling async toggleDarkMode({ commit, state, dispatch }, init) { let darkStatus = state.configuratorSettings.darkmodeEnabled; @@ -160,8 +165,6 @@ const actions = { iso = !iso; } commit('setIso', iso); - const keyboardLayout = iso ? 'enableIso' : 'disableIso'; - this.commit(`keycodes/${keyboardLayout}`); await dispatch('saveConfiguratorSettings'); }, async toggleClearLayerDefault({ commit, state, dispatch }) { diff --git a/src/store/modules/app/mutations.js b/src/store/modules/app/mutations.js index c120cbfe43..6cd62214f3 100644 --- a/src/store/modules/app/mutations.js +++ b/src/store/modules/app/mutations.js @@ -181,6 +181,9 @@ const mutations = { setDarkmode(state, value) { state.configuratorSettings.darkmodeEnabled = value; }, + setOSKeyboardLayout(state, value) { + state.configuratorSettings.osKeyboardLayout = value; + }, setIso(state, value) { state.configuratorSettings.iso = value; }, diff --git a/src/store/modules/app/state.js b/src/store/modules/app/state.js index e799b0fd97..a2f42e7981 100644 --- a/src/store/modules/app/state.js +++ b/src/store/modules/app/state.js @@ -15,7 +15,8 @@ function setDefaultConfiguratorSettings() { favoriteKeyboard: '', favoriteColor: '', clearLayerDefault: false, - iso: false + iso: false, + osKeyboardLayout: 'keymap_us' }; localStorageSet(CONSTS.configuratorSettings, JSON.stringify(initialConfig)); return initialConfig; @@ -75,6 +76,13 @@ const state = { { value: 'ja', label: '日本語' }, { value: 'zh-CN', label: '简体中文' } ], + osKeyboardLayouts: [ + // The labels are translatable strings + 'keymap_us', + 'keymap_uk', + 'keymap_german', + 'keymap_russian' + ], snowflakes: false }; diff --git a/src/store/modules/keycodes/index.js b/src/store/modules/keycodes/index.js index 6f3c213f1f..1023be2769 100644 --- a/src/store/modules/keycodes/index.js +++ b/src/store/modules/keycodes/index.js @@ -6,15 +6,19 @@ import settings from './kb-settings'; import media from './app-media-mouse'; import steno from './steno'; import store from '@/store'; +import keymapExtras from '@/i18n/keymap_extras'; -const keycodeLayout = { - ANSI: [...ansi, ...iso_jis], - ISO: [...iso_jis, ...ansi], - normal: [...quantum, ...settings, ...media] +const keycodePickerTabLayout = { + ANSI_ISO: [...ansi, ...iso_jis], + ISO_ANSI: [...iso_jis, ...ansi], + special: [...quantum, ...settings, ...media] }; const state = { - keycodes: [...keycodeLayout.ANSI, ...keycodeLayout.normal], + keycodes: [ + ...keycodePickerTabLayout.ANSI_ISO, + ...keycodePickerTabLayout.special + ], searchFilter: '', searchCounters: { ANSI: 0, @@ -27,17 +31,55 @@ const state = { active: 'ANSI' }; -function isISO() { - return store.state.app.configuratorSettings.iso; +function getOSKeyboardLayout() { + const fallbackOSKeyboardLayout = 'keymap_us'; + return ( + store.state.app.configuratorSettings.osKeyboardLayout || + fallbackOSKeyboardLayout + ); } -function generateKeycodes(isIso, isSteno) { +function isANSI() { + return keymapExtras[getOSKeyboardLayout()].isANSI; +} + +function toLocaleKeycode(keycodeLUT, keycodeObject) { + console.assert(!isUndefined(keycodeLUT)); + if ( + !Object.keys(keycodeObject).includes('name') || + !Object.keys(keycodeObject).includes('code') + ) { + // Not an object describing a keyboard key; return as is + return keycodeObject; + } + if (keycodeLUT[keycodeObject.code]) { + // Clone in a shallow manner the original keycodeObject object and + // override the name, title, and possibly other fields + return { ...keycodeObject, ...keycodeLUT[keycodeObject.code] }; + } else { + return keycodeObject; + } +} + +function generateKeycodes(osKeyboardLayout, isSteno) { + store.state.app.configuratorSettings.iso = !isANSI(); const keycodes = [ - ...(isIso ? keycodeLayout.ISO : keycodeLayout.ANSI), - ...keycodeLayout.normal, + ...(isANSI() + ? keycodePickerTabLayout.ANSI_ISO + : keycodePickerTabLayout.ISO_ANSI), + ...keycodePickerTabLayout.special, ...(isSteno ? steno : []) ]; - return keycodes; + if (!Object.keys(keymapExtras).includes(getOSKeyboardLayout())) { + console.log( + `${getOSKeyboardLayout()} is not a valid OS keyboard layout value!` + ); + return keycodes; + } + const { keycodeLUT } = keymapExtras[getOSKeyboardLayout()]; + return keycodes.map((keycodeObject) => + toLocaleKeycode(keycodeLUT, keycodeObject) + ); } const getters = { @@ -76,22 +118,22 @@ const mutations = { }, enableSteno(state) { state.steno = true; - state.keycodes = generateKeycodes(isISO(), state.steno); + state.keycodes = generateKeycodes(getOSKeyboardLayout(), state.steno); }, disableSteno(state) { state.steno = false; - state.keycodes = generateKeycodes(isISO(), state.steno); - }, - enableIso(state) { - state.keycodes = generateKeycodes(isISO(), state.steno); - if (state.active === 'ANSI') { - state.active = 'ISO/JIS'; - } + state.keycodes = generateKeycodes(getOSKeyboardLayout(), state.steno); }, - disableIso(state) { - state.keycodes = generateKeycodes(isISO(), state.steno); - if (state.active === 'ISO/JIS') { - state.active = 'ANSI'; + changeKeyLegends(state) { + state.keycodes = generateKeycodes(getOSKeyboardLayout(), state.steno); + if (isANSI()) { + if (state.active === 'ISO/JIS') { + state.active = 'ANSI'; + } + } else { + if (state.active === 'ANSI') { + state.active = 'ISO/JIS'; + } } }, setSearchFilter(state, newVal) {