Avoid exceptions by first checking language code validity

Bug: 49423
Change-Id: I3fd98ba08393856311a48fa40769027460c72ef9
Merge "Avoid exceptions by first checking language code validity"