|
Automatic GWT Internationalization detection
|
|
|
 |
|
|
|
|
By mdamour1976 | Published on Friday January 04, 2008 | Categories: Internationalization
|
In any documentation I have seen to date, the language a GWT application will use is either based on the locale "query string" or "meta" tag in the HTML document. While this gives us the ability to switch locales by changing either of these, it is not automatically picked up without the user designating their preference.
I personally don't really like having the language in the query string, many times my URL's are heavily modified by Apache mod_rewrite and I'd rather not add extra things in there. So for me, the best bet is to use the "meta" tag. This is very easy to do, just add this into your HTML:
...
Now, the GWT application will use English by default, if the meta tag specified "locale=fr" then we'd be seeing French. The way to make this automatic and dynamic is to use something like JSP or PHP to dish out your pages and build the meta tag. If you currently have static HTML pages you could quickly create a JSP or PHP page out of it and only modify the meta section.
All modern web-browsers send to the server a list of preferred languages that the client would like to see content. I've seen this used for quite a few years. When I did not see this sort of thing being done with GWT, I came up with this idea.
In the JSP, figure out the users preferred language, this is incredibly simple:
I can switch my browser settings to English or French and the application automatically uses the correct language! If the language is not supported, then I get the default (English).
You can get more sophisticated by trying to use the "Accept-Language" header field and pick the locale best suited for the user. For example they might prefer French, then Spanish and then English, in that order. If we do not have French, then we'd want to "fall back" to Spanish according to their preference if we can, rather than go straight to English if we don't support their top choice.
|
Article: Automatic GWT Internationalization detection
Categories: Internationalization
Description: How to automatically make your GWT application use the desired language settings
Tags: gwt google webtoolkit internationalization i18n
Text: <html> <head> <meta name="gwt:property" content="locale=en"> </head>... <meta name="gwt:property" content="locale=<%=request.getlocale()%>"> in any documentation i have seen to date, the language a gwt application will use is either based on the locale "query string" or "meta" tag in the html document. while this gives us the ability to switch locales by changing either of these, it is not automatically picked up without the user designating their preference. in the jsp, figure out the users preferred language, this is incredibly simple:
i personally don't really like having the language in the query string, many times my url's are heavily modified by apache mod_rewrite and i'd rather not add extra things in there. so for me, the best bet is to use the "meta" tag. this is very easy to do, just add this into your html:
now, the gwt application will use english by default, if the meta tag specified "locale=fr" then we'd be seeing french. the way to make this automatic and dynamic is to use something like jsp or php to dish out your pages and build the meta tag. if you currently have static html pages you could quickly create a jsp or php page out of it and only modify the meta section. all modern web-browsers send to the server a list of preferred languages that the client would like to see content. i've seen this used for quite a few years. when i did not see this sort of thing being done with gwt, i came up with this idea. you can get more sophisticated by trying to use the "accept-language" header field and pick the locale best suited for the user. for example they might prefer french, then spanish and then english, in that order. if we do not have french, then we'd want to "fall back" to spanish according to their preference if we can, rather than go straight to english if we don't support their top choice. i can switch my browser settings to english or french and the application automatically uses the correct language! if the language is not supported, then i get the default (english).
Author: mdamour1976
Comments
- anonymous : If you are looking for the market leader in yard management software that provides real-time logistics information leveraging leading edge wireless, cloud software, and hardware technologies, you have found the right company.
We, at Exotrac, provide unprecedented real-time logistics to our clients. We provide the most advanced cloud-based, turn-key, cost-effective solution to help our clients gain an edge over their competition.
Real time, mobile based, cost effective solution! All at the tip of your fingers!!
Exotrac offers the following next-generation family of web based yard management solutions.
|
|
|