3

How can I write the equivalent for

<cfset lang = Evaluate("SERVER.Locale.#LocaleName#.#SESSION.Locale#")>

without using Evaluate.

I tried something like

<cfset lang = SERVER[Locale][#LocaleName#][#SESSION.Locale#]>

after referring this, but it was not working.

UPDATE

<cfset localename = "test">
<cfset session.locale = "en">
<cfif Not IsDefined("SERVER.LOCALE")>
    <cfset SERVER.Locale = StructNew()>
</cfif>

<cfif IsDefined("SERVER.Locale.#LocaleName#")>
    <cfset StructDelete(SERVER.Locale, "#LocaleName#")>
</cfif>
<cfset "SERVER.Locale.#LocaleName#" = StructNew()>
<!---<cfset lang = Evaluate("SERVER.Locale.#LocaleName#.#SESSION.Locale#")>--->
<!---<cfset lang = SERVER["Locale.#LocaleName#.#SESSION.Locale#"]>--->
<cfset lang = SERVER.Locale[LocaleName][SESSION.Locale]>
<cfoutput>#lang#</cfoutput>

ERROR:

Element en is undefined in a CFML structure referenced as part of an expression.

Community
  • 1
  • 1
Rino Raj
  • 6,264
  • 2
  • 27
  • 42

1 Answers1

11

This:

<cfset lang = Evaluate("SERVER.Locale.#LocaleName#.#SESSION.Locale#")>

Should be revised to this:

<cfset lang = SERVER.Locale[LocaleName][SESSION.Locale]>

You should not have the [Locale] in square brackets like that.

I think the error message (which you should always post with your question) probably actually explains that to you, dunnit?

Adam Cameron
  • 29,677
  • 4
  • 37
  • 78
  • 1
    Adam - he could use square brackets around it if (as Matt said in his comment) he put quotes around it. That is likely the error he was getting (cannot find "locale" as member of the struct "server" or something similar). – Mark A Kruger Nov 25 '15 at 16:33
  • @Adam I have updated the question and tried the code which you gave in http://cflive.net/ . I got n error. – Rino Raj Nov 25 '15 at 17:25
  • Yes @MarkAKruger but I'm not commenting on code he might have tried but didn't...because that would be stupid. I'm commenting on the code he *did* try, and explained how it was wrong. As for your error, Rino: "Element en is undefined in a CFML structure referenced as part of an expression"... well clearly the struct element you're accessing doesn't exist. Read the error message. Check your code, and check the struct you're accessing. Resolve the differences. – Adam Cameron Nov 25 '15 at 17:31
  • Yes. You where right. SERVER.Locale[LocaleName] is an empty object. – Rino Raj Nov 25 '15 at 17:50