i18n grails and jquery with different languages

0

I'm using the Language Internationalization (i18n) feature in a Grails project. Some of the tags are inserted directly into the .gsp files and another part is in the JS (Jquery / Bootstrap) scripts. These in the scripts need to use a third-party jquery lib. The Grails feature checks the system language. Therefore, if the system and the browser are configured with different languages, the site will display a portion of the texts in one language and the other part in the other language. To try to work around this problem, I tried to read the system language using jQuery, then compare with the browser language and match both, but apparently the command to check the system language does not work (tested in mac, win, android, in FF, Chrome, Safari)

var userLang = navigator.language || navigator.userLanguage;
var systemLang = navigator.systemLanguage;
console.log( userLang + " : " + systemLang );

So I need help to make languages the same, either by Jquery or by Grails. Would anyone know how to do this?

    
asked by anonymous 15.09.2017 / 17:01

1 answer

0

Well I do it the following way. In my layout I put the following tag in HEADER

<g:set var="lang" value="${session.'org.springframework.web.servlet.i18n.SessionLocaleResolver.LOCALE'}"/>

And in all my messages I put the following code.

<g:message code='CODIGO MSG' lang='${lang}'/>

This will automatically identify the user's language.

I keep and prefer to use the browser language.

In case you want, you can implement something for the user that informs the language of the user so that it is possible to customize the system.

    
19.03.2018 / 06:46