Re: Support for internationalization

Marc Palmer <[email protected]>
Newsgroups gmane.comp.java.webmacro.user
Organization AnyWare Ltd.
Message-ID <[email protected]>
Ankur G35 Saxena wrote:
> Hi I have not been getting myself upto date on the latest version of
> webmacro, last I downloaded the api was in march of 2004. Now I have a
> task at hand where in I have to support languages like chinese, french
> and many more...
> 
> How do i go about doing this? Anything special I have to do, some
> examples would be great. Also when I put text into the webmacro file
> from java, can I put any char(unicode for other languages) since I
> will picking these translated words from an XML file.

The usual approach in JSP-land seems to be creating a ResourceBundle 
instance per session (assuming the language can be set by the client) 
and accessing that in the page for all UI strings...

i.e. for "hello world":

<html>
<body>
<b>$UIResourceBundle.HELLOWORLD</b>
</body>
</html>

...I'm rust on ResourceBundle so it might not support get(Object). 
Anyway the upshot of this is that you just need your servlet (or WM 
template I suppose) to get the language from the HTTP headers if 
possible, and then load the correct strings into a Map or similar, and 
put that in the session.

Then in every page, in a common included header you can do:

#set $UIStrings = $Session.XXXXX

Where XXXX is where you get the stored Map from the session.

You could of course do this by creating Maps in a common WM template 
(using #bean) containing all your translations so you don't have to mess 
with other files / ResourceBundle loading schemes (never been a fan of 
that mechanism).

Then you could put those into maps by ISO language code... preferably 
trying to avoid it being done for every request (#macro / include as macro?)

$stringsByCountryCode.put( "en", $stringsEN);
$stringsByCountryCode.put( "fr", $stringsFR);
$stringsByCountryCode.put( "de", $stringsDE);

...and then in every page processing you get the strings you need by:

#set $UIStrings = $stringsByCountryCode.get($Session.XXXXX)

...and remember to check for null...

Cheers
-- 
Marc Palmer    [email protected]
			
Wangjammers - Java, J2ME and Web Consultants
   ~ http://www.wangjammers.org/



-------------------------------------------------------
This SF.Net email is sponsored by Oracle Space Sweepstakes
Want to be the first software developer in space?
Enter now for the Oracle Space Sweepstakes!
http://ads.osdn.com/?ad_id=7393&alloc_id=16281&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.