Hey guys,
The company I work for has a ColdFusion function that's being stored in the
application scope.
This function is used to pull translated text which changes based off of the
users current country that they selected. An issue we've been having however
is that on occasions we will run into instances where the translator
function will output the wrong string. For instance I've seen instances
where pages got all messed up because we had some alt text that was being
translated using this component and instead it outputted whole paragraphs
from some other random location on the site.
This only occurs maybe, once a month. Usually someone will call my
department and complain because text is inaccurate, I ask them to reload the
page and it goes away.
Do you think this could have anything to do with the fact that this function
is being stored in the application scope?
Code Example
<!--- Start Application.cfm --->
<cfset
application.translator=createObject("component",'packages.translator.transla
tor')>
<!--- End Application.cfm --->
<!--- Start function --->
<cffunction
access="public"
name="lookup"
returntype="string"
output="no"
hint="Returns the text found for the given language and
placeholder">
<cfargument name="placeholder" type="string"
required="yes">
<cfargument name="language" type="string"
required="yes">
<cfset var tempText = "">
<!--- Attempt to short-circuit the whole translation-in-memory
thing, and just do a lookup TVR 1/19/2008 --->
<cfquery name="getTranslation" datasource="mainDNS">
SELECT * FROM translations
WHERE lang = <cfqueryparam CFSQLType="STRING"
value="#language#">
AND placeholder = <cfqueryparam CFSQLType="STRING"
value="#placeholder#">
</cfquery>
<!--- If nothing found, and not already looking for English, check
English --->
<cfif (getTranslation.recordCount EQ 0) AND (language NEQ 'EN') >
<cfquery name="getTranslation" datasource="mainDNS">
SELECT * FROM translations
WHERE lang = 'EN'
AND placeholder = <cfqueryparam CFSQLType="STRING"
value="#placeholder#">
</cfquery>
</cfif>
<cfif getTranslation.recordCount NEQ 0 >
<!--- Replace any variables in the text, marked by <% %>,
with values passed to the function as var1, var2, etc. --->
<cfset tempText = getTranslation.content>
<cfloop collection="#arguments#" item="varName">
<cfif ucase(left(varName, 3)) eq "VAR">
<cfset tempText = replaceNoCase(tempText, "<% #varName#
%>", arguments[varName])>
</cfif>
</cfloop>
</cfif>
<cfreturn temptext>
</cffunction>
<!--- End function --->
<!--- Start Usage --->
<cfoutput>
#application.translator.lookup(placeholder="testtext.69EE0E03",language=requ
est.current_lang)#
</cfoutput>
<!--- End Usage --->
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Want to reach the ColdFusion community with something they want? Let them know
on the House of Fusion mailing lists
Archive:
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:323598
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4