If Apache is handling your static content, and you are simply using Tomcat to serve dynamic content, then you can use the request.getLocale() method to find out what language the visitors browser is suggesting. For example:

   String lang = request.getLocale().getLanguage();
   if ( "es".equals(lang) ) {
      ....
   }
   else {
      ...
   }

How to get Tomcat to mimic Apache HTTPD's approach of serving static HTML pages in the right language, I am not sure. The only approach I can think
of is to group all language content together in the same sub folder, for
example:

  /en/...
  /es/...
  /fr/...

and then using relative paths. Using the above approach (ignoring language
variations), you could do:

   String lang = request.getLocale().getLanguage();
   ServletContext context = getServletConfig().getServletContext();
   if ( (new File(context.getRealPath("/" + lang)).exists() ) {
       response.sendRedirect("/" + lang);
   }
   else {
      response.sendRedirect("/en/");
   }

This assumes index.jsp within the language folder.

As a commentary on my part: if you expect to support more than European
languages, then it is worthwhile standardising on UTF-8 for content
encoding.


On 7-May-2009, at 15:35, Andrew Davidson wrote:

Hi



I do you know how I can build a multi lingual website? My main website is in English. I want to have a landing page in Spanish that describes my website and invites the user to click through the English version of the web site. Any idea how I set this up using Tomcat? The bulk of our web site is static
html pages.



Some one sent me a link about how to do this using the Apache web server so
that it check the Accept-Language of the http header

http://developers.sun.com/dev/gadc/technicalpublications/articles/apache.htm
l



I have not been able to find a similar discussion for how to configure
Tomcat to get similar behavior



Do I have to replace index.html with a servlet that checks the value of Accept-Language and generates a redirect to something like index.html.en or
index.html.en



Thanks



Andy



p.s. I am using Tomcat 5.5.x





 _____

Music Trainer makes it easy to learn new songs by slowing down or speeding
up play back without changing the pitch!



Learn more at www.SantaCruzIntegration.com





---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to