I'll take a look at this. RB is updated in 5.5 for another change I
did, so I would need to do a bit of merging.


On 9/5/06, Phillip Senn <[EMAIL PROTECTED]> wrote:
If I may be so bold...
This is how I rewrote over my lunch hour:

<cfcomponent displayname="resourceBundle" hint="Reads and parses resource
bundle per locale">
<cfset Variables.resourceBundle = StructNew()>

<cffunction name="Init" access="public" output="false"
returntype="components.resourceBundle" hint="I return the resource bundle">
   <cfargument name="FileName" required="Yes" type="string" hint="This must
be the path + filename UP to but NOT including the locale. We auto-add
.properties to the end.">
   <cfargument name="Locale" required="No" type="string" default="en_US">
   <cfset var l = StructNew()>
   <cfset var l.Buffer = "">
   <cfset var l.Element = "">
   <cfset l.Filename = arguments.Filename &
"_#arguments.Locale#.properties">
   <cfif NOT fileExists(l.Filename)>
      <cfthrow message="Fatal error: resource bundle #l.Filename# not
found.">
   </cfif>
   <cffile action="read" file="#l.Filename#" variable="l.Buffer"
charset="utf-8">
   <cfloop index="l.Element" list="#l.Buffer#" delimiters="#chr(10)#">
      <cfif len(trim(l.Element)) and left(l.Element,1) NEQ "##">
         <cfset Variables.resourceBundle[trim(listFirst(l.Element,"="))] =
trim(listRest(l.Element,"="))>
      </cfif>
   </cfloop>
   <cfreturn this>
</cffunction>

<cffunction name="getResource" access="public" output="false"
returntype="string" hint="Returns bundle.X, if it exists, and optionally
wraps it ** if debug mode.">
   <cfargument name="resource" type="string" required="true">
   <cfset var result = "">
   <cfif not structKeyExists(variables.resourceBundle, arguments.resource)>
      <cfset result = " (Unknown translation)">
   <CFELSE>
      <cfset result = variables.resourceBundle[arguments.resource]>
   </cfif>
   <cfif isDebugMode()>
      <cfset result = "*** #result# ***">
   </cfif>
   <cfreturn result>
</cffunction>
</cfcomponent>



You are subscribed to cfcdev. To unsubscribe, please follow the instructions at 
http://www.cfczone.org/listserv.cfm

CFCDev is supported by:
Katapult Media, Inc.
We are cool code geeks looking for fun projects to rock!
www.katapultmedia.com

An archive of the CFCDev list is available at 
www.mail-archive.com/[email protected]




--
===========================================================================
Raymond Camden, Vice President of Technology for roundpeg

Email    : [EMAIL PROTECTED]
Blog     : ray.camdenfamily.com
AOL IM   : cfjedimaster

Video game player? Have kids? Check out KidGamers.org


You are subscribed to cfcdev. To unsubscribe, please follow the instructions at 
http://www.cfczone.org/listserv.cfm

CFCDev is supported by:
Katapult Media, Inc.
We are cool code geeks looking for fun projects to rock!
www.katapultmedia.com

An archive of the CFCDev list is available at 
www.mail-archive.com/[email protected]

Reply via email to