August 08, 2005

i18n calendars updated

i've updated the i18nCalendars CFCs to include the new coptic and ethiopic calendars added to icu4j 3.4. and that makes a total of nine calendars. i don't imagine having any use for either of these calendars right now but given the recent focus on africa and ethiopia in particular, you never know. if you're interested in using icu4j's new AcceptLanguage method, you'll need to wrapper it. this method makes use of an 'out-parameter' method to return a boolean as to whether the method used a fallback locale (ie. it couldn't find a suitable locale among the server's installed locales, so it returns a fallback locale instead). coldfusion won't pick up on that returned boolean array. below find some java code for this (it returns a structure with the selected locale and whether or not it was a fallback locale):
import java.util.*;
import com.ibm.icu.util.ULocale;

public class ULocaleAcceptLanguage {
/*   
   class:      ULocaleAcceptLanguage
   version:   15-jul-2005
   author:      Paul Hastings paul@sustainableGIS.com
   notes:      simple wrapper class for ICU4J acceptLanguage
*/

   public final static HashMap getULocale(String httpAcceptLanguage){
      HashMap results = new HashMap();
      boolean[] fallback = new boolean[1];
      ULocale thisLocale = ULocale.acceptLanguage(httpAcceptLanguage,fallback);
      Boolean fallB= new Boolean(fallback[0]);
      results.put("locale",thisLocale.toString());
      results.put("fallback",fallB.toString());
      return results;      
   }
   
}
compile this and drop it in your cfinstall classes dir. you can then make use of it:
<cfscript>
   aL=createObject("java","ULocaleAcceptLanguage");
   acceptLanguageStr="en-us,th;q=0.7,ar;q=0.3";
   uL=al.GetULocale(acceptLanguageStr);
</cfscript>

<cfdump var="#uL#">

0 Comments:

Post a Comment

<< Home