I am dying to figure out a way to make a check to see if something is in the site Dictionary and if it's not then use something else. I have a billion instances of the following logic in my XSLT code:
Please tell me there is a way to do this logic inside the <xsl:value-of> tag? Just want to fall back on the English @nodeName if no match for it is found in the dictionary and this seems awfully wordy for such a simple thing.
I will try tohelp youcome up withmy suggestion. If Iunderstand your questionrightyou're looking fora solutionwhere you do nothave to writechooseconstructioneach time youtranslatesomething.
I wrote an article on using Dictionary Items in XSLT - the way you do this (using @nodeName as the key) is a perfect fit for the "bonus" at the end of the article - using that, you'd be able to do this with a single line:
Here's the condensed version of what you need from (that article):
<!-- Grab each section of labels -->
<xsl:variable name="frontpage-labels" select="umbraco.library:GetDictionaryItems('FrontPage')/DictionaryItems/DictionaryItem" />
<xsl:variable name="search-labels" select="umbraco.library:GetDictionaryItems('Search')/DictionaryItems/DictionaryItem" />
<xsl:variable name="product-labels" select="umbraco.library:GetDictionaryItems('Products')/DictionaryItems/DictionaryItem" />
<!-- Join them all for easy access -->
<xsl:variable name="labels" select="$frontpage-labels | $search-labels | $product-labels" />
<!--
Take the label key from the element's name;
If no DictionaryItem defined for this, wrap the element's name in hash-signs,
to signal a missing translation to the frontend.
-->
<xsl:template match="* | @*" mode="label">
<xsl:value-of select="$labels[@key = name(current())]" />
<xsl:if test="not($labels[@key = name(current())])">
<xsl:value-of select="concat('#', name(), '#')" />
</xsl:if>
</xsl:template>
Thank you so much for your responses, guys. Honestly, though, these solutions just seem like MORE code to me, no? I mean, this is happening on many, many pages. Is this meant to be an xsl:include, I guess?
Yes - it's an include file that enables you to use that one single apply-templates line wherever you need a translated label output.
This way, you'll even be able to swap an entirely different translation mechanism in, because you're not hard-wired to the Umbraco Dictionary any longer (code-wise where you need the labels).
Anyway, I guess you _could_ do these two lines everywhere, if you don't feel like trying the include solution:
xsl:value-of -- Inline Fallback/Nullcheck Logic?
Hi--
I am dying to figure out a way to make a check to see if something is in the site Dictionary and if it's not then use something else. I have a billion instances of the following logic in my XSLT code:
Please tell me there is a way to do this logic inside the <xsl:value-of> tag? Just want to fall back on the English @nodeName if no match for it is found in the dictionary and this seems awfully wordy for such a simple thing.
Thanks,
Garrett
Hi Garrett,
I will try to help you come up with my suggestion.
If I understand your question right you're looking for a solution where you do not have to write choose construction each time you translate something.
<xsl:variable name="translate">
<xsl:choose>
<xsl:when test="normalize-space(umbraco.library:GetDictionaryItem(@nodeName))">
<xsl:value-of select="umbraco.library:GetDictionaryItem(@nodeName)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@nodeName"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
And you can print it this way, if I remember correctly
<xsl:copy-of select=$translate />
Hope my answer can help you, if I understand correctly
/Dennis
Hi Garrett,
I wrote an article on using Dictionary Items in XSLT - the way you do this (using @nodeName as the key) is a perfect fit for the "bonus" at the end of the article - using that, you'd be able to do this with a single line:
Here's the condensed version of what you need from (that article):
/Chriztian
Thank you so much for your responses, guys. Honestly, though, these solutions just seem like MORE code to me, no? I mean, this is happening on many, many pages. Is this meant to be an xsl:include, I guess?
Hi Garrett,
Yes - it's an include file that enables you to use that one single apply-templates line wherever you need a translated label output.
This way, you'll even be able to swap an entirely different translation mechanism in, because you're not hard-wired to the Umbraco Dictionary any longer (code-wise where you need the labels).
Anyway, I guess you _could_ do these two lines everywhere, if you don't feel like trying the include solution:
/Chriztian
is working on a reply...