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

Forums / Developing with Sitefinity / Localization with PathPrefix and DomaiName

Localization with PathPrefix and DomaiName

7 posts, 0 answered
  1. Phill Hodgkinson
    Phill Hodgkinson avatar
    362 posts
    Registered:
    10 Nov 2004
    20 Feb 2010
    Link to this post
    Hi there,

    I have a site that supports two languages only. In initial development and now post launch the site has only required persistenceMode="PathPrefix". I have a number of custom code that injects the currentculture ("en" or "fr") into the path for various urls. Now my client has acquired the fr language version of their domain and would like that to be picked up and switch the site to french as well. Because I have so much work put into supporting PathPrefix I can't just switch to DomainName mode. Is there another way to have these two modes work together/at the same time?

    A related question. I have a simple custom language toggle button with the following code:
    if (Request.Url.ToString().IndexOf("/en/") > 0)
        Response.Redirect(Request.Url.ToString().Replace("/en/", "/fr/"));
    else
        Response.Redirect(Request.Url.ToString().Replace("/fr/", "/en/"));
    The above code works just fine in PathPrefix mode, the redirect updates the url and changes the language of the content on the page. However if I switch to DomainName mode and update the above code so that instead of replacing /en/ with /fr/ it replaces "ENgdomain.com" with "FRdomain.com" the page is redirected with the updated url but the content doesn't change it's language. Is there another way I could get this to work? If I could get this working I'd be willing to go through my other code and remove all PathPrefix custom reliant code and switch to DomainName only.

    As always any help is greatly appreciated.

    Regards,
    Phill


  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    22 Feb 2010
    Link to this post
    Hi Phill Hodgkinson,

    1. It is not possible to set DomainName and PathPrefix persistanceMode to work together at the same time. The property accepts only string value. Also there are many places in the code that this value is read and it would be impossible to hack all classes.

    2. The content listed by your controls could not be relevant to the culture if CurrentThread.CurrentUICulture is not correctly set upon your redirect. You could try to set the CurrentUICulture using simple code from this post - How to get the right content item

    Best wishes,
    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. Phill Hodgkinson
    Phill Hodgkinson avatar
    362 posts
    Registered:
    10 Nov 2004
    22 Feb 2010
    Link to this post
    In the end that did the trick. Thanks again! My working code for toggling based on domain name is as follows:
    protected void Button_ToggleLang(object sender, EventArgs e)
    {
        CultureInfo culture;
        if (Request.Url.ToString().IndexOf("eng-domain.com") > 0)
        {
            culture = CultureInfo.GetCultureInfo("fr");
            System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
            Response.Redirect(Request.Url.ToString().Replace("eng-domain.com", "fr-domain.com"));
        }
        else
        {
            culture = CultureInfo.GetCultureInfo("en");
            System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
            Response.Redirect(Request.Url.ToString().Replace("fr-domain.com", "eng-domain.com"));
        }
    }

    It's a bit odd that when using PathPrefix I just had to redirect with the prefix added, but redirecting to domain didn't set the culture. They serve the same purpose but obviously work differently.

    Thanks again!
    Phill
  4. Phill Hodgkinson
    Phill Hodgkinson avatar
    362 posts
    Registered:
    10 Nov 2004
    23 Feb 2010
    Link to this post
    Ok, I spoke too soon... I was able to use the above code locally and with modifying my hosts file to redirect the two domains back to my local web server it all worked. I uploaded the exact same code to the live server last night and it didn't work. The domain would get updated, redirect would happen and content would stay in it's initial language. If I land on the site via fr-domain.com the content comes up in fr and will never switch to english. If I hit the site with en-domain.com the content will come up in en and never switch to fr.

    Is there anything else that needs to be done? Could it be a cookie or server var that needs to be cleared? If it's any help, this is what localization section of web.config looks like (domains have been changed).

    <localization defaultProvider="Sitefinity" persistenceMode="DomainName" defaultCulture="en" cultures="en, fr" autoSetClientLanguage="false" allowSpecificCultures="true">
      <providers>
        <clear />
        <add name="Sitefinity" type="Telerik.Localization.Data.DefaultProvider, Telerik.Localization.Data" connectionStringName="DefaultConnection" />
      </providers>
      <cultureMappings>
        <add key="en-domain.ca" culture="en" />
        <add key="fr-domain.ca" culture="fr" />
        <add key="www.en-domain.ca" culture="en" />
        <add key="www.fr-domain.ca" culture="fr" />
      </cultureMappings>
    </localization>


    Any help would be greatly appreciated. Let me know if this should be filed via a support ticket for better resolution of the problem.

    Regards,
    Phill
  5. Phill Hodgkinson
    Phill Hodgkinson avatar
    362 posts
    Registered:
    10 Nov 2004
    24 Feb 2010
    Link to this post
    So I'm still struggling with this one. Using my Lang Button code above works locally as I said but not on live site. I realized the one difference. On the live site page caching is enabled for all pages (required as performance is not acceptable to the client without this enabled). With page caching on the redirect doesn't change languages when using DomainName mode, however when using PathPrefix it does work.

    Any explanations and work arounds? Can you replicate this on your end? I'm able to replicate it consistently on my live site and can now also replicate it locally using hosts file.

    Also, not as urgent, but how can I redirect to the FR page name as well and not just the domain?

    Finally, I believe I also need to fill out a form that is an "annex" to the license for the other language domain. I haven't done this yet, could this be the problem? Once this annex is completed do I get a new license key?

    Thanks again and looking forward to some answers.

    Cheers,
    Phill
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    24 Feb 2010
    Link to this post
    Hi Phill Hodgkinson,

    I will get back to you in the support request you opened.

    All the best,
    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.
  7. Phill Hodgkinson
    Phill Hodgkinson avatar
    362 posts
    Registered:
    10 Nov 2004
    25 Feb 2010
    Link to this post
    For anyone who may come across the issue with persistenceMode="DomainName" and their pages not changing languages I was able to get a solution via support ticket. This issue only seems to arise when page caching is enabled. In order to resolve the issue I had to update Global.asax as follows:

    public override string GetVaryByCustomString(HttpContext context, string custom)
    {
        if (custom.Equals("cms"))
        {
       // Change the following line     
    return String.Concat(context.Request.Url.Host, context.Request.RawUrl, context.Request.Browser.Type).ToLower();
        }
        return base.GetVaryByCustomString(context, custom);
    }


    On a related note I'm till not able to deploy as I've still got bugs in the backend caused by the DomainName persistenceMode. I've started a new thread to try to see if anyone has encountered these issues.

    Cheers,
    Phill
Register for webinar
7 posts, 0 answered