Switch between languages in Linux. Write in multiple languages with same keyboard.
How to set up multiple keyboard layouts from console.
Overview
A guide for polyglots to use Cyrillic letters, Chinese characters, Arabic, Latin letters and any other language in Linux, with the ability to easily switch between them in an X11 graphical environment or console.
There are several input methods that can be used, just a plain usage of xkb which just changes keyboard layouts or more complete methods which include spell checkers, character and word suggestions, and support for Asiatic scripts like ibus.
With ibus (preferred one)
IBus is an intelligent input bus for Linux/Unix. It can help with a fast switching between any language, spell checking and also including emoticons.
sudo apt install ibus-libpinyin ibus-table-emoji ibus-sunpinyin ibus-cangjie ibus-typing-booster ibus-zhuyin
Make Ubuntu use it
Make Ubuntu use ibus as the default input method by using the following command im-config and then choosing it from the list.
It will automatically create the $HOME/.xinputrc
file with that
information to be loaded at the next start up.
Unicode character and Emojis
Display character suggestions and emojis correctly: sudo apt install xfonts-unifont ttf-unifont fonts-noto-color-emoji
Note: sudo apt get install fonts-noto
can also be used but it takes
more than 700Mb of disk usage.
Spellchecking
For having the spellchecking and dictionary functionality it needs to have the hunspell dictionaries already installed.
sudo apt install hunspell-ru hunspell-en-us hunspell-es hunspell-pt-br hunspell-it hunspell-de-de hunspell-es hunspell-fr hunspell-ru hunspell-ar
Then when you select each language from the preferences windows, you will see that some has a tick in the spellchecking feature, those are the dictionaries which have been installed.
Text predictor
To see a list of word suggestions when typing a word, you need to first choose the language you want at the ibus selection window, and then choose ibus-typing-booster[^ibus-typing-booster] from the same window.
The predictor works on the previously selected language.
Setup
Set it up with ibus-setup. Configuration data will be saved
with dconf
.
dconf is a simple tool for manipulating a dconf
database
1
Migrate config
After adding languages and setting up
If you want to have the same ibus configuration between different
computers, you need to dump the configuration using dconf
and then
load it in the new computer.
To check the current configuration use dconf dump /desktop/ibus/:
<pre class="shell">
<samp>
<span class="shell-prompt">$</span> <kbd>dconf dump /desktop/ibus/</kbd>
general]
engines-order=['xkb:us::eng', 'libpinyin', 'xkb:latam::spa', 'xkb:br::por', 'xkb:ru::rus', 'xkb:fr::fra', 'typing-booster', 'xkb:ru:phonetic:rus', 'xkb:ara::ara', 'xkb:jp::jpn', 'xkb:de::ger', 'xkb:it::ita']
preload-engines=['xkb:us::eng', 'libpinyin', 'xkb:ara::ara', 'xkb:fr::fra', 'xkb:latam::spa', 'xkb:ru::rus', 'xkb:jp::jpn', 'xkb:de::ger', 'xkb:it::ita', 'xkb:ru:phonetic:rus', 'xkb:br::por', 'typing-booster']
use-global-engine=false
version='1.5.22'
[general/hotkey]
triggers=['<Control><Alt><Shift>space']
[panel]
custom-font='Sans 20'
show=2
use-custom-font=true
[panel/emoji]
favorites=['✋', '😁']
</samp>
</pre>
Then write it to a file with <dconf dump /desktop/ibus/ > ~/ibus-custom.cfg.
And in the new computer populate the subpath after copying the configuration file: <dconf load /desktop/ibus/ < ~/ibus-custom.cfg.
Now all the languages and custom shortcuts are available at the new computer, but we need to be sure to replicate the same packages in the new computer.
With xkb
The X11/Xorg server uses XKB, the X Keyboard Extension, to control the available keyboard layouts.
If we want to use many languages with the same keyboard, we will have to address four main topics: model, layout, variant and options.
To specify the different languages, we use the command setxkbmap
which sets
the keyboard using the X Keyboard Extension.
It is used like: setxkbmap [-model xkb_model] [-layout xkb_layout] [-variant xkb_variant] [-option xkb_options]
so the in each topic we
will see how to fulfill each parameter.
1. Current configuration
You can see your current configuration with setxkbmap -query or for further details setxkbmap -print -verbose 10 .
$ setxkbmap -query
rules: evdev
model: pc105
layout: us
In Debian/Ubuntu systems the default keyboard layout is described in
/etc/default/keyboard
2.
$ cat /etc/default/keyboard
KEYBOARD CONFIGURATION FILE
Consult the keyboard(5) manual page.
XKBMODEL="pc105"
XKBLAYOUT="us"
XKBVARIANT=""
XKBOPTIONS=""
BACKSPACE="guess"
At this stage we pay particular attention to the current “physical” keyboard model.
XkbModel selects the keyboard model. This has an influence only for some extra keys your keyboard might have. The safe fallback are pc104 or pc105. But for instance laptops usually have some extra keys, and sometimes you can make them work by simply setting a proper model.
2. Languages
Select which keyboard layouts are needed, i.e.: the languages you will use.
XkbLayout selects the keyboard layout. Multiple layouts may be specified in a comma-separated list, e.g. if you want to quickly switch between layouts.
For a complete list of keyboard layouts and its descriptions check
/usr/share/X11/xkb/rules/base.lst
.
The layout name is often the typical two letter country code. e.g.: for Russian: ru.
3. Variants
For each layout, a variant can be chosen.
XkbVariant selects a specific layout variant. For instance, the default sk variant is qwertz, but you can manually specify qwerty, etc.
The full list of variants can also be seen at
/usr/share/X11/xkb/rules/base.lst
.
For example you can choose:
For a Russian layout, a phonetic variant is available, which will make it writing Russian in a Latin/US keyboard very intuitive.
! variant ... phonetic_winkeys ru: Russian (phonetic, with Win keys) ...
And to see specifically the mappings it has, consult the proper layout file, e.g. for Russian (ru):
/usr/share/X11/xkb/symbols/ru
and locate thexkb_symbols "phonetic"
. It will have all the key mappings like:key <LatT> { [ Cyrillic_te, Cyrillic_TE ] };
where it specifies that theLatin T
key will be the Cyrillic version:т
.
The full list of variants available can be seen online at: https://manpages.ubuntu.com/manpages/disco/man7/xkeyboard-config.7.html
4. Switch between layouts
XkbOptions contains some extra options (comma-separated). Used for specifying layout switching, notification LED, compose mode etc.
To switch between the keyboard layouts we rely on the options
parameter of XKB
.
It already comes with a list of possible key combinations that will be
switching between all the specified layouts listed in /usr/share/X11/xkb/rules/base.lst
, starting with grp:
and
ending with toggle
.
$ grep "grp:.*toggle" /usr/share/X11/xkb/rules/base.lst
grp:toggle Right Alt
grp:lalt_toggle Left Alt
grp:caps_toggle Caps Lock
grp:shift_caps_toggle Shift+Caps Lock
grp:alt_caps_toggle Alt+Caps Lock
grp:shifts_toggle Both Shift together
grp:alts_toggle Both Alt together
grp:ctrls_toggle Both Ctrl together
grp:ctrl_shift_toggle Ctrl+Shift
grp:lctrl_lshift_toggle Left Ctrl+Left Shift
grp:rctrl_rshift_toggle Right Ctrl+Right Shift
grp:ctrl_alt_toggle Alt+Ctrl
grp:alt_shift_toggle Alt+Shift
grp:lalt_lshift_toggle Left Alt+Left Shift
grp:alt_space_toggle Alt+Space
grp:menu_toggle Menu
grp:lwin_toggle Left Win
grp:win_space_toggle Win+Space
grp:rwin_toggle Right Win
grp:lshift_toggle Left Shift
grp:rshift_toggle Right Shift
grp:lctrl_toggle Left Ctrl
grp:rctrl_toggle Right Ctrl
grp:sclk_toggle Scroll Lock
grp:lctrl_lwin_toggle Left Ctrl+Left Win
The full list of options available can be found online at: https://manpages.ubuntu.com/manpages/disco/man7/xkeyboard-config.7.html .
5. Testing
To test it works as desired, we specify the command and try to switch between layouts.
For example for English and Russian (phonetic) keyboards switching
with both CTRL
keys pressed at the same time: setxkbmap -model pc105 -layout us,ru -variant ,phonetic -option grp:ctrls_toggle
.
Then we press both CTRL and start typing in Русский.
6. Persisting Changes
setxkbmap
changes the layout for the current X session only.
To keep changes in the next reboot we can choose between:
- Manually changing the configuration files:
xinitrc
orxprofile
.
- Using the command
localectl
which automatically saves the new configuration.
6.1 Manual
Create the X11 configuration file
/etc/X11/xorg.conf.d/00-keyboard.conf
with the new data:
Section "InputClass"
Identifier "system-keyboard"
MatchIsKeyboard "on"
Option "XkbLayout" "us,ru"
Option "XkbModel" "pc105"
Option "XkbVariant" ",phonetic"
Option "XkbOptions" "grp:ctrls_toggle"
EndSection
6.2 Automatic
locatectl
automatically creates/updates the required configuration
file /etc/default/keyboard
(in Ubuntu) or
/etc/X11/xorg.conf.d/00-keyboard.conf
.
It is used like: $ localectl [--no-convert] set-x11-keymap layout [model [variant [options]]]
Following the above example:
$ localectl set-x11-keymap us,ru pc105 ,phonetic grp:ctrls_toggle $ cat /etc/default/keyboard XKBMODEL=pc105 XKBLAYOUT=us,ru XKBVARIANT=,phonetic XKBOPTIONS=grp:ctrls_toggle BACKSPACE=guess
7. Graphical indicator
Finally we add an X11 keyboard indicator and switcher.
gxkb is an utility that switchs the language selecting it from a menu, and shows an icon with the current active layout.
If you change the layout with the above combination key, gxkb
also
updates and show the current layout.
To install it in Debian/Ubuntu: sudo apt-get install gxkb.
Keyboards layout references
To generate any graphical representation of the keyboard layout, use
gkbd-keyboard-display -l "<language_code>
or xkbprint.
Examples:
- for English US version: gkbd-keyboard-display -l us
- for English US with
altgr-intl
variant: gkbd-keyboard-display -l “us(altgr-intl)"
/usr/share/X11/xkb/symbols/
Each letter on the keyboard can have up to 4 symbols associated. They
are defined in /usr/share/X11/xkb/symbols/
for each language in the
form of key <KEYCODE> { [ symbol1, symbol2, symbol3, symbol4 ] };
.
Each symbol can be accesed with:
- unmodified
<letter>
- press a letter without any other modificator
- shift
- press SHIFT +
<letter>
- access the upper left letter symbol definition
- press SHIFT +
- altgr
- press ALT gr +
<letter>
- access the bottom right letter symbol definition
- press ALT gr +
- shift+altgr
- press SHIFT + ALT gr +
<letter>
- access the upper left letter symbol definition
- press SHIFT + ALT gr +
altgr stands for Alt Graph and is the right alt key. “Is a modifier key used to type characters that are unusual for the locale of the keyboard layout”. 3
Example key layout and how to access each symbol:
SHIFT | SHIFT + ALT gr |
without modifiers | ALT gr |
Arab
Arab keyboard layout without variants.
Code: ar
.
Brazilian
Brazilian portuguese keyboard layout.
Code: br
.
English (US)
English US keyboard layout.
Code: us(altgr-intl)
.
French
French keyboard layout.
Code: fr
.
Italian
Italian keyboard layout.
Code: it
.
Russian
Russian keyboard main layout is called ЙЦУКЕН4, the keyboard with the most popular Cyrillic letters layout.
Code: ru
.
Russian phonetic
Russian phonetic variant layout lets you use a common US English layout (qwerty) but typing each letter phonetic equivalent in Cyrillic.
Code: ru(phonetic)
.
Spanish
Spanish keyboard layout.
Code: es
.
References
- https://github.com/ibus/ibus
- https://www.x.org/wiki/XKB/
- https://wiki.archlinux.org/index.php/Xorg/Keyboard_configuration
- To define custom keys: https://help.ubuntu.com/community/Custom%20keyboard%20layout%20definitions
- Find out IP addresses from MACs in a Local Area NetworkMay 10, 2023
- Choose any key as the modifier in i3wm in 6 stepsJanuary 20, 2021
- Adding a swap memory to Linux from command line in 6 stepsApril 2, 2020
- Free up space in Linux (Ubuntu)March 27, 2020
- Switch between languages in Linux. Write in multiple languages with same keyboard.
- How to make Ubuntu display emojisFebruary 12, 2020
- Detect and mount USB devices in Linux from consoleJanuary 24, 2019
- How to make screencasts in Ubuntu LinuxJanuary 21, 2019
- Using i3 window manager in LinuxJanuary 7, 2019
- Setting Up A Fresh Linux ServerAugust 25, 2018
- How To Download A Website With Wget The Right WayJune 30, 2017
- Replicate Installed Package Selections From One Ubuntu System To AnotherApril 24, 2017
- Using Clamav Antivirus In UbuntuJanuary 25, 2017
- How to Type Spanish Characters, Accents and Symbols in LinuxJune 6, 2016
Ubuntu
- How to activate tap to click touchpad's feature in Ubuntu in 4 stepsMarch 4, 2021
- Difference between suspend and hibernate in Ubuntu and how to execute them from command lineApril 12, 2020
- Solving Google Chrome's gpu-process error message in Ubuntu LinuxJanuary 7, 2019
- Solving Google Chrome's secret service operation error message in Ubuntu LinuxJanuary 7, 2019
- Start Emacs In Ubuntu The Right WayJune 10, 2017
Unix Shell
- Connect to a Bluetooth device from command line in Ubuntu LinuxJune 23, 2020
- Add Infolinks Script To An Existing Website From Console With Sed CommandApril 4, 2017
- How to change all files permissions to 644 and directories to 755January 10, 2017
- Shell Redirect Output And Errors To The Null Device In BashDecember 9, 2016
- Prevent Running Of Duplicate Cron JobsDecember 8, 2016
- Delete All Backup Files Recursively In BashNovember 28, 2016
- Bash Script to Find Out If MySQL Is Running Or NotNovember 9, 2016
Articles
Subcategories
Except as otherwise noted, the content of this page is licensed under CC BY-NC-ND 4.0 . Terms and Policy.
Powered by SimpleIT Hugo Theme
·