Re: get the browser's language and session set up question
Re: get the browser's language and session set up question
- Subject: Re: get the browser's language and session set up question
- From: Dev WO <email@hidden>
- Date: Wed, 11 Feb 2004 10:27:34 +0100
Hi Tim,
Firstly, I'll have a look at HelloWorld code later today, but here's my
input:
I don't really need to set the character encoding, as I'm using UTF-8,
but instead I need to understand how WO deals with the localized
ressources (english.lproj, french.lproj, etc). So I could get the
browser/OS language then display the first page in this language (and a
way to come in with another language, by providing links on this page).
Then get the language parameter from the link the user clicked and have
his session in this language (no language rewrite after he clicks on
the first page).
I think I should look more closely to the example before saying
something wrong;)
I'll keep you posted later today... But I'm not sure my skills are
enough good to help you though.
> 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
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.