Internationalization Question

Sorry if this has been posted already, but I havn't seen any tutorials regarding it.

Is there any possible way to let the browser default the language that is displayed? I.e. If i add to the bundle japanese and the persons browser language preference is Japanese, to display the program in japanese by default without making the user select it.

To break it down:

1) User Logs in

2) Check the users language preferences

3) Set the projects text to the language to the preferred language

From what I've seen I have not discovered a way to do this. Any help would be appreciated.

[622 byte] By [r3cca] at [2007-11-26 9:50:04]
# 1

User's preferences, i think, are sent to the server by the browser using the HTTP headers.

Ref: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4

For example,

Accept-Language: da, en-gb;q=0.8, en;q=0.7

would mean: "I prefer Danish, but will accept British English and other types of English."

The header can be parsed to check for the preferred language and then application can set its locale...

KarthikR at 2007-7-7 1:00:14 > top of Java-index,Development Tools,Java Tools...
# 2
Well would I have to write my own parser for this or could Java Studio Creator do this for me to detect the preferred language?
r3cca at 2007-7-7 1:00:15 > top of Java-index,Development Tools,Java Tools...
# 3

I am not sure if creator provides this facility but i believe you can use the 'request' object to obtain this info:

http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletRequest.html#getLoca le()

public java.util.Locale getLocale()

Returns the preferred Locale that the client will accept content in, based on the Accept-Language header. If the client request doesn't provide an Accept-Language header, this method returns the default locale for the server.

Returns:

the preferred Locale for the client

KarthikR at 2007-7-7 1:00:15 > top of Java-index,Development Tools,Java Tools...
# 4

Ok I will try it thanks for the information.

I also have a few more questions, I figure it would be good to post here rather then a new topic since this is regarding internationalization.

Is there any way to internationalize images with text on them? I have a form set up and the labels change but I'm wondering if there is any way to change the image buttons to change as well.

The other question is, is there anyway to internationalize preset information? I.e. I connect a drop down list to populate it, is there anyway to change that text?

r3cca at 2007-7-7 1:00:15 > top of Java-index,Development Tools,Java Tools...
# 5

Regarding the first question:

> Is there any way to internationalize images with text on them?

One method is to save your localized images in a .jar, as, say, image-fr.gif for french and image.gif as default. Then you can reference the image file name from ResourceBundles for each locale. For example in MyResource.properties:

myImage = image.gif

and in MyResources_fr.properties:

myImage = image-fr.gif

Then reference the desired image by the key myImage and you will obtain the correct file name for each locale.

For the second question, you may want to follow the thread in:

http://forum.sun.com/jive/thread.jspa?forumID=123&threadID=103833

KarthikR at 2007-7-7 1:00:15 > top of Java-index,Development Tools,Java Tools...