Hi John,
It looks like you are trying to set a GSP variable with javascript, but that is not possible since the GSP is rendered server-side before it is served to the client as HTML and javascript. You can, however, just work with the 'lang' variable in javascript, storing it in localStorage, cookie, etc to persist it for the session.
On a side note, if you are doing internationalization work, I believe it is generally recommended to do a page refresh to re-render your page with the appropriate language. Here is a page from stackflow that gives a good description of why:
http://stackoverflow.com/questions/11676558/i18n-server-side-vs-client-side. If you choose to use a page refresh, you can change your <a href...> to a small form that posts back to the server and you can store the language in the session on the server.