Hello Xavier,
I feel I am too new with WebObjects to answer your question,
especially on the development list. However I can share a little
with
you.
You wrote:
-I'd like to get the browser's language (or the OS language if
possible), that should load the entry page in the right language,
or
if there's no match, go to a default language (let say English).
-If the user clicks on the main link (the actual language), all
the
session would be in this language.
I can tell you that my investigation into the HelloWorld project
found
in
Developer/Examples/JavaWebObjects/HelloWorld
produces these two results you wrote of.
I can't tell you exactly how it is working but it is working
successfully with Traditional Chinese and English as i have tested
it.
The very first page is already determined to be Chinese (and not
English) if I simply set the language preference to be that (in
System
Preferernces - International control panel).
The following code is in Session.java of the HelloWorld project
import com.webobjects.foundation.*;
import com.webobjects.appserver.*;
import com.webobjects.eocontrol.*;
public class Session extends WOSession {
private NSMutableDictionary _supportedLanguages = null;
public Session() {
super();
/* ** Put your per-session initialization code here ** */
}
private String _browserCharacterEncoding = null;
public void setLanguages(NSArray aLanguageArray) {
if ((aLanguageArray == null) || (aLanguageArray.count() ==
0))
{
aLanguageArray = new NSArray("English");
}
String preferredLanguage =
(String)aLanguageArray.objectAtIndex(0);
if (preferredLanguage.equals("Japanese")) {
_browserCharacterEncoding = "SJIS";
} else if (preferredLanguage.equals("Chinese")) {
_browserCharacterEncoding = "Big5";
} else {
_browserCharacterEncoding = "ISO8859_1";
}
super.setLanguages(aLanguageArray);
}
public void takeValuesFromRequest(WORequest aRequest, WOContext
aContext) {
aRequest.setDefaultFormValueEncoding(_browserCharacterEncoding);
super.takeValuesFromRequest(aRequest, aContext);
}
public void appendToResponse(WOResponse aResponse, WOContext
aContext) {
aResponse.setContentEncoding(_browserCharacterEncoding);
super.appendToResponse(aResponse, aContext);
}
}
My reading is that aLanguageArray array for the session is going to
contain the browser Character Encoding in the variable
preferredLanguage.
That determines the specific language page to be sent.
The browser encoding information is set from the original WORequest
object before the session is set up and that each WO Response has a
call to super setting up the WOResponse object with the correct
encoding.
My confusion lies
1.) in the calls to super in this example and what effect it has -
how
does the "super.setLanguages(aLanguageArray)" method
2.) how does the WORequest information set up the information to
begin
with?
I can find no use of the line that reads:
private NSMutableDictionary _supportedLanguages = null;
I realise that last two methods are pulling info from the WORequest
(or into the WOResponse) that the browser has sent as part of the
http
request and then sets the correct encoding for a response but I
can't
understand how it gets the browser character encoding info from
that.
I am not so familiar with RFIC 2616.
If possible I would appreciate an explanation you can offer.
Regards,
Tim