If you’re a multi-language fanatic like myself, you want the ease of switching between languages in a variety of contexts. These include typing, spell-checking and interfacing with applications in your Linux system. Here I’ll mention a number of tips and shortcuts to facilitate the task.
The following X-keyboard-layout settings are specific to my setup, but I configured
- An international version of the US keyboard, which, with the Right-ALT modifier, provides international keys such as ñ, ß, ä, ü, áéíóú, for Spanish, German and some other compatible-language typing needs.
- Standard Polish and Portuguese keyboards.
- A phonetic QUERTY variant of the Russian keyboard, since my finesse with the traditional Cyrillic keyboard layout leaves much to be desired.
setxkbmap -model pc105 -layout us,pl,pt,ru -variant altgr-intl,,,phonetic setxkbmap -option "grp:shifts_toggle"
The second directive indicates the two Shift keys as the layout-switching mechanism.
To automatically invoke the above settings upon launching your X session, place the lines in
~/.xinitrc or your window manager auto start configuration.
I also recommend a status indicator for the current keyboard layout. In the Awesome window manager, I use the default provided keyboard layout widget:
mykeyboardlayout = awful.widget.keyboardlayout()
Since you may wish to interact with your applications in different languages, be sure to install all necessary locales:
- Uncomment the desired locales in
/etc/locale.conf, setting LANG to your preferred default locale.
- Alternatively, if you run a dpkg-based distro such as Debian, execute
to carry out the above changes.
I very much encourage setting your default locale to some secondary language for additional language exposure in a technical context. Then, assuming your application supports the respective locale, it will feature the appropriate translations. Otherwise, it will default to an available locale such as English.
What happens when you wish to temporarily invoke an application or the whole terminal session in a different locale from your default? Or you wish for one specific application to always execute in a different locale?
When I worked in an office environment, I always configured my system for a non-English locale such as Spanish or Portuguese, which, rarely, but occasionally, would create problems when someone needed to work with me on a problem at my laptop, and actually understand what I was doing.
To address this, I created a number of shell aliases in
~/.bashrc to manually prefix an application:
alias lang_en="LC_ALL=\"en_US.UTF-8\"" alias lang_pl="LC_ALL=\"pl_PL.UTF-8\"" alias lang_es="LC_ALL=\"es_ES.UTF-8\"" alias lang_pt="LC_ALL=\"pt_BR.UTF-8\""
To then temporarily invoke the shell in the English locale, I would execute
Or “lang_pl vim” to execute VIM in Polish, for example. You can also define a locale-specific alias for your app:
alias vim="lang_pl vim"
VIM spell checking
To configure multi-language spell checking in VIM, first download the respective language dictionaries at http://ftp.vim.org/vim/runtime/spell/ and place them in ~/.vim/spell. Download both the .spl and .sug files for the respective language when available.
To toggle the spell checker, execute “:setlocal spell!” in normal mode. Execute “:help spell” if unfamiliar with the VIM spellchecker.
To change the spell language, type “:setlocal spelllang=
To ease the above, I added two mappings to my ~/.vimrc:
map <F6> :setlocal spell!<CR> map <F7> :setlocal spelllang=
F6 toggles the spell checker, and F7 changes the spell language, leaving you to type just the two-letter language code.