Cache result of Language::isValidCode() to avoid regex processing

The function can be called over 2000 times in generating a page. This way
is significantly faster even for random invalid codes.  For real use it
should avoid the regex most of the time with no change in behavior.

Change-Id: I9fcbae1770be0d3f405d3d12254c11943b0d5f46