Move language related funcs to new 'lang.js'

Make it easier to navigate the code by splitting language-related
functions out into a new file 'lang.js'.