Check that ime was defined before selecting a language

Fixes a regression from I759c01f894569372d69d3b879e34aafda2ed41b1.

Change-Id: I5c3998b687fb92e3c90301edecb25b6a8306f423