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

Forums / Developing with Sitefinity / Language Selector

Language Selector

5 posts, 0 answered
  1. Andree
    Andree avatar
    44 posts
    Registered:
    11 Jan 2010
    16 Feb 2010
    Link to this post
    Hi Ivan,

    I've been writing a custom control for handling the switching between two of our site languages (English, Japanese), and have had troubles making it work via the standard .NET CultureInfo classes.

    I tried the existing Language Selector control (found under "Navigation" in the page editor), and although it lists both languages, and the current page its on has both a published english and japanese version of the page, it does not swap between the two.

    Is there any additional codes or settings that need to be enabled for the language swapping to work? Our page localisation is set up to use Path prefix, e.g. http://www.domain.com/en/content.aspx and http://www.domain.com/ja/content.aspx


    Regards,
    Alvaro
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    16 Feb 2010
    Link to this post
    Hello Alvaro,

    By design the control switched the languages correctly It makes a postback and changes the persistanceMode. What your customized control should do?

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Andree
    Andree avatar
    44 posts
    Registered:
    11 Jan 2010
    16 Feb 2010
    Link to this post
    Hey Ivan,

    After a little bit of investigation, it turns out that the reason the standard Language Selection tool isn't working is due to the code executed by my own control. If I run the standard Language Selection control before doing anything with my own control, it works fine.

    I'm using the following code to change the current culture:

    Thread.CurrentThread.CurrentCulture = new CultureInfo(e.CommandArgument.ToString());
    Thread.CurrentThread.CurrentUICulture = new CultureInfo(e.CommandArgument.ToString());

    Where e.CommandArgument is either ja-JP or en-GB.

    Is there another approach to changing the current locale to work within Sitefinity?


    Regards,
    Alvaro
  4. Andree
    Andree avatar
    44 posts
    Registered:
    11 Jan 2010
    17 Feb 2010
    Link to this post
    Hi Ivan,

    After a bit more fiddling, and looking up other support forum posts, I've put together the following:

    CultureInfo info = new CultureInfo(e.CommandArgument.ToString());
    Thread.CurrentThread.CurrentUICulture = info;
    this.Context.Items["cmscurrcult"] = info;
    string appPath = this.Page.Request.Path.Substring(3);
    Response.Redirect(String.Format("/{0}{1}", info.TwoLetterISOLanguageName, appPath));

    This does redirect to the new language setting for the swapping of languages, but the moment a link is clicked from any of the sitefinity generated links like menus, etc. the site redirects to the next page in the default English language, not the currently selected language.

    Could you give me some example code on how to swap the language around programmatically?

    Regards,
    Alvaro
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    17 Feb 2010
    Link to this post
    Hi Alvaro,

    Try creating a ViewState property to persist the selected index value. Then if you make a post back get the property value and set the language.

    sample code

    public string selectedIndexValue
    {
        get
        {
            string s = (string)ViewState["selectedIndexValue"];
            return ((s == null) ? String.Empty : s);
        }
        set
        {
            this.ViewState["selectedIndexValue"] = value;
        }
    }
     
    void LanguageList_SelectedIndexChanged(object sender, EventArgs e)
    {
        selectedIndexValue = LanguageList.SelectedItem.Value;
    }
     
    protected void Page_Load(object sender, EventArgs e)
    {
     
         
        LanguageList.SelectedIndexChanged += new EventHandler(LanguageList_SelectedIndexChanged);
        if (Page.IsPostBack)
        {
            string val = selectedIndexValue;
        }


    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Register for webinar
5 posts, 0 answered