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

Forums / Developing with Sitefinity / multilanguage site default language

multilanguage site default language

8 posts, 0 answered
  1. yuval
    yuval avatar
    11 posts
    Registered:
    23 Jun 2008
    02 Mar 2009
    Link to this post
    Hi,

    I have a multilanguage site but not all pages are implemented on all languages.
    for example i have an english (default language) page which doesnt have a french version.
    Is it possible to redirect the user to the default language page? instead of getting just an empty page..

    thanks alot in advance,
    yuval
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    02 Mar 2009
    Link to this post
    Hello yuval,

    Generally, when the client tries to access your website, it is redirected to this language version which is get from client's regional settings.
    You can prevent auto client language setting by adding autoSetClientLanguage property as the example below demonstrates. Thus, your users will be forced to choose their language manually.
    <localization defaultProvider="Sitefinity" autoSetClientLanguage="false" persistenceMode="PathPrefix" defaultCulture="en" cultures="en, es, fr, de, bg">  

    Another way is creating a custom HttpModule that inherits IHttpModule then check whether on of the languages you have ( french) is translated or not and redirect the user to appropriate or default language.

     
    // add logic here 
     
     
    CultureInfo frCulture = CultureInfo.GetCultureInfo("fr");  
                if (culture != null && culture.Equals(frCulture))  
                {  
                    context.Response.Redirect(  
                        UrlHelper.ResolveLanguageUrl(  
                            UrlHelper.UnresolveLanguageUrl(context.Request.RawUrl), LocalizationManager.DefaultCulture), true); 
                 }  

    I hope this helps.

    All the best,
    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. yuval
    yuval avatar
    11 posts
    Registered:
    23 Jun 2008
    02 Mar 2009
    Link to this post
    Hi Ivan,

    thanks for the quick reply.
    I think i didn`t explained myself good enough.
    What i meant was that for example, the user is currently on an english version page and now he clicks on the language bar to switch to french, but there is no french version. the behaviour i want is that the user will reach the default language page. is it possible?

    thanks,
    yuval 
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    02 Mar 2009
    Link to this post
    Hi yuval,

    It is possible checking the CultureInfo and using the HttpModule I mentioned about in the previous post.

    All the best,
    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. yuval
    yuval avatar
    11 posts
    Registered:
    23 Jun 2008
    02 Mar 2009
    Link to this post
    Hi Ivan,

    thank you very much for your help.
    One last thing, how can i know if there is a version of the page at the lanugage im in? for example french.

    thanks alot,
    yuval
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    02 Mar 2009
    Link to this post
    Hi yuval,

    Check out the code below:

    HttpContext context = HttpContext.Current;  
            if (CmsUrlContext.Current != null && context.Items["cmspagemode"] == null)  
            {  
                CultureInfo culture = (CultureInfo)context.Items["cmscurrcult"];  
                CultureInfo frCulture = CultureInfo.GetCultureInfo("fr");  
                if (culture != null && culture.Equals(frCulture)) 
                  { 
                   // do something here  
                  } 


    Kind regards,
    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.
  7. yuval
    yuval avatar
    11 posts
    Registered:
    23 Jun 2008
    02 Mar 2009
    Link to this post
    Hi Ivan,

    I dont understand where you are making the test if you have a translated version of the page.

    these lines of code:
     CultureInfo culture = (CultureInfo)context.Items["cmscurrcult"];  
                CultureInfo frCulture = CultureInfo.GetCultureInfo("fr");  
                if (culture != null && culture.Equals(frCulture)) 

    just check if the current language you are in is french
    isn`t it?

    thanks very much,
    yuval
  8. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    06 Mar 2009
    Link to this post
    Hello Yuval,

    There are two approaches for this task:

    1. Check the LanguageVersions collection, of the ICmsPage:
    CmsManager m = new CmsManager(); 
    ICmsPage page = m.GetPage() as ICmsPage; 
    if (page.LanguageVersions.ContainsKey(ID_OF_THE_LANGUAGE)) 
        // found 

    2. Finding all pages which exists in a given language:
    protected void Page_Load(object sender, EventArgs e)   
    {   
        Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("de");   
        Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("de-de");   
      
        WritePageNames(SiteMap.RootNode);   
    }   
      
    private void WritePageNames(SiteMapNode node)   
    {   
        foreach (SiteMapNode childNode in node.ChildNodes)   
        {   
           Response.Write(childNode.Title);   
           Response.Write("<br />");   
           WritePageNames(childNode);   
        }   
    }  
    Then, if your page is in that collection, then you actually have the page with such language version.

    All the best,
    Georgi
    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
8 posts, 0 answered