Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Topic author was deleted

    Sep 04, 2012 @ 21:09

    Feedback regarding our Polyglot Install

    First off, Polyglot has been working great for us.  However we've made some tweaks that work for us better in the long run that I wanted to share with the community.

    First off, we are no longer using the LanguageSelector.xslt.  We are using something similar called TranslationNodePicker.xslt which is shown below (note the usual extension and header tags have been excluded):

      <xsl:output method="xml" omit-xml-declaration="yes" />

      <xsl:param name="currentPage" />    
      <xsl:variable name="langISO" select="umbraco.library:RequestQueryString('lang')" />

      <xsl:variable name="translatedNodeID">
        <xsl:choose>
          <xsl:when test="$langISO='en'">
            <xsl:value-of select="$currentPage/@id"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$currentPage/*/*/language[text() = $langISO]/parent::node()/@id"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
                      
      <xsl:variable name="translatedCurrentPage" select="umbraco.library:GetXmlNodeById($translatedNodeID)" /> 


    The above XSLT brings in the 'currentPage' param and returns either the currentPage node (if default language (english in this case)) or the translated node through the variable 'translatedCurrentPage'.

    This makes the downstream XSLT a bit easier to work with IMHO.  Take for example the following XSLT that includes the above:


      <xsl:output method="xml" omit-xml-declaration="yes" />
                  
      <xsl:param name="Property" select="macro/Property" />
      <xsl:include href="../xslt/TranslationNodePicker.xslt" />     
                  
      <xsl:template match="/">

        <xsl:variable name='field' select="$translatedCurrentPage/*[name()=$Property]"/>

      </xsl:template>

    A few things to note:

    • The second XSLT does not bring in the currentPage param.  This is done automatically during the 'include'.
    • The second XSLT does not refer to 'currentPage', instead it only refers to 'translatedCurrentPage' whose value is set in the first XSLT.  Now the second XSLT only needs to refer to the property name.
    • This method has been stress tested with a fairly large cache file (~30MB) with great results.

     

    For our top Navigation, we are using this:

    <xsl:output method="xml" omit-xml-declaration="yes"/>
      
      <xsl:include href="../xslt/TranslationNodePicker.xslt" />
      <xsl:variable name="startingNode" select="$currentPage/ancestor-or-self::root" />
        
      <!-- create search form -->
      <xsl:template match="/" name='search'>    
        <div id="SearchBoxRight">
          <form method="get" action="search.aspx">    
            <input type="text" title="search web site" name="q" class="search-input" onblur="if(!this.value)this.value='Enter search terms...';" onclick="this.value=''" >
              <xsl:attribute name="value">
                <xsl:value-of select="umbraco.library:GetDictionaryItem('SearchSuggestion')"/>
              </xsl:attribute>
            </input>
            <input type="hidden" name="site" value="Europa"/>
            <input type="hidden" name="output" value="xml_no_dtd"/>
            <input id="lang" type="hidden" name="lang" value="{$langISO}" runat="server"/>
            <input id="client" type="hidden" name="client" value="Europa_{$langISO}" runat="server"/>
            <input id="proxystylesheet" type="hidden" name="proxystylesheet" value="Europa_{$langISO}" runat="server"/>
            <input type="submit" title="search" >
              <xsl:attribute name="value">
                <xsl:value-of select="umbraco.library:GetDictionaryItem('SearchSubmit')"/>
              </xsl:attribute>
            </input>
            
          </form>
        </div>
      </xsl:template>
      
      <!-- create navigation -->
      <xsl:template match="/">
        <xsl:choose>
          <!-- English -->
          <xsl:when test="$langISO='en'">
            <div id="nav">
              <div style="float:left;width:710px;">
                <ul class='nav'>
                  <xsl:for-each select="$startingNode/*[string(displayInTopNavigation)='1']">
                    <li>
                      <a href="{umbraco.library:NiceUrl(@id)}?lang=en">
                        <xsl:value-of select="@nodeName" />
                        <xsl:if test="count(./*[displayInTopNavigation='1'])">
                          <!-- add down arrow -->
                          <img src='/css/images/down_arrow.png' alt='Select'/>
                        </xsl:if>
                      </a>
                      <xsl:if test="count(./*[displayInTopNavigation='1'])">
                        <ul>
                          <xsl:for-each select="./*[displayInTopNavigation='1']">
                            <li>
                              <a href="{umbraco.library:NiceUrl(@id)}?lang=en">
                                <xsl:value-of select="@nodeName" />
                              </a>
                            </li>
                          </xsl:for-each>
                        </ul>
                      </xsl:if>
                    </li>
                  </xsl:for-each>
                </ul>
              </div>
              <xsl:call-template name="search"/>
            </div>
          </xsl:when>
        
          <!-- non-english -->
          <xsl:otherwise>
            <div id="nav">
              <div style="float:left;width:710px;">
                <ul class='nav'>
                  <xsl:for-each select="$startingNode//*[contains(name(), 'TranslationFolder')]/*[displayInTopNavigation='1' and language=$langISO and @level=3]">
                    <li>
                      <a href="{umbraco.library:NiceUrl(./parent::node()/parent::node()/@id)}?lang={$langISO}">
                        <xsl:value-of select="@nodeName" />
                        <xsl:if test="count(./parent::node()/parent::node()//*[displayInTopNavigation='1' and language=$langISO and @level &gt; 3])">
                          <!-- add down arrow -->
                          <img src='/css/images/down_arrow.png' alt='Select'/>
                        </xsl:if>
                      </a>
                      <xsl:if test="count(./parent::node()/parent::node()//*[displayInTopNavigation='1' and language=$langISO and @level &gt; 3])">
                        <ul>
                          <xsl:for-each select="./parent::node()/parent::node()//*[displayInTopNavigation='1' and language=$langISO and @level &gt; 3]">
                            <li>
                              <a href="{umbraco.library:NiceUrl(./parent::node()/parent::node()/@id)}?lang={$langISO}">
                                <xsl:value-of select="@nodeName" />
                              </a>
                            </li>
                          </xsl:for-each>
                        </ul>
                      </xsl:if>
                    </li>
                  </xsl:for-each>
                </ul>
              </div>
              <xsl:call-template name="search"/>
            </div>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:template>

    And finally, macros were not caching properly b/c the language needs to use the query string which is not apart of the caching mechanism.  So with a little help from this blog, we were able to cache Polyglot enabled macros.

    The secret with the caching is to set the lang param to the macro like this from the template:

    <umbraco:Macro Property="productDescription" Alias="PropertyTranslationFormatted" Lang="[@lang]" runat="server"></umbraco:Macro>

     

    Umbraco caches the macro based on the parameters.  Be sure to add 'Lang' to your macro property lists.

    I just wanted to pass along some lessons learned along the way with Polyglot.  Post comments and errors in my logic here for the masses.

    Thanks Dimitri!

  • dimi309 245 posts 579 karma points
    Sep 05, 2012 @ 10:31
    dimi309
    0

    Wow, thanks for all the feedback Kevin! I'll keep these things in mind for future versions.

    Best regards,

    Dimitri

Please Sign in or register to post replies

Write your reply to:

Draft