You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Arieh Markel <Ar...@Central.Sun.COM> on 2000/06/16 20:00:53 UTC

Localization and DefaultServlet

I am about to tackle the issue of locating localized versions of
web-resources (html files, images, etc).

Perhaps the topic has been already discussed. If so, apologies.

I would like to get input as far as the applicability of the proposal
I am about to make.

So here it is:

. modify DefaultServlet to operate in a manner similar to 
  ResourceBundle.getBundle (resource, Locale)
  
  so that when a document path is looked up, the Locale is factored in
  the calculation of the real path to the resource
  
  example:
  
  	request:		http://bar.com/resource.html
  	requestLocale:		en_US
	defaultserverLocale:  	fr_FR
	
	DocumentRoot:		/dir/docRoot/
	
   DefaultServlet would try to locate the resource.html file in an
   appropriately localized subdirectory off DocumentRoot in the following
   order:
   
   	1. /dir/docRoot/en_US/resource.html
   	2. /dir/docRoot/en/resource.html
   	3. /dir/docRoot/fr_FR/resource.html
   	4. /dir/docRoot/fr/resource.html
   	5. /dir/docRoot/resource.html
   	
The advantage of the approach is that the hypertext links (HREF in the 
documents) request no localization. 

A disadvantage is that there is more work to do for every request.
Also, that there is valid direct access to the localized resource.

Another disadvantage is that it forces to lay out the files in a specific 
manner.

(I would add that it would have been possible to include the 'locale' string
as part of the basename of the file - i.e. /dir/docRoot/resource_en_US.html,
however, the manipulation of the concatenated strings makes it more
complicated in my opinion).


----

I understand that I could implement the same within our code, by extending
DefaultServlet and refer to it on the web.xml for the application.

----

So, I would like to hear some opinions about the solution, whether it is 
worthwhile resolving for the general case, or whether I just need to
implement it within our own application.

Thanks.

Arieh
--
 Arieh Markel		                Sun Microsystems Inc.
 Network Storage                        500 Eldorado Blvd. MS UBRM11-194
 e-mail: arieh.markel@sun.COM           Broomfield, CO 80021
 Let's go Panthers !!!!                 Phone: (303) 272-8547 x78547
 (e-mail me with subject SEND PUBLIC KEY to get public key)


Re: Localization and DefaultServlet

Posted by Juan Jose Pablos <jj...@bton.ac.uk>.
Hi Arieh,
I think that you should not use the directory as the way to find the
resource, if you use LocalStrings_<Locale>.properties in the servlet, using
a diferent mapping does not seems right. I mean you know if you use
ResourceBundle.getBundle (resource, Locale), it tires to get it from a
properties file like LocalStrings_<Locale>.properties, so same mapping to
get resources make them easier to remember and understant.

Another thing, For deep path /a/b/c/d, how are you going to search the right
localized
resource  /a/b/c/d/en or /en/a/b/c/d, its seems more expensive than the
other solution isn't it?
if you add the locale information on the name of file
name_<locale>.extension  that information is keep if the file is move to
another directory, if you move <locale>/myfile to /, how do you know the
localize information now?

It is just a few thoughts from a Junior in a chat of experts...


Juan



----- Original Message -----
From: "Arieh Markel" <Ar...@Central.Sun.COM>
To: <to...@jakarta.apache.org>
Sent: Friday, June 16, 2000 7:00 PM
Subject: Localization and DefaultServlet


> So here it is:
>
> . modify DefaultServlet to operate in a manner similar to
>   ResourceBundle.getBundle (resource, Locale)
>
>   so that when a document path is looked up, the Locale is factored in
>   the calculation of the real path to the resource
>
>   example:
>
>   request: http://bar.com/resource.html
>   requestLocale: en_US
> defaultserverLocale:  fr_FR
>
> DocumentRoot: /dir/docRoot/
>
>    DefaultServlet would try to locate the resource.html file in an
>    appropriately localized subdirectory off DocumentRoot in the following
>    order:
>
>    1. /dir/docRoot/en_US/resource.html
>    2. /dir/docRoot/en/resource.html
>    3. /dir/docRoot/fr_FR/resource.html
>    4. /dir/docRoot/fr/resource.html
>    5. /dir/docRoot/resource.html
>
> The advantage of the approach is that the hypertext links (HREF in the
> documents) request no localization.
>
> A disadvantage is that there is more work to do for every request.
> Also, that there is valid direct access to the localized resource.
>
> Another disadvantage is that it forces to lay out the files in a specific
> manner.
>
> (I would add that it would have been possible to include the 'locale'
string
> as part of the basename of the file - i.e.
/dir/docRoot/resource_en_US.html,
> however, the manipulation of the concatenated strings makes it more
> complicated in my opinion).
>