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

Forums / Developing with Sitefinity / Switching between language versions of the site

Switching between language versions of the site

3 posts, 0 answered
  1. Frank Hoffman
    Frank Hoffman avatar
    4 posts
    Registered:
    19 Aug 2009
    19 Jul 2011
    Link to this post
    I have a customer who has both English and Spanish versions of their Sitefinity 3.7 site.  They would like to have a hyperlink where they can switch between the English and Spanish versions, without changing their browser settings.

    I've tried many different things, but I can't seem to get the site to recognize the new culture when I set it programmatically.  I have the following code in a master page:

    protected void Page_Load(object sender, EventArgs e)
    {
        UpdateCultureInfo();
    }
     
    protected void languageLink_Click(object sender, EventArgs e)
    {
        if (System.Threading.Thread.CurrentThread.CurrentCulture.Name == "es-ES")
            SetLanguage("en-US");
        else
            SetLanguage("es-ES");
     
        UpdateCultureInfo();
    }
     
    private void UpdateCultureInfo()
    {
        if (System.Threading.Thread.CurrentThread.CurrentCulture.Name == "es-ES")
        {
            this.languageLink.Text = "In English";
            this.nav.Attributes.Add("class", "navSpanish");
            this.tagline.ImageUrl = "/images/healthyBodies_sm_spanish.png";
        }
        else
        {
            this.languageLink.Text = "en español";
            this.nav.Attributes.Add("class", "nav");
            this.tagline.ImageUrl = "/images/healthyBodies_sm.png";
        }
    }
     
    private void SetLanguage(string language)
    {
        System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(language);
        System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(language);
    }


    The hyperlink it's trying to set looks like this.

    <asp:LinkButton ID="languageLink" runat="server" text="en español" OnClick="languageLink_Click" />

    Here's what the localization section looks like in web.config.

    <localization defaultProvider="Sitefinity" persistenceMode="PathPrefix" defaultCulture="en" allowSpecificCultures="true" cultures="en, es">
        <providers>
            <clear />
            <add name="Sitefinity" type="Telerik.Localization.Data.DefaultProvider, Telerik.Localization.Data" connectionStringName="DefaultConnection" />
        </providers>
    </localization>

    I've tried several variations on that web.config setting.

    I've been beating my head against the wall on this one, so if anybody has any ideas, they would be greatly appreciated.
  2. Brenton
    Brenton avatar
    10 posts
    Registered:
    12 Sep 2008
    20 Jul 2011
    Link to this post
    I have the same issue. Exactly. Is anybody out there?
  3. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    25 Jul 2011
    Link to this post
    Hi,

    There is a control called language selector in the Navigation section of the Sitefinity page toolbox. From there you can add drop down which changes the current culture.

    The other option is to create a custom control which renders available languages as flag links.


    All the best,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested 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
3 posts, 0 answered