Solprovider Lenya Kongregate Registration for Free Flash Games and Chat with solprovider

Messages do not use i18n

There is a bug in Cocoon so any tags passed to fields are trashed. You could fix this by removing the line that serializes as XML. It was bad programming to put it there. If the programmer wanted the &, < and > changed to &amp;, &lt;, and &gt;, then the programmer could do it easily. Changing them back after Cocoon destroyed them is much more work.

Without this bug, you could pass multiple messages that each use i18n with:
form.model.messages = "<i18n:text key=\"error1\">Error 1 has occurred.</i18n:text><br/><i18n:text key=\"error2\">Error 2 has occurred.</i18n:text>";

With this bug, the tags will show on your form, and your visitors will be confused.

Luckily, the Cocoon Forms block adds functionality for processing Forms. Just copy the cocoon-2.1.6-src/cocoon-2.1.6/src/blocks/forms/samples/resources directory inside Lenya. I recommend apache-lenya-1.2.2/build/lenya/webapp/lenya/resources/forms. I changed my messages field to:
form.model.messages = "~~error1~Error 1 has occurred.~~error2~Error 2 has occurred.";

Then I fixed the form processing to turn that into XML. The following code changes any fd:output values that contain "~~" into i18n:text tags with BR tags between them.

FILE: forms-field-styling.xsl
REPLACE:
<xsl:template match="fi:output | fi:field[fi:styling/@type='output']" priority="2">
<xsl:copy-of select="fi:value/node()"/>
</xsl:template>


WITH:
<xsl:template match="fi:field[fi:styling/@type='output']" priority="2">
<xsl:copy-of select="fi:value/node()"/>
</xsl:template>

<xsl:template match="fi:output" priority="2">
<xsl:variable name="value" select="fi:value/node()"/>
<xsl:choose>
<xsl:when test="contains($value, '~')">
<xsl:call-template name="outputparse">
<xsl:with-param name="txt"><xsl:value-of select="$value"/></xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="fi:value/node()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template name="outputparse">
<xsl:param name="txt"/>
<xsl:choose>
<xsl:when test="contains($txt, '~~')">
<xsl:variable name="sbefore">
<xsl:value-of select="substring-before($txt, '~~')"/>
</xsl:variable>
<xsl:if test="string-length($sbefore) &gt; 0">
<xsl:call-template name="outputline">
<xsl:with-param name="txt"><xsl:value-of select="substring-before($txt, '~~')"/></xsl:with-param>
</xsl:call-template><BR/>
</xsl:if>
<xsl:call-template name="outputparse">
<xsl:with-param name="txt"><xsl:value-of select="substring-after($txt, '~~')"/></xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="outputline">
<xsl:with-param name="txt"><xsl:value-of select="$txt"/></xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template name="outputline">
<xsl:param name="txt"/>
<xsl:choose>
<xsl:when test="$txt = ''"></xsl:when>
<xsl:when test="contains($txt, '~')">
<xsl:element name="i18n:text">
<xsl:attribute name="key">
<xsl:value-of select="substring-before($txt, '~')"/>
</xsl:attribute>
<xsl:value-of select="substring-after($txt, '~')"/>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<i18n:text><xsl:value-of select="$txt"/></i18n:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


<< Presentationi18n Validation Popups >>

Contact Solprovider
Paul Ercolino