You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Andrew Davidson <an...@santacruzintegration.com> on 2009/05/07 21:35:44 UTC
how to build an multi lingual website
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
Re: how to build an multi lingual website
Posted by Andre-John Mas <aj...@sympatico.ca>.
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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: how to build an multi lingual website
Posted by George Sexton <ge...@mhsoftware.com>.
Christopher Schultz wrote:
>
>> <%=rb.getString("Date")%> <INPUT TYPE=TEXT VALUE="05/27/2009">
>
> Heh, I hope you use a Locale-specific date format otherwise you'll
> confuse a lot of people. ;)
I think I have this down. You can check:
http://www.mhsoftware.com/caldemo/
and let me know...
--
George Sexton
MH Software, Inc.
Voice: +1 303 438 9585
URL: http://www.mhsoftware.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: how to build an multi lingual website
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
George,
On 5/11/2009 5:30 PM, George Sexton wrote:
> Another way of doing this is to use resource bundles. It's uglier in
> some ways, but better in other ways.
The OP said he was using mostly static content, so I think the
redirection based upon Accept-Language is a better strategy.
If you are using a dynamic web site, going with resource bundles is
definitely the way to go.
> <%=rb.getString("Date")%> <INPUT TYPE=TEXT VALUE="05/27/2009">
Heh, I hope you use a Locale-specific date format otherwise you'll
confuse a lot of people. ;)
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkoInA4ACgkQ9CaO5/Lv0PC25ACdEdUVVVxyFpvSx1Uc8fW9ThfO
HLAAni1nVSdyv7yFByN4PPSaXIL67VWQ
=fv49
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: how to build an multi lingual website
Posted by George Sexton <ge...@mhsoftware.com>.
Christopher Schultz wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Andrew,
>
> On 5/7/2009 3:35 PM, Andrew Davidson wrote:
>> 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
>>
Another way of doing this is to use resource bundles. It's uglier in
some ways, but better in other ways.
Create a captions.properties file for spanish:
Date=Term for Date in Spanish
and a captions_en.properties
Date=Date
Place the file in your WEB-INF/classes directory.
Now, add this code to your page:
Locale lc=request.getLocale();
ResourceBundle rb=ResourceBundle.getBundle("captions",lc);
Now, on your JSP page instead of
Date <INPUT TYPE=TEXT VALUE="05/27/2009">
you have
<%=rb.getString("Date")%> <INPUT TYPE=TEXT VALUE="05/27/2009">
The good part of this is that you end up with only one set of JSP pages.
The bad side is that you have to code your layout so it can deal with
variable size captions. Spanish captions are going to be some 20% longer
on average than English.
Additionally, if you're using images with text, you'll have to put
handling in.
--
George Sexton
MH Software, Inc.
Voice: +1 303 438 9585
URL: http://www.mhsoftware.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: how to build an multi lingual website
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Andrew,
On 5/7/2009 3:35 PM, Andrew Davidson wrote:
> 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.html
>
> I have not been able to find a similar discussion for how to configure
> Tomcat to get similar behavior
You can think about mod_* as a servlet in Tomcat that doesn't yet exist.
You can implement any capability you need to match something that Apache
httpd does with one of its modules.
> 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.[es]
That sounds like a decent idea.
Andre-John suggests using request.getLocale().getLanguage() to determine
where to go. I would recommend getting the raw Accept-Language header
information and checking that against the languages you support. You
don't want to blindly redirect to index.html.zh when you only have
index.html.en and index.html.es.
You may be able to leverage urlrewrite (http://tuckey.org/urlrewrite/)
to do your heavy-lifting. I think something like this would work:
<rule>
<!-- Attempt to find Spanish without an English preference over it -->
<condition name="Accept-Language"
value="(en){0}?.*es(_[A-Z][A-Z])?" />
<from>/index.html</from>
<!-- Don't try any more rules -->
<to last="true" type="redirect">/index.html.es</to>
</rule>
<!-- Default rule: go to English for everyone else -->
<rule>
<from>/index.html</from>
<to type="redirect">/index.html.en</to>
</rule>
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkoIlSMACgkQ9CaO5/Lv0PDqlwCdHP+bzdw6m4XMv05EnivZbtnk
7+gAn1Q4A4aOjCBjINhQQTUlApHUO4ND
=ammP
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org