I was looking at a way for a GWT application to use the Browser's
language preference without having to either provide the parameter
(locale=fr) on the URL or to add the metatag for the locale in the
HTML.

The solution is quite easy to implement as long as the GWT application
is running within a Servlet container (e.g. Jetty, Tomcat).

The first step is to have the GWT application localized for the
language you want to use.  I will not explain how to do that since the
documentation of GWT is quite clear.

The second step is to create a JSP from the HTML, i.e. copy the HTML
as JSP.
For example: copy TestLocale.html to TestLocale.jsp

You add the following lines at top of the JSP:
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"
    import="java.util.Locale" %>

You add the following metatag within the head tag of the html
contained in the JSP
    <meta name="gwt:property" content="locale=<%=request.getLocale()
%>">

The third step is to replace html by jsp in the <welcome-file> tag
within web.xml:
For example:
  <welcome-file-list>
    <welcome-file>TestLocale.html</welcome-file>
  </welcome-file-list>
become
  <welcome-file-list>
    <welcome-file>TestLocale.jsp</welcome-file>
  </welcome-file-list>

The fourth step .. testing by replacing html by jsp in the URL.

I have an Eclipse project where I internalionalized (English and
French) the default GWT project created by the Eclipse plugin.  I
could share the project if required.

You are free to incorporate my humble contribution in the GWT
documentation unless there is something wrong with it, in which case I
would like to know what.

Regards,

Bernie1953

-- 
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to