Copied to clipboard

Flag this post as spam?

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


  • Anthony Candaele 1197 posts 2049 karma points
    Jan 09, 2011 @ 16:04
    Anthony Candaele
    0

    implementing language selector

    Hi,

    I am implementing the language selector solution that Tim Geyssen provided on his blog:

    http://www.nibble.be/?p=32

    The problem is that this code is still in the old schema:

    <xsl:template match=”/”>
    <form>
    <select name=”langselection” onchange=”loadPage(this.form.elements[0])” target=”_parent._top” >
    <option selected=”selected”>– Please select –</option>
      <xsl:for-each select=”$currentPage/ancestor::root/node”>
             <option value=”{umbraco.library:NiceUrl(@id)}”><xsl:value-of select=”data [@alias = ‘language’]”/></option>      
      </xsl:for-each>
    </select>
    </form>
    </xsl:template>

    I have already converted some code to the new schema:

    <xsl:template match="/">
        <form>
            <select name="langselection" onchange="loadPage(this.form.elements[0])" target="_parent._top">
                <option selected="selected">– Please select –</option>
                <xsl:for-each select="$currentPage/ancestor::*">
                  <option value="{umbraco.library:NiceUrl($currentPage/@id)}">
                      <xsl:value-of select="$currentPage/language"/>
                    </option>
                </xsl:for-each>
            </select>
        </form>
    </xsl:template>

    But I still have an issue with looping through the top level root nodes.

    Currently my site structure looks like this:

    en
       page 1
       page 2
       page ...

    nl
       page 1
       page 2
       page ...

    fr
       page 1
       page 2
       page ...

    With the above converted code though, I'm just getting one top level node: en

    So I guess the line: <xsl:for-each select="$currentPage/ancestor::*">
    does not loop through all my top level nodes.

    How can I loop through all the top level nodes?

    Thanks for your help,

    Anthony Candaele
    Belgium

  • Kim Andersen 1447 posts 2197 karma points MVP
    Jan 09, 2011 @ 17:15
    Kim Andersen
    0

    Hi Anthony.

    I haven't tried this language selector, but I guess that you need to change the for-each to this:

    <xsl:for-each select="$currentPage/ancestor::root/*">

    /Kim A

  • Kim Andersen 1447 posts 2197 karma points MVP
    Jan 09, 2011 @ 17:26
    Kim Andersen
    0

    Ohh and by the way you might want to change the value of the option-tags from this:

    <option value="{umbraco.library:NiceUrl($currentPage/@id)}">

    to this:

    <option value="{umbraco.library:NiceUrl(@id)}">

    Otherwise all of the values will be same as the current page :)

    And hen the content of the options must be changed from this:

    <xsl:value-of select="$currentPage/language"/>

    to this:

    <xsl:value-of select="language"/>

    when you are inside a loop, and want to output anything unique from the nodes, you shall not use $currentPage. If you do so, there'll be output values from the current page where the for-each are being run at.

    /Kim A

  • Anthony Candaele 1197 posts 2049 karma points
    Jan 09, 2011 @ 17:43
    Anthony Candaele
    0

    Hi Kim,

    Thanks, now the language selector shows all options (English, Nederlands, Français) witht their respective values (/en.aspx, /nl.aspx and /fr.aspx).

    The only thing that does not work seemingly is the Javascript file:

    <script language=“JavaScript”>
        function loadPage(list) {
        location.href=list.options[list.selectedIndex].value }
      </script>

    If I select an option in the dropdownlist, nothing happens, I suppose there should be a page reload.

    The html in my dropdownlist looks like this:

    <form><select name="langselection" onchange="loadPage(this.form.elements[0])" target="_parent._top"><option selected="selected">– Please select –</option><option value="/en.aspx">English</option><option value="/nl.aspx">Nederlands</option><option value="/fr.aspx">Français</option></select></form>

    Thanks for helping me out,

    Anthony Candaele
    Belgium

  • Anthony Candaele 1197 posts 2049 karma points
    Jan 09, 2011 @ 18:01
    Anthony Candaele
    0

    The problem with the Javascript is solved. It was rather trivial. I copied the Javascript code from Tim's blog, but apparantly the double quotes are not valid:

    <script language=“JavaScript”>
    function loadPage(list) {
      location.href=list.options[list.selectedIndex].value
    }
    </script>

    So I just replaced the invalid double quotes and now my language selector works perfectly :)

    <script language="JavaScript">

    Thanks for helping me out Kim,

    Anthony

  • Kim Andersen 1447 posts 2197 karma points MVP
    Jan 09, 2011 @ 20:01
    Kim Andersen
    0

    You are very welcome Anthony :)

    /Kim A

  • dominik 711 posts 733 karma points
    Feb 24, 2011 @ 16:44
    dominik
    0

    one question

    is it possible to jump to the nearest element if no translation is available

    for example:

    I got two languages english and german and my structure is like:

    en/products/cars/car-one.aspx

    but in german there is only:

    de/products/cars/ available but not car-one.aspx?

    The user should be redirected to the de/products/cars/ and not to the root directory like it is at the moment

     

    Thanks

  • dominik 711 posts 733 karma points
    Mar 04, 2011 @ 10:13
    dominik
    0

    Can somebody please help?

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

    Continue discussion

Please Sign in or register to post replies