More in this section

Forums / Developing with Sitefinity / Language "Toggle"

Language "Toggle"

7 posts, 0 answered
  1. Phill Hodgkinson
    Phill Hodgkinson avatar
    362 posts
    Registered:
    10 Nov 2004
    12 May 2009
    Link to this post
    Hi There,

    I've searched the forums quite a bit and have been unable to find a sample of what I'm looking for. I'm building a site that will only ever have two languages and would like to have a button/link up top that will switch or "toggle" the site to the other language. This post http://www.sitefinity.com/support/forums/support-forum-thread/b1043S-bmbdeb.aspx  looks close but it lists both the current language and the other language. Is another approach required entirely or is there an easy way I could hide the current language?  Based on that post I think I'd prefer something that didn't inherit from the LanguageList as it sounds like there are some hard coded style issues that are hard to get around.

    As always any help is greatly appreciated!
    Cheers,
    Phill
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    12 May 2009
    Link to this post
    Hello Phill Hodgkinson,

    You can use the following declaration

    <style type="text/css">   
    .langList li   
    {   
        float:left;   
        padding: 0px;   
        list-style-type:none;  
           
    }  
       
    </style>  
      
    <lng:LanguageBar  ID="list1" runat="server">  
        <LayoutTemplate>  
            <lng:LanguageList CssClass="langList" ID="languageList" runat="server"></lng:LanguageList>  
        </LayoutTemplate>  
    </lng:LanguageBar>  

    You can enable the localization through your web.config file only for the languages you want.( section localization)

    Styling issues related to hardcoded properties have been sorted out in the last release.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Phill Hodgkinson
    Phill Hodgkinson avatar
    362 posts
    Registered:
    10 Nov 2004
    12 May 2009
    Link to this post
    Hi Ivan,

    Thanks for the quick reply. However this doesn't quite do what I need. The code you provided shows two links for English and Francais (my two supported languages). However, when I'm in the english mode I don't want or need the link to english to be displayed and the same would apply to when in the french mode.

    On a related note, with the two links there, when I click to switch to french on a page that I know has a french version I get an error "Could not find the sitemap node with URL '~/Private.aspx'." where private.aspx is actually a page group, so it shouldn't even be a page. Any suggestions where to trouble shoot that one?

    Thanks again!
    Phill
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    13 May 2009
    Link to this post
    Hello Phill Hodgkinson,

    The control loads all cultures you have added in the web.config. Below is a sample code that you can use to hide the current selected language.

     
        protected void Page_Load(object sender, EventArgs e) 
        { 
            LanguageList lngList = this.FindControlRecursive(list1, "languageList"as LanguageList; 
            string defaultCulture = Thread.CurrentThread.CurrentUICulture.Name;; 
            for(  int i = lngList.Items.Count-1 ; i >= 0 ; i-- ) 
            { 
                ListItem li = lngList.Items[i]; 
                 
                if (li.Value == defaultCulture) 
                { 
                    lngList.Items.RemoveAt(i); 
                } 
            } 
        } 
        private Control FindControlRecursive(Control root, string id) 
        { 
            if (root.ID == id) 
            { 
                return root; 
            } 
     
            foreach (Control c in root.Controls) 
            { 
                Control t = FindControlRecursive(c, id); 
                if (t != null
                { 
                    return t; 
                } 
            } 
     
            return null
        }  
     

    As for the problem with group page I am not able to reproduce it.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Phill Hodgkinson
    Phill Hodgkinson avatar
    362 posts
    Registered:
    10 Nov 2004
    14 May 2009
    Link to this post
    Hi Ivan,

    Thanks so much for the sample code, did the trick for me! 

    As for the error I'm having, I'm still at a bit of a loss. One thing that I did was create my basic menu structure and then only after did I realize that I needed to enable localization. Could that be the cause?

    Would it be useful at all for me to email/IM you the url so that you can see what happens?

    Thanks again!
    Cheers,
    Phill
  6. Phill Hodgkinson
    Phill Hodgkinson avatar
    362 posts
    Registered:
    10 Nov 2004
    14 May 2009
    Link to this post
    Here's a bit more info. I've made some progress and found a work around but I'm not sure why it's necessary. To step back, here's my basic site setup:
    1. Require 2 menus, MenuA(Private) and MenuB(Public)
    2. Most but not all content is to be bilinugal (en, fr)

    In order to get my menus to work I set their StartingNodeUrl to Private.aspx and Public.aspx. My understanding with localization was that if the "strinct" setting wasn't set then it would just use the default language instead. So when I was at page MenuB -> Page 1 and hit the lang toggle, it would complain that it couldn't find node Private.aspx. (note Private.aspx and Public.aspx are both set to not appear in navigation as they are only used to group). I had to manually create the french version of Private.aspx and Public.aspx to make the error go away. So there's my work around....

    ... but not there yet. Now I see the french version of Page 1 with no errors, but I don't get any menu items, both menu's are completely blank. The only way to get an item to appear is create the french version. This isn't an option for me since not all pages will have french versions. What to do???

    Thanks again!
    Phill
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    18 May 2009
    Link to this post
    Hello Phill Hodgkinson,

    I have sent a reply to the other post opened by you that has reference to this thread.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
7 posts, 0 answered