kbdf is a simple python script to translate text that was typed accidentally in wrong keyboard layout.
For now its only support Russian and English keyboard layouts
kbdf supports Python3 on Linux and Windows.
You can install it using pip:
pip install git+https://github.com/alexantoshuk/kbdf
Or manually download kbdf.pyw and make it executable:
cmod +x kbdf.pyw
...and install python dependencies:
pip install pynput
pip install pyperclip
Install xclip
with your package manager on Xorg or wl-clipboard
on Wayland.
On Linux: just bind it to some hotkey.
On Windows: you can use AutoHotkey and put caps.ahk and kbdf.ahk to autostart.
kbdf.pyw
- translate last typed line, or selection if exists
kbdf.pyw selection
- translate selected text only
Simple!
- Backup current clipboard content.
- Emit ctrl+insert to copy selection to clipboard.
- If selection is not empty, go to (6).
- Emit shift+home for line selection (if not in 'selection' mode).
- Emit ctrl+insert to copy selection to clipboard.
- Get clipboard content and translate text word by word.
- Write translated text to clipboard.
- Emit shift+insert to replace selection with clipboard content.
- Restore clipboard content from backup.
- For now it can switch only between Russian and English keyboard layouts.
- It doesn't work in the terminal (except if terminal support to select line by shift+home and copy/paste by ctrl+insert shift+insert).
- Undefined behavior when bind this script to hotkeys with super and some other modifiers. I am just bind it to F12.
The alternatives is much more functional. But goal of this project is simplicity, stability, work on Linux (Xorg and Wayland) and Windows. And in my opinion, automatic switching creates more problems than it solves, so in kbdf there is no such possibility.