• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Localization issue "toujours"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Localization issue "toujours"


  • Subject: Re: Localization issue "toujours"
  • From: Gilles MATHURIN <email@hidden>
  • Date: Fri, 4 Aug 2006 22:29:47 -0400

Hello again

I still have an issue with localizating an testApp (as this app must help me to master that subject ;-) it's a bit normal, isn't it ?)
Firstly let me say that i resolved the precedent issue by following Chuc advice and by removing the Dictionaries definition from the Session Constructor. I placed them outter.


So now when i test the app on Safari, it works great so that when i change the default language of my system, the WOApp display the corresponding localized Main Component. I added some print out in the code in order to control the differents variables as you can see below… So what's wrong will you say ?

Heck ! What's working in Safari don't work in Camino, and i didn't test in Firefox.

Here is what i got on Camino :

Application: LocalizationApp
Error: java.lang.IllegalArgumentException: Attempt to insert null into an com.webobjects.foundation.NSMutableArray.
Reason: Attempt to insert null into an com.webobjects.foundation.NSMutableArray.
Stack trace:
File Line# Method Package
NSMutableArray.java 211 addObject com.webobjects.foundation
Session.java 113 browserLanguages Session
Session.java 31 awake Session
WOSession.java 720 _awakeInContext com.webobjects.appserver
WOApplication.java 1762 _initializeSessionInContext com.webobjects.appserver
WOComponentRequestHandler.java 309 _dispatchWithPreparedApplication com.webobjects.appserver._private
WOComponentRequestHandler.java 358 _handleRequest com.webobjects.appserver._private
WOComponentRequestHandler.java 432 handleRequest com.webobjects.appserver._private
WOApplication.java 1306 dispatchRequest com.webobjects.appserver
WOWorkerThread.java 173 runOnce com.webobjects.appserver._private
WOWorkerThread.java 254 run com.webobjects.appserver._private
Thread.java 613 run java.lang
NA : Non applicable, JIT activated


Here is the quite bit simplified session.java code :

//
// Session.java
// Project LocalizationApp
//
//

import com.webobjects.foundation.*;
import com.webobjects.appserver.*;
import com.webobjects.eocontrol.*;

public class Session extends WOSession {

String codes[] = new String[] {"fr","us","de"};
String countries[] = new String[] {"FRANCE", "USA", "ALLEMAGNE"};
public NSDictionary countryCodeToCountryName = new NSDictionary (countries,codes);;

String lcodes[] = new String[] {"fr","en","de"};
String lnames[] = new String[] {"French", "English", "German"};
public NSDictionary languageCodeToLanguageName = new NSDictionary (lnames,lcodes);


    public Session() {
        super();

        /* ** Put your per-session initialization code here ** */

	}

	public void awake() {
		super.awake();
		this.setLanguages(browserLanguages());
	}

	protected String removeTail(String aString) {
		String aCleanedString = aString;
		int index = aString.indexOf(";");
		if (index> 0) {
			aCleanedString = aString.substring(0,index);
		}
		return aCleanedString.trim();
	}

	/** Return the browser prefs in a array */
	protected NSArray browserLanguagePreferences(String aBrowserString) {
		NSMutableArray aList = new NSMutableArray();
		if (aBrowserString != null) {
			int index = 0;
			String aBrowserCode = "";
			String remainderString = aBrowserString;
			while (remainderString.length() > 0) {
				index = remainderString.indexOf(",",index);
				if (index>0) {
					aBrowserCode = remainderString.substring(0,index);
					aList.addObject(removeTail(aBrowserCode));
					remainderString = remainderString.substring(index + 1);
				}
				else {
					aBrowserCode = remainderString;
					aList.addObject(removeTail(aBrowserCode));
					remainderString ="";
				}
			}
		} else { // Use the default
			aList.addObject("en-US");
		}
		return aList;
	}

	public static String languageCode(String aName) {
		// the string is in the form xx-YY
		String aCode = "";
		if (aName.length() > 2) {
			aCode = aName.substring(0,2).toLowerCase();
		} else if (aName.length() == 2) {
			aCode = aName.toLowerCase();
		} else {
			aCode = "zz"; // Unable to determine the country code
		}
		return aCode;
	}

protected NSArray browserLanguages() {
NSMutableArray browserLanguages = new NSMutableArray();
if (context().request() != null) {
// So many different way to specify the accepted languages !
// Each adaptor has their own…
String aHeader = context().request().headerForKey("accept-language");
// Visualisation du Header
System.out.println(aHeader + " header");

if ((aHeader == null) || aHeader.equals("")) {
aHeader = context().request().headerForKey("Accept-Language");
// Visualisation du Header
System.out.println(aHeader + " header");
}
else if ((aHeader == null) || aHeader.equals("")) {
aHeader = context().request().headerForKey("HTTP_ACCEPT_LANGUAGE");
// Visualisation du Header
System.out.println(aHeader + " header");
}
String aBrowserCode = "";

java.util.Enumeration anEnumaration = browserLanguagePreferences (aHeader).objectEnumerator();

while (anEnumaration.hasMoreElements()) {
aBrowserCode = (String)anEnumaration.nextElement();
System.out.println(aBrowserCode);

String languageName = (String) languageCodeToLanguageName.objectForKey(languageCode(aBrowserCode));
// Verification 2
System.out.println(languageName + "_verif2");

browserLanguages.addObject(languageName);
// Verification 3
System.out.println(browserLanguages + "_verif3");
}
}
// Verification 4
System.out.println(browserLanguages + "_verif4");
return browserLanguages;
}
}


When i built it, i have got that for the several "System.out.println" in the Run Log :

fr
French_verif2
("French")_verif3
("French")_verif4
Hello World
fr header
fr
French_verif2
("French")_verif3
("French")_verif4

Any clue to help me understand what's wrong with this code ?

Thanks.

Regards.

GM

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Localization issue (From: Gilles MATHURIN <email@hidden>)
 >Re: Localization issue (From: Chuck Hill <email@hidden>)
 >Re: Localization issue (From: "Jerry W. Walker" <email@hidden>)

  • Prev by Date: Re: Event update ; notice
  • Next by Date: Re: Event update ; notice
  • Previous by thread: Re: Localization issue
  • Next by thread: problem in passing parameters
  • Index(es):
    • Date
    • Thread