aspose file tools
The moose likes Struts and the fly likes i18n Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Frameworks » Struts
Reply Bookmark "i18n" Watch "i18n" New topic
Author

i18n

Jeff Born
Greenhorn

Joined: Sep 27, 2002
Posts: 23
I've been playing around with i18n and Struts and have gotten it to work via changing my Regional Settings and restarting Tomcat. However it is my understanding I should be able to update the Tools->Internet Options->Languages->Add... Add a Language and then move it up in priority. I've tested this out using Google and it works just fine. However I can't seem to get my struts application to work the same way. I've also looked at the struts tutorial on i18n and have had no luck with that example also. Is there anyone I can send a war files to that has worked with i18n and point out the error in my ways?
Thanks,
jb
Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 564
Hi Jeff,
the Locale is the important factor here:
struts will automatically generate the right Locale in the users' sessions, depending on what locale the browser specifies in its http request. Changing the internet explorer options or your windows OS options will affect that.
The default Locale that struts will generate if it finds nothing in the http request depends on the language settings of the machine running the appserver, presumably windows with tomcat in your case.
Now the important thing is that you program the response using the Locale generated by struts. The application resources strings (messages) should be taken care of automatically if you have ApplicationResources_DE.properties, ApplicationResources_SP.properties etc etc for each language.
With date, numeric & currency formats and so on you have to pass the Locale from the session to the Java functions.
Does that cover what you were attempting to do?
Adam


I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.
Jeff Born
Greenhorn

Joined: Sep 27, 2002
Posts: 23
Yes except what I have isn't working. I think I'm close because I can swith the locale via the regional settings and have spanish served.
Like you said though I shouldn't have to do this. I should be able select the language from IE.
Any ideas on where to look if changing the regional settings causes spanish to be served, but not changing the language vi IE?
PS I am using Tomcat 4.1 and Windows 2000.
Another question/request anyone have a war file they can send me that does i18n correctly that I can drop into the webapps directory in Tomcat and trace through how that works.
Thanks for the info,
jb
Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 564
I'm sorry but the wars I've got are all huge and have to have their database up and running. Have you tried looking at the examples that come with struts, or in their resources links?
I'm not clear what you are looking at when you say ".. causes spanish to be served ...". Do you mean you have got hold of the Locale from the session and do Locale.getCountry()? That should show whatever you have set your browser locale to. Struts picks it up automatically from the request.
Adam
Axel Janssen
Ranch Hand

Joined: Jan 08, 2001
Posts: 2164
I don't have yet practical knowledge in struts i18n.
Maybe it is cached in the session? What about trying to invalidate the session?
Axel
David Yutzy
tumbleweed and gunslinger
Ranch Hand

Joined: Jun 29, 2001
Posts: 192
We are currently working on a multi-lingual, Struts application for a major food chain.
The issues we've had implementing i18n were very problematic at first.
If you are just looking to display multi-lingual, static text, Struts is great and picks up Resource bundle and displays properly.
However, if you have forms and the user enters, say, French text, then how do you handle validation in a multi-lingual manner?
What about numbers entered as "2,00" versus "2.00", how do you do computations?
What we came up with was to extend the text tags within Struts to include a "key" attribute.
This key points to a resource bundle value like:
i18n.date={0,date}
i18n.number=(0,number}
i18n.currency={0,currency}
Using this method, your custom tag formats (according to the Struts locale) the information in the text box automatically.
To deal with posting multi-lingual data, we have a custom class that is called in the applicable "set" methods (of the form bean) to automatically convert the information, according to local.
Then in the "get" method (of form bean), the locale is once again applied to the values.
Using these processes, your code always deals with data in the same format whether in the Action, Form Bean, or other code.
Jeff Born
Greenhorn

Joined: Sep 27, 2002
Posts: 23
Been out of the office for a while, but finally figured out my problem. I'm no where near ready to try to input data from different locales, but will reference your reply when I get there.
My solution was adding the following line

to the top of the wrapper.jsp (in my case it is actually main.jsp)
I had added the first 2 lines to the included jsps without the html:html locale="true" tag. This just doesn't work. I finally added the top line to the wrapper file. This file always included the html:html locale="true" tag. I concluded (incorrectly) that This file didn't need the UTF-8 line just the files that actually use <bean:message>
Thanks for all the help guys!
jb
David Yutzy
tumbleweed and gunslinger
Ranch Hand

Joined: Jun 29, 2001
Posts: 192
One last thing to keep in mind...
The local="true" attrib. only effects struts "tags" that read from the resource bundle, NOT actual field values.
So your input field, dates, numbers, etc. will not be i18n using the locale="true".
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: i18n
 
Similar Threads
How to read property file
Extending RequestProcessor
i18n in a javascript page
Struts: The Complete Reference - Internationalizaion ???
Hide Module JSP pages under WEB-INF