This object is defined to convert the keyboard layout to user langauge in above condition I mentioned.
in which 
var lang = (userLanguage.indexOf(keyboardName) == 0) ? userLanguage : keyboardName; 
fails.