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 15:52:43 +0100
Thanks Pierre,
I remember reading this article some time ago, all my web pages have
the UTF-8 declaration inside the HTML code, WOBuilder is set to use
UTF-8 by default, and so for xCode.
So do I really need to overwrite something in the session.java, like
explained in the article:
----
You also need to overwrite Session.appendToResponse and set the
encoding to "UTF8"; before calling super, the same applies to
takeValuesFromRequest . You may also want to add a meta in the header
giving the encoding (I am not sure this is necessary with modern
browsers).
public void appendToResponse(WOResponse aResponse, WOContext
aContext) {
// set the encoding before anything is garbled
aResponse.setContentEncoding( _NSUtilities.UTF8StringEncoding );
super.appendToResponse(aResponse, aContext);
}
public void takeValuesFromRequest(WORequest aRequest, WOContext
aContext) {
aRequest.setDefaultFormValueEncoding(
_NSUtilities.UTF8StringEncoding );
super.takeValuesFromRequest(aRequest, aContext);
}
----
As long as there's the UTF-8 declaration inside the HTML code, the
browser should behave correctly, but I don't know how it works for
forms and/or user's input...?
Le 11 fivr. 04, ` 15:24, Pierre Frisch a icrit :
> Hi Xavier,
>
> Just one word of caution do not disregard the character encoding.
> There are a few things you need to do to make it work with all browser
> and if you don't do that you will repent. Have a look on www.wodev.com
> look for InternationalCharacters and there are quite a few tips.
>
> Pierre
> --
> Pierre Frisch
> sPearWay Ltd.
> sPearCat Web Catalogs, the flexibility of custom design, the price of
> a package.
> http://www.spearcat.com/
>
>
> On Feb 11, 2004, at 5:41, Dev WO wrote:
>
>> OK, so I've made some searching in the different examples provide
>> with the dev tools.
>> It appears that there's another small localization example in the
>> WOExample tour. This example appears to be closer to what I'm looking
>> for, as it doesn't deal with character encoding (which is useless
>> when using UTF-8), but only with browser language.
>> It looks like the example only check the language the first time
>> (because I can copy and paste the address in another browser and
>> still get the same language as the first one), or this is just a
>> caching issue...I have to investigate.
>> But as of now, I don't know how to allow the user to choose the
>> language on the first page...
>>
>> I'll investigate a little more...
>>
>>
>> Le 11 fivr. 04, ` 10:27, Dev WO a icrit :
>>
>>> 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.
>> _______________________________________________
>> 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.
_______________________________________________
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.