diff options
author | Andrew Dolgov <[email protected]> | 2019-12-11 07:52:49 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2019-12-11 07:52:49 +0300 |
commit | 4b92138d6b4072bcd80c00a02312a06add205280 (patch) | |
tree | 936391ec9bc9402000e4a50ef5ed23daf7924d30 |
initial
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | init.php | 53 |
2 files changed, 54 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..4cdee7d --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +git checkout to ``(plugins.local)/hotkeys_ru`` diff --git a/init.php b/init.php new file mode 100644 index 0000000..63db6e1 --- /dev/null +++ b/init.php @@ -0,0 +1,53 @@ +<?php +class Hotkeys_Ru extends Plugin { + private $host; + + function about() { + return array(1.0, + "Mirrors English hotkey map into Russian keyboard layout", + "fox"); + } + + function init($host) { + $this->host = $host; + + $host->add_hook($host::HOOK_HOTKEY_MAP, $this); + } + + private function mb_strtr($str, $from, $to) { + $keys = []; + $values = []; + + if (!is_array($from)) { + preg_match_all('/./u', $from, $keys); + preg_match_all('/./u', $to, $values); + $mapping = array_combine($keys[0], $values[0]); + } else { + $mapping = $from; + } + return strtr($str, $mapping); + } + + function hook_hotkey_map($hotkeys) { + + $local_map = []; + + foreach ($hotkeys as $k => $v) { + + if (strpos($k, "(") === FALSE) { + $local_k = $this->mb_strtr($k, "`~!@#$%^&qwertyuiop[]asdfghjkl;'zxcvbnm,./QWERTYUIOP{}ASDFGHJKL:\"|ZXCVBNM<>?", + "ёЁ!\"№;%:?йцукенгшщзхъфывапролджэячсмитьбю.ЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭ/ЯЧСМИТЬБЮ,"); + + if ($local_k != $k) + $local_map[$local_k] = $v; + } + } + + return array_merge($hotkeys, $local_map); + } + + function api_version() { + return 2; + } + +} |