Copied to clipboard

Flag this post as spam?

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


  • Garrett Fisher 341 posts 496 karma points
    Mar 08, 2010 @ 15:57
    Garrett Fisher
    0

    toggling between languages

    With regard to Multi-language sites,...

    What is the most effective way toggle between multiple Home Pages / Sites?  I am confused that they have the same page name / url.  I have assigned them fake subdomains as intructed elsewhere on the forum, but honestly I don't see how this is going to do the trick.

    I have a dropdown at the top of the page that offers Spanish and English.  How can I make the users' choice select the correct home page and subpages?

    Thanks again,

    Garrett

  • dandrayne 1138 posts 2262 karma points
    Mar 08, 2010 @ 16:15
    dandrayne
    0

    A javascript powered dropdown is convenient and widely used (although not very accessible).  If there are only two languages I usually just write out two standard links to the homepages of each language.

    Like


    <select id="lang-select">
    <xsl:for-each select="$currentPage/ancestor::root/node [@nodeTypeAlias = 'HomePage' and string(./data [@alias='umbracoNaviHide']) != '1']">
    <option value="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="data [@alias = 'Language']"/></option>
    </xsl:for-each>
    </select>

    then

    $("select#lang-select").change(function() {
    window.location = $(this).find("option:selected").val();
    })

    (js is untested!)

    Dan

     

  • Garrett Fisher 341 posts 496 karma points
    Mar 08, 2010 @ 21:03
    Garrett Fisher
    0

    Seems to make good sense. Thanks for that.

    However, I do not have a field on this page for Language.  I was instructed to do this using the Manage Hostnames dialog, where I then choose a language and a subdomain with which to associated the page/site.  How do I dynamically get the assigned language from the node as described above?  Because

    <xsl:value-of select="data [@alias = 'Language']"/>

    isn't returning anything.

    Thanks again,

    Garrett

  • dandrayne 1138 posts 2262 karma points
    Mar 09, 2010 @ 13:42
    dandrayne
    0

    I used a field on the document so I could have a human-readable language option.  People didn't want to see "en-GB" or even "english - united kingdom", so I created a field to allow people to name the language, so we got:

    "English"
    "Francais"
    "US English"

    etc.

  • Garrett Fisher 341 posts 496 karma points
    Mar 12, 2010 @ 17:35
    Garrett Fisher
    0

    Ok. Gotcha.  Thanks again.  Now, a couple of remaining issues:

    1. How can I get the select box to "auto-select" based on which language was/is selected?  I don't know how to perform this comparison in the XSLT.  I mean, without hard-coding the subdomain(s). Any ideas?
    2. Is there a way to modify the <xsl:for-each> in such a way that the URL in the <option> isn't ALWAYS the home page?  In other words, when you change the language, it would stay ion the same page, just changing the subdomain.  Eg., "http://fr.localhost/about.aspx" to "http://en.localhost/about.aspx".  Any way?

    I very appreciate your time, @dandrayne.

    //Garrett

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Mar 12, 2010 @ 17:56
    Chriztian Steinmeier
    1

    Hi Garett,

    I have an XSLT snippet that does both of your remaining issues, but it's using 'relations' (having created additional languages' sites by copying the entire structure from the base site and checking a checkbox for creating a relation between them). This way the URL of the two pages doesn't even have to be the same...

    Anyway, maybe you can use some of it (as Dan, I have a 'language' property on the Homepage DocumentType):

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet 
        version="1.0" 
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:umbraco.library="urn:umbraco.library"
        exclude-result-prefixes="umbraco.library">
    
    <xsl:output method="xml" omit-xml-declaration="yes" />
    
    <xsl:param name="currentPage" />
    <xsl:variable name="currentLanguage" select="$currentPage/ancestor-or-self::node[@level = 1]/data[@alias = 'language']" />
    <xsl:variable name="relatedNode" select="umbraco.library:GetRelatedNodesAsXml($currentPage/@id)" />
    
    <xsl:template match="/">
    
        <select onchange="window.location = this.options[this.selectedIndex].value;">
            <xsl:if test="$relatedNode/relations[relation]">
                <xsl:attribute name="onchange">
                    <xsl:text>window.location = '</xsl:text>
                    <xsl:value-of select="umbraco.library:NiceUrl($relatedNode/relations/relation/node/@id)" />
                    <xsl:text>'</xsl:text>
                </xsl:attribute>
            </xsl:if>
    
            <xsl:for-each select="$currentPage/ancestor-or-self::root/node">
                <option value="{umbraco.library:NiceUrl(@id)}">
                    <xsl:if test="data[@alias = 'language'] = $currentLanguage">
                        <xsl:attribute name="selected">selected</xsl:attribute>
                    </xsl:if>
                    <xsl:value-of select="data[@alias = 'language']"/>
                </option>
            </xsl:for-each>
        </select>
    
    </xsl:template>
    
    </xsl:stylesheet>

    /Chriztian 

  • Garrett Fisher 341 posts 496 karma points
    Mar 12, 2010 @ 19:21
    Garrett Fisher
    0

    This is fantastic, Chriztian!  Thank you so much!  However, I DO still have one problem-- the currentLanguage variable returns as English no matter what.  In other words, the redirect is working great but even when I'm on the Spanish or French sites, "English" is selected.  Any idea why this would be?  My @language fields are definitely populated correctly.

    Thanks,

    Garrett

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Mar 12, 2010 @ 19:56
    Chriztian Steinmeier
    0

    Hey Garrett,

    'couple of possibilities for currentLanguage not changing:

     

    1. The actual property on the document is not called language
    2. The property is not on the Document at level 1 (do you have the roots of the different sites at level 1?)
    3. Can't think of a third option... :-) 

    (You could also look for a specific DocumentType instead of going to level 1, that was just easiest in my scenario)

    /Chriztian

     

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Mar 12, 2010 @ 20:09
    Chriztian Steinmeier
    0

    Oh - remember to check the generated HTML source — another reason "English" would be selected regardless of actual language, could be that English is the first language, and that no options are explicitly selected... does the HTML actually contain <option selected="selected">English</option> ?

    /Chriztian 

  • Garrett Fisher 341 posts 496 karma points
    Mar 12, 2010 @ 21:49
    Garrett Fisher
    0

    Yes.  Below is my output:

    <select onchange="window.location='/about-gtp.aspx'">
    <option value="http://en.localhost" selected="selected">English</option>
    <option value="http://fr.localhost">Spanish</option>
    </select>

    I copied code exactly.  What do you think is going on here?

    Thanks in advance,

    Garrett

  • Garrett Fisher 341 posts 496 karma points
    Mar 12, 2010 @ 22:01
    Garrett Fisher
    0

    The answer, Chriztian, is that I AM NOT *IN* the site I THINK I am!  I was told that if I set the subdomains and associate a language with them under the Manage Hostnames doalog, that Umbraco would take care of the rest in terms of separating the sites.  Why, no matter what subdomain I am browsing, am I always looking at the same site?  I tried changing some content in my Spanish site and I am on http://ES.localhost/, and my changes are not there.  I am ALWAYS looking at the English site.  What am I doing wrong here? 

    //Garrett

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Mar 15, 2010 @ 23:32
    Chriztian Steinmeier
    0

    Hi Garrett,

    This was caused by the issue with top-level nodes being named the same, from this thread, right?

    (Just making sure future Umbraco-Ninja-Padawans will find an explanation for this.)

    /Chriztian

  • Garrett Fisher 341 posts 496 karma points
    Mar 17, 2010 @ 20:36
    Garrett Fisher
    0

    Yes, this was the reason-- good lookin' out :)  That problem is a thing of the past.  NOW-- glad I have you back, Chriztian, because I'm using your XSLT code snippet for toggling the language, and although it seems to be working great in Some places, I am getting somewhat inconsistent results from it.  To refresh your memory, here's what we've got:

    <select onchange="window.location=this.options[this.selectedIndex].value;">
    <xsl:if test="$relatedNode/relations[relation]">
    <xsl:attribute name="onchange">
    <xsl:text>window.location='</xsl:text>
    <xsl:value-of select="umbraco.library:NiceUrl($relatedNode/relations/relation/node/@id)" />
    <xsl:text>';</xsl:text>
    </xsl:attribute>
    </xsl:if>

    <xsl:for-each select="$currentPage/ancestor-or-self::root/node">
    <option value="{umbraco.library:NiceUrl(@id)}">
    <xsl:if test="data[@alias = 'language'] = $currentLanguage">
    <xsl:attribute name="selected">selected</xsl:attribute>
    </xsl:if>
    <xsl:value-of select="data[@alias = 'language']"/>
    </option>
    </xsl:for-each>
    </select>

    What's happening is that on 2nd-tier pages (eg., Home > About), it's writing out the FULL path in the onchange call, eg.:

    http://es.localhost/about-gtp.aspx

    And so the toggle works-- the language is switched because of the inclusion of the subdomain.  However, this first part of the URL is left out on 3rd-tier, and moreover, any nth-tier page greater than the 2nd level.  Why is this? Can you please give me some advice on how to fix this in the XSLT? 

    Thanks again,

    Garrett

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Mar 17, 2010 @ 23:45
    Chriztian Steinmeier
    0

    Hi again Garrett - we meet again :-)

    I'm afraid I can't give you any great explanation here, because the culprit lies within the NiceUrl() method - as you can see, the actual URL is generated from the id of the related node — if you're curious about the XML returned from GetRelatedNodesAsXml(), it looks similar to this example:

    <relations>
        <relation typeId="1" typeName="Relate Document On Copy" createDate="1/18/2010 3:01:59 PM" parentId="1047" childId="1062">
            <comment></comment>
            <node id="1062" parentID="1060" level="2" writerID="0" sortOrder="2" createDate="2010-01-18T15:01:59" nodeName="Dokumentation" path="-1,1060,1062" />
        </relation>
    </relations>

    Maybe someone closer to Core can shed some light on this peculiarity...

    /Chriztian

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Mar 18, 2010 @ 11:00
    Douglas Robar
    0

    Perhaps this issue is related to your niceUrl() problem with the 3rd level? Includes proposed workaround:

    http://our.umbraco.org/forum/getting-started/installing-umbraco/6449-Umbraco-NiceUrls-not-returning-with-full-domain

    cheers,
    doug.

Please Sign in or register to post replies

Write your reply to:

Draft