In Ubuntu 12.04 I have two input languages installed, English and Russian. I would like to disable use of Russian language in terminal – so that regardless of system-wide selection, terminal will always have english input language.
Is that possible?
The problem is, accidentally typed non-english characters may introduce a lot of pain (especially invisible ones).
UPDATE:
First of all, I'd like to thank all the participants – I am really excited how quickly people try to help!
Looks like I have to more clearly state the problem. The problem is that not only I'd like to have English switched on by default when I create new terminal window or switch to old terminal window, I'd also like to make impossible switching the language from English to Russian inside the terminal window.
Now, the results.
I've tried gxneur – looks like one has to build it from the sources, which I am not ready to try. I tried to install it with apt-get and could not figure out how to easily configure it. And it did not show the icon in the taskbar. So I removed it.
I've tried Python script and it immediately stops with following output:
No such schema 'org.gnome.desktop.input-sources'
Traceback (most recent call last):
File "./set_language.py", line 63, in <module>
lang_list = read_prev()
File "./set_language.py", line 52, in read_prev
currlang = get_lang()
File "./set_language.py", line 24, in get_lang
curr_n = int(get(key[1]+key[0]+key[4]).strip().split()[-1])
File "./set_language.py", line 20, in get
return subprocess.check_output(["/bin/bash", "-c", cmd]).decode("utf-8")
File "/usr/lib/python3.2/subprocess.py", line 522, in check_output
raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['/bin/bash', '-c', 'gsettings get org.gnome.desktop.input-sources current']' returned non-zero exit status 1
Finally, I've tried the shell script, it runs, but does not seem to work – I still can easily switch to Russian in terminal. And it also once in a while says
No such schema 'org.gnome.desktop.input-sources'
So, all in all, I could not make any of the solutions work.
I guess the bottom line here is that what I'd like to get is not that simple, so it's ok to not have it.
Best Answer
Note on the answer below
The answer was originally written for 14.04, but rewritten January 6, 2017, to also work on (at least) 16.04 and 16.10.
wmctrl
is no longer needed.Script to automatically set a different language for a single application.
What it does
gnome-terminal
). Just run the script and, with the application in front, set the desired language.Notes
The script
How to use
The script uses
xdotool
:Copy the script above into an empty file, save it as
set_language.py
Test-run it by the command:
While running the script:
You can change both default language as the terminal language at any time. The set language(s) will be remembered.
If all works as expected, add it to Startup Applications: Add to Startup Applications: Dash > Startup Applications > Add. Add the command:
Explanation, the short (conceptual) story:
The script uses two files, to store the set languages for both the default language and the language, used in the exceptional application (
gnome-terminal
in this case, but you can set any application).The script then periodically (once per second) does two tests:
The script compares the situation with the test(s) one second ago. Then if:
there was a change in application:
exceptional --> default: read language file for default language & set language. If the file does not exist (jet), create it, store the current language as default.
default --> exceptional: the other way around.
If there was a change in language (but not in window class):
We may assume user set a different language for either the exceptional application or the default input language --> write the currently used input language into the according file (either for default language or the exceptional language).