GWT: How to dynamically set the browser locale

Hi,

After fighting a little with the GWT internacionalization I wanted to set the language automatically, avoiding the user the need of selecting it. I only have three cultures: en (default), es and fr. If the user comes from es or fr a script will change the <meta name=”gwt:property” content=”locale=en”> tag.

I have done it with js:


 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
 
 <script type="text/javascript">
 
 var lan="en";
  
 if(!jQuery.browser.msie)
 {
	 lan=window.navigator.language.split('-')[0];
 }
 else
 {
	 lan=window.navigator.userLanguage.split('-')[0];
 }

 if(lan == "fr"||lan == "es")
 	$("meta[name='gwt:property']").attr("content", "locale="+lan); 
 
 </script>

This is executed BEFORE the gwt javascript.

Regards.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: