Hi Mihai,
Thanks for your review
I will explain you in one condition.
Let suppose we choose portuguese(pt-BR) as user language in Setting and  'en' as keyboard layout, then 

var lang = (userLanguage.indexOf(keyboardName) == 0) ? userLanguage : keyboardName; 

will give output as  'en'  which  cannot be accepted by latin.js
In that condition 
langAlias if defined,
langAlias[keyboardName] will convert the 'en'  to  'en-US'  which need to be passed to 
latin.js
Please check with this condition described above,
var lang = (userLanguage.indexOf(keyboardName) == 0) ? userLanguage : keyboardName; will not be sufficient then.