i18n grails and jquery with different languages

Asked

Viewed 40 times

0

I’m using the language internationalization feature (i18n) in a Grails project. A portion of the tags are inserted directly into the files. gsp and another part is in the JS scripts (Jquery/Bootstrap). These that are in the scripts need to use a third-party jquery lib. The Grails feature checks the system language. Therefore, if the system and browser are configured with different languages, the site will display one part of the text in one language and the other part in the other language. To try to get around this problem, I tried reading 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 on 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 equal, either by Jquery or Grails. Someone would know how to do this?

  • In my opinion, do not use jquery to check what kind of language the browser is using... check the graisl documentation: http://guides.grails.org/grails_i18n/guide/index.html

1 answer

0

Well, I’ll do it this 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 place the following code.

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

This will automatically identify the user’s language.

I maintain and prefer to use the browser language.

If Voce wants to Voce can implement something for the user that informs the language of it so that it is possible to customize the system.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.