First let me apologize for not replying during the conversation today.

I wanted to talk in a language that we all understand, so I wanted to rewrite it the way that I think is considered a "best practice" now.

However, if my boss knew that I was taking time to write code for an open source project instead of the current project that is behind schedule, he would have had my head.

So I had to wait until after 5:00 before I could reply.

 

I'm saying that the way I'm learning to do cfcs is instead of:

<cfset application.resourceBundle = createObject("component","org.hastings.locale.resourcebundle")>

do this:

<cfset application.resourceBundle = CreateObject("component","org.hastings.locale.resourcebundle").Init(theFile, application.blog.getProperty("locale"))>

 

 

and write the cfc this way:

<!---

This code is a modified version of the resourceBundle.cfc by Paul Hastings.

You can find the original code + examples here:

http://www.sustainablegis.com/unicode/resourceBundle/rb.cfm

--->

<cfcomponent displayname="resourceBundle" hint="Reads and parses resource bundle per locale">

<cffunction name="Init" access="public" output="false" returntype="components.resourceBundle" hint="I return the resource bundle">

   <cfargument name="rbFile" 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="rbLocale" required="No" type="string" default="en_US">

   <cfset var resourceBundleFile = "">

   <cfset var rbIndx = "">

   <cfset Variables.resourceBundle=structNew()>

   <cfset arguments.rbFile = arguments.rbFile & "_#arguments.rbLocale#.properties">

   <cfif NOT fileExists(arguments.rbFile)>

      <cfthrow message="Fatal error: resource bundle #arguments.rbFile# not found.">

   </cfif>

   <cffile action="" file="#arguments.rbFile#" variable="resourceBundleFile" charset="utf-8">

   <cfloop index="rbIndx" list="#resourceBundleFile#" delimiters="#chr(10)#">

      <cfif len(trim(rbIndx)) and left(rbIndx,1) NEQ "##">

         <cfset Variables.resourceBundle[trim(listFirst(rbIndx,"="))] = trim(listRest(rbIndx,"="))>

      </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 val = "">

   <cfif not isDefined("variables.resourceBundle")>

      <cfthrow message="Fatal error: resource bundle not loaded.">

   </cfif>

   <cfif not structKeyExists(variables.resourceBundle, arguments.resource)>

      <cfset val = "_UNKNOWNTRANSLATION_">

      <CFELSE>

      <cfset val = variables.resourceBundle[arguments.resource]>

   </cfif>

   <cfif isDebugMode()>

      <cfset val = "*** #val# ***">

   </cfif>

   <cfreturn val>

</cffunction>

</cfcomponent>

 

Having said all this, I want to convey to the group how humbled I was to see that the author was an active member of the group (what was I thinking?)!

Anyway Paul, just consider this a code review, and don't take it personal.

 

Besides, wait until I start questioning your variable naming convention!

 


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