January 08, 2004

cf resource bundle flavors

last week (02-jan-04) i droned on about the three types of resourceBundle (rb) methods that can be used in cfmx. this week i'd thought i'd flap my lips about the two flavors of resourceBundle files used with these three methods. let's deal with the simplest one first (for use with resourceBundleCFC). its nothing more than a utf-8 encoded text file of key/value pairs. something like the following: englishFive=5 thaiFive = ๕ (you will need a thai or unicode font to read this) these types of rb files can be easily created using notepad (yes notepad), dreamweaver, or any sort of text editor capable of producing utf-8 encoded files (unfortunately not cfstudio, in case you were wondering). as you can see, these are human readable. this flavor of rb files are easily and directly accessible by cf. the downside to all this goodness is that it can spiral out-of-control with large, complex rb files covering many locales (languages). the other rb flavor is based on java style rb files (because it makes use of java resourceBundle or PropertyResourceBundle classes) and similarly consists of key/value pairs in a text file but the "value" text is ASCII escaped unicode (\uXXXX where XXXX is the unicode code point expressed as a hexadecimal value). for instance: loatianFive=\u0ED5 bengaliFive=\u09EB thaiFive=\u0E55 the javaRB CFC can handle this type of rb file. creating these types of files is a bit more complicated (unless you are one of those very rare individuals who have the whole of the unicode in your head) and is usually handled by external tools such as the command line native2ascii supplied with normal java installs (in the bin dir) or the nifty rbManager tool from IBM. recent experience tells me that this might be a concept some folks will have trouble understanding so here's a snippet that actually builds and reads this flavor of rb file (its part of the guts of an rbManager cf clone i've been building off and on): <cfscript> // set up some constants thaiFive=chr(3669); tibetianFive=chr(3877); loatianFive=chr(3797); tamilFive=chr(3051); bengaliFive=chr(2539); arabicFive=chr(1637); malayamFive=chr(3432); // java objects prop=createObject("java","java.util.Properties"); fos = CreateObject("java", "java.io.FileOutputStream"); fis = CreateObject("java", "java.io.FileInputStream"); // resourceBundle rbFile=getDirectoryFromPath(expandpath("*.*")) & "test.properties"; // build test property file (as a basis for resourceBundle) fos.init(rbFile); prop.setProperty("thaiFive","#thaiFive#"); prop.setProperty("loatianFive","#loatianFive#"); prop.setProperty("tibetianFive","#tibetianFive#"); prop.setProperty("tamilFive","#tamilFive#"); prop.setProperty("bengaliFive","#bengaliFive#"); prop.setProperty("arabicFive","#arabicFive#"); prop.setProperty("malayamFive","#malayamFive#"); prop.store(fos,"test: brought to you by the number five"); fos.close(); // done close output file //get property file & dump keys fis.init(rbFile); prop.load(fis); fis.close(); // done close input file keys=prop.propertyNames(); writeoutput('<font face="Arial Unicode MS">'); while (keys.hasMoreElements()) { thisKEY=keys.nextElement(); thisMSG=prop.getProperty(thisKey); writeoutput("#thisKEY# = #thisMSG#<br>"); } writeoutput("</font>"); </cfscript> the rb file produced by this snippet would be something like (note that its a bunch of locales jumbled together, absolutely NOT what you'd do in production but you get the idea) : #test: brought to you by the number five #Thu Jan 01 19:04:53 GMT+07:00 2004 malayamFive=\u0D68 loatianFive=\u0ED5 bengaliFive=\u09EB thaiFive=\u0E55 arabicFive=\u0665 tibetianFive=\u0F25 tamilFive=\u0BEB output would be something along these lines (again you'll need some unicode capable font to properly read these): malayamFive = ൨ loatianFive = ໕ thaiFive = ๕ bengaliFive = ৫ arabicFive = ٥ tibetianFive = ༥ tamilFive = ௫ so now you know.

0 Comments:

Post a Comment

<< Home