il8n-ized web pages

Hello. I now understand the basic aspects of Localization and the use of Resource Bundles but there are always some things that I cannot understand. I think that this is a fairly simple question for me to ask the people here.

I can't seem to picture the execution of getting the right Resource Bundles. I have read that when using bundles, you have the option of explicitly telling the program what Locale to use. What I'm trying(very hard) to figure out is how does a web page know what Locale to use. I'm not sure if I'm making any sense here. I think I'll just give a scenario.

Here it goes...

Let's say I have a web application that I need to il8n-ize. Well.. maybe just one language... The two resource bundle classes are located on the web server and uses a database to get the translations. How does the web page tell the server what resource bundle it needs?

[897 byte] By [1549845821a] at [2007-10-2 4:33:48]
# 1

I think it could work this way:

- if you use applet then java applet runtime asks client side operating system for system locale and uses it;

- if you use server side application then IP of incomming connection can be used to find out in which country computer which loads page is located. I also suspect that HTTP protocol allows server to ask browser about preferred language since I'm able to set up language preferences in Mozilla :)

sztejkata at 2007-7-16 0:05:31 > top of Java-index,Desktop,I18N...
# 2

So is it kind of automatic on when you browse the page? I just kind of need to make the page call the locale.getDefault() method and pass it as argument when getting the resource bundle (getBundle("blah", thatLocale))?

Uhmm... was I right? or even close to being right?

Thanks.

Romaine (I don't know why my name appears as numbers on my browser)

1549845821a at 2007-7-16 0:05:31 > top of Java-index,Desktop,I18N...
# 3

No, it is not automatic. In the scenario you describe (browser client, server side execution) you need to specifically query the client for the locale. One way of doing that is to use the Accept-Language information that the browser sends in the HTTP header, but that is a very hit-and-miss method - in many cases you get only a language, no country/region info, and there is no guarantee that the browser language correpsonds to the user's preferred locale in the context of your application. So the browser info should not be used as the primary source of info, rather as a fallback. E.g., the first time a user connects you may use the browser info to display the pages in that language (if you have not other way of making assumptions about the user's preferences), but you should then offer the user the option of selecting a locale. You can then save that information in a cookie and pass that information to the server for the session (and even for future sessions).

Also, in your original post you mention getting the resourcebundles from a database - that would be an additional step that is not covered by the default getBundle methods.

For an application that is installed and executed on a client system the situation is of course much easier, there you can simply query for the default locale and use that.

one_danea at 2007-7-16 0:05:31 > top of Java-index,Desktop,I18N...
# 4

quote: one_dane

but you should then offer the user the option of selecting a locale. You can then save that information in a cookie and pass that information to the server for the session (and even for future sessions).

Oh! I understand that!

Also, in your original post you mention getting the resourcebundles from a database - that would be an additional step that is not covered by the default getBundle methods.

Hm.. yes. That must have been in a different thread. So was I right about extending the ListResourceBundle class and overriding its getBundle() method making the class get its contents from a database? I've seen other threads here abou it but it doesn't seem to clearly explain it.

Thank you very much for your reply. I know there's still some questions lingering at the back of my head, just can't remember what.

Romaine

1549845821a at 2007-7-16 0:05:31 > top of Java-index,Desktop,I18N...
# 5

I remember!! How is the execution of getting the Resource Bundle?

is it kind of like(its what I assessed from your reply):

1. client(browser) opens the web page...

2. the client sends his Locale to the server...

3. Here is the part I don't know. How does the server send the ResourceBundle containing the info back to the client? ObjectOutputStream? I've been reading that Struts can do this but I don't know Struts yet.

4. browser opens the bundle?

5. Fills in whatever needs to be filled in.

6. Voila! A page in a different language!

quote: one_dane from another thread

http://forum.java.sun.com/thread.jspa?threadID=543805&tstart=0

I would suggest that you read the documentation for the relevant APIs and the tutorials/FAQs that can be found with a simple search on the Sun Java site. They provide very clear information about the hierarchy used for loading .class and .properties files.

Thanks. But I was only a bit confused about that then.

1549845821a at 2007-7-16 0:05:31 > top of Java-index,Desktop,I18N...
# 6
*bump*one_dane where are you?
1549845821a at 2007-7-16 0:05:31 > top of Java-index,Desktop,I18N...
# 7

For some reason I have not been getting notifications recently about forum updates.

Anyway, I am not sure how your web application is implemented, and the exact process to some extent depends on that. Here's a good article on JSPs:

http://java.sun.com/developer/technicalArticles/Intl/MultilingualJSP/index.html

And the Sun J2EE Design guid shows in detail, with code examples, how to use ResourceBundles:

http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/i18n/i18n3.html#1083286

one_danea at 2007-7-16 0:05:31 > top of Java-index,Desktop,I18N...