A multi-language OS environment in Linux

2018-10-09 @Technology

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.

Keyboard-layout switcher

The following X-keyboard-layout settings are specific to my setup, but I configured

  1. An international version of the US keyboard, which, with the Right-ALT modifier, provides international keys such as ñ, ß, ä, ü, ö, áéíóú, àèìòù, êô, ç, ãõ, for Spanish, German, French, and Portuguese language typing needs.
  2. Standard Polish and Portuguese keyboards. (Some portuguese keys for the international keyboard can be a bit slow to generate.)
  3. 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()

More on the altgr-intl US-international keyboard (updated 2018-12-24)

I will explain how to actually output all of these international letters.

Forward-tilde vowels (á, é, …): hold the R-Alt followed by the vowel.

The spanish ñ: R-Alt + n

The spanish ¿: R-Alt + ?

The german ß, ä, ü, ö: R-alt + s/q/y/p

French, Portuguese backward-tilde vowels (à, è, …): R-alt + `, release, then the vowel.

French, Portuguese ç: R-alt + <

French, Portuguese ê, ô: R-alt + , release, then the vowel.

Portuguese ã, õ: R-alt + ~, release, then the vowel.

Application locales

Since you may wish to interact with your applications in different languages, be sure to install all necessary locales:

  1. Uncomment the desired locales in /etc/locale/gen
  2. Execute locale-gen
  3. Create /etc/locale.conf, setting LANG to your preferred default locale.
  4. Alternatively, if you run a dpkg-based distro such as Debian, execute
dpkg-reconfigure locales

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

lang_en bash

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=”, using the two-letter respective language code.

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.

Questions, comments? Connect.