Hi,

Le 18 nov. 2005, à 04:22, Johan Henselmans a écrit :
I am trying to get localized date formatting to work.

My first Idea was to use the browser accept-language to format the data, but I am already stuck before that:

How do I get the localized data format?

I tried this one, which should work according to the Class definition
NSTimestampFormatter dateTimeFormatter = new NSTimestampFormatter( "%A %e %B %Y", new Locale("DUTCH"));
                return dateTimeFormatter.format(perfDate());

That did not work, it could not resolve the symbol:
Trainingdata.java:45: cannot resolve symbol
symbol : constructor NSTimestampFormatter (java.lang.String,java.util.Locale)


You must perform something like this instead (code not compiled, written from memory):


    DateFormatSymbols dateFormatSymbols;
    Locale locale;
    timestampFormat NSTimestampFormartter;

    // "nl" is the ISO-639 symbol for Dutch
    locale = new Locale("nl");
    dateFormatSymbols = new DateFormatSymbols(locale);
timestampFormat = new NSTimestampFormartter("%A %e %B %Y", dateFormatSymbols);


If you want to get the proper Locale class for a particular language name string as found in Session object, you can perform a search with a Qualifier :

    NSArray locales, results;
    EOQualifier qualifier;
    Locale locale;

// Assuming "language" is an existing language string get from the session, like "Dutch" or "French" qualifier = EOKeyValueQualifier("getDisplayLanguage", EOQualifier.QualifierOperatorEqual, language);
    locales = new NSArray(Locale.getAvailableLocales());
results = EOQualifier.filteredArrayWithQualifier(locales, qualifier);

    if(results.count() == 1) {
            locale = (Locale)results.lastObject();
    }
    ...

While performing this filtering, default locale (i.e. Locale.getDefault()) _MUST_ be an english one, because the "getDisplayLanguage()" method return the language name for the default locale. If this is not the case, you'll have to find the locale using a loop:

    int index;
    Locale[] locales;
    Locale local;

    locale = null;
    locales = Locale.getAvailableLocales();
    for(index = locales.length; ((index-- > 0) && (locale == null)); ) {
if(locales[index].getDisplayLanguage(Locale.ENGLISH).equals(language)) {
                    locale = locales[index];
            }
    }


Then I tried the code from Chuck's book on localized Date Formatting:

java.text.SimpleDateFormat aFormat = new java.text.SimpleDateFormat("EEEE,d MMMM yyyy", new Locale("Dutch"));
                return aFormat.format(perfDate());

This one returns the english date format.

What is even more interesting: in Mozilla (set to Dutch Accept-Language, to compare)

the date format is: Wed 28 Dec 2005 20:30 uur:

In Safari the date format is: Wednesday,28 December 2005

Anyone that can shed light on this subject?

--
Francis Labrie
Saint-Bruno-de-Montarville, Québec, Canada

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to