1

I know that on many Desktop Environments, Using win + Space one can switch between installed language inputs.

Is there a command line way of achieving the same ?

Severus Tux
  • 9,866

2 Answers2

2

Don't worry, there is a quick solution.
Open a new terminal and execute localectl set-locale LOCALEVAR=LOCALE to impose a new locale. Before executing the command, replace "LOCALE" with the desired locale from the output of localectl list-locales and "LOCALEVAR" with any variable name from the output of locale.

If you want to change the keyboard input locale of the terminal use localectl set-keymap LANGNAME; if you want to change the keyboard input locale of the GUI use localectl set-x11-keymap LANGNAME. Replace "LANGNAME" with the short-name of your language.

Explanation: the console command localectl is used to change the system locale and keyboard layout settings.
The system locale if for the system services and the GUI; the keyboard settings control the keyboard layout used on the console and of the GUI.

  • 2
    Isn't this something different than emulating + from command line for changing the current input language? – Gunnar Hjalmarsson Sep 28 '16 at 17:27
  • @GunnarHjalmarsson this will change the system input locale (second part of the answer) or the system output locale (first part): all GUI and CLI applications will use the new locale if correctly configured. Note that the user who asked the question does not use a desktop environment, so this is a quick way to change the output/input language globally. – Lorenzo Ancora Sep 28 '16 at 18:56
  • Maybe you are right; this is new stuff to me. If I run localectl list-keymaps (in a terminal window on my desktop or in a TTY window) it returns "Couldn't find any console keymaps." setxkbmap OTOH changes the current layout in terminal/TTY instantly. – Gunnar Hjalmarsson Sep 28 '16 at 19:45
  • @Gunnar Hjalmarsson it happens because you did not install any keymap. :-) setxkbmap is valid only if the system uses the old X keyboard extension. localectl is more portable because it uses the native kbd driver and the change is immediate, but you need to correctly configure your Xorg server. – Lorenzo Ancora Sep 28 '16 at 22:58
  • 1
    Thanks for the lesson. :) As regards "valid only if the system uses the old X keyboard extension" - isn't that still standard in Ubuntu? Is it about to be changed? – Gunnar Hjalmarsson Sep 28 '16 at 23:42
  • @GunnarHjalmarsson you're welcome. :-) It is not a global standard (even if de facto is used by many desktop systems) and, because it is an extension, can be replaced easily in future versions of the X Server or with the advent of new system daemons. This should be a good thing to keep the system safe and allow the input from new devices. ;-) – Lorenzo Ancora Sep 29 '16 at 15:26
2

Trying to help by posting an own answer using the setxkbmap command.

To switch to English(US):

setxkbmap -layout us

To switch to Kannada:

setxkbmap -layout in -variant kan
Gunnar Hjalmarsson
  • 33,540
  • 3
  • 64
  • 94