Switch keyboard layouts with i3

You can do it with xkblayout-state and i3blocks

For xkblayout-state:

I assume you have git.

~$ git clone https://github.com/nonpop/xkblayout-state.git
~$ cd xkblayout-state
~$ make

Now copy compiled xkblayout-state somewhere in your PATH, for example:

~$ `cp xkblayout-state /usr/local/bin/`

Now for i3blocks:

sudo apt-get install i3blocks
cp /etc/i3blocks.conf ~/.i3blocks.conf

In your i3 config file (~/.config/i3/config) replace i3status with i3blocks,

# Start i3bar to display a workspace bar (plus the system information i3status
# finds out, if available)
bar {
        status_command i3blocks
        tray_output primary                                               
}
# in case of layout change event - send signal to i3blocks
bindsym ISO_Next_Group exec pkill -RTMIN+1 i3blocks

And restart i3wm (mod+shift+R), you should now see that i3blocks appeared.

Open your ~/.i3blocks.conf and add somewhere (for example, right above [VOLUME] section):

#Language indicator
[language]
#label=LNG
command=xkblayout-state print %s | awk '{print toupper($0)}'
interval=once
signal=1

Again, restart i3wm (mod+shift+R), and you should see your locales in status bar, switching.

Check out xkblayout-state --help, there is many options for different output.


Follow up to @aring's answer:

You can do it with xkblayout-state and i3blocks

Switching back and forth between two languages with xkblayout-state, put this in your ~/.config/i3/config file:

bindsym $mod+b exec xkblayout-state set $(( $(xkblayout-state print %c) ^ 1 ))