1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Can I use dropdownlist for culture selection

Can I use dropdownlist for culture selection

8 posts, 0 answered
  1. Priya Ramesh
    Priya Ramesh avatar
    26 posts
    Registered:
    23 Jul 2009
    21 Sep 2009
    Link to this post
    Hi,
       I want to use a radcombobox for selecting the culture . Is there a way I can use the radcombobox or my own custom control for selecting the culture?

    Thanks,
    Priya
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    21 Sep 2009
    Link to this post
    Hi Priya Ramesh,

    Actually it is possible, but it will require to create a custom control from scratch. Below is a sample control  that illustrate getting and binding all language versions. You should  complete the code and create custom events that rise when the language is changed so that you can get the same behavior as our control.

    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Web; 
    using Telerik.Cms.Web.UI; 
    using Telerik.Web.UI; 
    using System.Globalization; 
    using Telerik.Localization; 
     
    /// <summary> 
    /// Summary description for CustomLanguageBar 
    /// </summary> 
    public class CustomLanguageBar : SimpleControl 
        public CustomLanguageBar() 
        { 
     
        } 
        public override string LayoutTemplatePath 
        { 
            get 
            { 
                return "~/CustomControls/WebUserControl.ascx"
            } 
        } 
     
        protected override void CreateChildControls() 
        { 
            base.CreateChildControls(); 
            CultureInfo neutralCulture = LocalizationManager.GetNeutralCulture(CultureInfo.CurrentUICulture); 
            int i = 0; 
            foreach (CultureInfo info in LocalizationManager.Cultures.Values) 
            { 
                RadComboBoxItem ComboItem = new RadComboBoxItem(info.NativeName, LocalizationManager.GetMappingKey(info.Name)); 
                if (info.Equals(neutralCulture) || info.Equals(CultureInfo.CurrentUICulture)) 
                Combo.SelectedIndex = i; 
                Combo.Items.Add(ComboItem); 
                i++; 
            } 
        } 
     
        public virtual RadComboBox Combo 
        { 
            get 
            { 
                return base.Container.GetControl<RadComboBox>("RadComboBox1"false); 
            } 
        } 

    I hope this helps.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Priya Ramesh
    Priya Ramesh avatar
    26 posts
    Registered:
    23 Jul 2009
    21 Sep 2009
    Link to this post
    Thanks for the information. How do I change the culture/language programatically? (Like in .Net I can set the currentthread's currentuiculture)

    Thanks,
    Priya
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    22 Sep 2009
    Link to this post
    Hi Priya Ramesh,

    You can easily switch the culture by overriding OnPreRender method and there get the current context and the ApplicationPath.

    string Lang = String.Empty; 
    CultureInfo info = (CultureInfo)this.Context.Items["cmscurrcult"]; 
    string appPath = this.Page.Request.ApplicationPath; 
     

    Then you can use String.Format to change the url. The same behavior is used for LanguageBar and LangugeList controls.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Steve L
    Steve L avatar
    2 posts
    Registered:
    17 Jul 2009
    02 Oct 2009
    Link to this post
    The Sitefinity built-in language selector spells Italiano as italiano (note the small letter i (eye)  at the start of the language name).  How do I correct this?
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    02 Oct 2009
    Link to this post
    Hello Stephen Lupton,

    It is possible. Add the code shown below to Admin.master.cs.
     protected override void OnPreRender(EventArgs e) 
        { 
            base.OnPreRender(e); 
     
           DropDownList LangListControl =  LangBar.Controls[0].FindControl("languageList"as DropDownList; 
     
            if (LangListControl != null
            { 
                foreach (ListItem item in LangListControl.Items) 
                { 
                    if (item !=null && item.Text == "italiano"
                    { 
                        string newText = "Italiano"
                        item.Text = newText; 
                    } 
                } 
            } 
        } 

    I hope this helps.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. Priya Ramesh
    Priya Ramesh avatar
    26 posts
    Registered:
    23 Jul 2009
    02 Oct 2009
    Link to this post
    Hi,
      The above code you sent only changes the italiano to Italiano in the admin section of the page
    I am  using the Language bar(Language selector control) in my page and want to change it to Italiano.

    Thanks,
    Priya
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    03 Oct 2009
    Link to this post
    Hi Priya Ramesh,

    You can create a user control and declare Language bar there with ID="LangBar". In the code behind of your user control you could use the same code which I sent to Stephen.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
8 posts, 0 answered