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

Forums / Developing with Sitefinity / Force sitemap to use default language if page not translated

Force sitemap to use default language if page not translated

5 posts, 0 answered
  1. Phill Hodgkinson
    Phill Hodgkinson avatar
    362 posts
    Registered:
    10 Nov 2004
    15 May 2009
    Link to this post
    Hi There,

    So I have an issue where I'm trying to build a bilingual (en, fr) site but not every page will be translated, especially during development. Thanks to Ivan and this thread I was finally able to get a language toggle working http://www.sitefinity.com/support/forums/support-forum-thread/b1043S-cbbtta.aspx

    However the issue I'm having now (as I mention at the bottom of that post but wanted to break it into it's own thread) is that if I haven't created a fr (not the default) version of the page my menus show up blank. As I mentioned this causes two problems for me, first not all pages will get translated so I need their menu items to show up in english, secondly, while developing and translating the site, content editors need to be able to navigate the site in French to see what's missing etc. They can't do this with blank menus.

    One other issue here is that I have two top level groups so that I can have two menus. The two groups (public/private) obviously have no need to be translated but if I don't create the other lang version of them I get an asp error that public.aspx can't be found when switching to the non default language. Definitely a bug in my opinion as this should be ignored or at the very least directed to a 404 language not found page.

    Is there a trick to get the sitemap to revert back to using the default language for the menu lable if the page hasn't been localized? If there's no trick could someone pointme to hack or where I'd want to add custom code?

    Many thanks in advance!
    Cheers,
    Phill
  2. Phill Hodgkinson
    Phill Hodgkinson avatar
    362 posts
    Registered:
    10 Nov 2004
    15 May 2009
    Link to this post
    Small update, I just came across this thread from about a year ago that may answer my question (the last two posts). http://www.sitefinity.com/support/forums/support-forum-thread/b1043S-bcctak.aspx

    Unfortunately it's not what I wanted to hear. Is this still the case that the sitemap provider won't revert to the default language if the page hasn't been localized? You have a mechanism in place for the page to use the default language content if it hasn't been localized but that's totally useless if someone switches languages and all the menu items disappear. 

    Seems like someone started to implement localization an then got pullled onto something else before finishing the job. My fingers are crossed that this functionality has since been completed to include the sitemap provider and that I'm just missing a simple setting somewhere.

    Thanks again!
    Phill
  3. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    15 May 2009
    Link to this post
    Hello Phill Hodgkinson,

    You can achieve redirecting from non translated  pages to translated versions of the same pages. You should create a http module that redirects all request from French pages to the English version( or vice versa).I am sending you a sample module that.  You can change the  logic and made changes in accordance with your needs. Also, this redirection will not affect the Admin section of your website. Furthermore, "/en/" is not removed from the url and your hyper links will remain untouched as well. In this case you can use LanguageBar control on your pages and all users that select French language will be redirected to the en version of the site until the french version is released ( or vice verca) .

    public class CustomHttpModule : IHttpModule  
    {  
        #region IHttpModule Members  
      
        public void Dispose()  
        {  
        }  
      
        public void Init(HttpApplication context)  
        {  
            context.BeginRequest += new EventHandler(context_BeginRequest);  
        }  
      
        void context_BeginRequest(object sender, EventArgs e)  
        {  
            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))  
                {   
                   // redirect to the default culture 
                    context.Response.Redirect(  
                        UrlHelper.ResolveLanguageUrl(  
                            UrlHelper.UnresolveLanguageUrl(context.Request.RawUrl), LocalizationManager.DefaultCulture), true);  
                }  
            }     
        }  
        #endregion  
    }  



    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.
  4. Phill Hodgkinson
    Phill Hodgkinson avatar
    362 posts
    Registered:
    10 Nov 2004
    16 May 2009
    Link to this post
    Hi Ivan,

    Thanks for your reply but your recommended solution isn't at all what I was looking for, it sends the user in an endless loop where they always end up back at the english site.

    I have a site where 80% of my pages will be in french, with french menu items displayed, however if a page isn't translated I need the english menu item to show up and the english page to be displayed when selected. However when they select the english page I need all the french menu items to remain there. Similarly, if they're on an english page and click on the link that toggles the site to french, the site needs to switch into french mode with french menus but display that one page in english if it's not translated. 

    There's still the case of the entire application throwing an error if you have a group menu node that doesn't have the second language generated for it. Would you not agree that this is a "bug" ?

    Thanks again for your help, I'd love to find a solution to this as it's critical for me in launching my site.
    Phill
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    18 May 2009
    Link to this post
    Hi Phill Hodgkinson,

    The current CmsSiteMap does not support your requirement.

    There are several ways that I could suggest.

    1. When you are creating a page in one version - en, then create this page in the other language version you have - fr. You can do it programmatically - Check out this KB article utomatically create other language versions of the page using Sitefinity API
    2. Create a CustomSiteMap that will be used instead of CmsSiteMap and implement your logic there.

    Sample code of Custom SiteMap

    using System; 
    using System.Collections; 
    using System.Collections.Specialized; 
    using System.Web; 
    using Telerik.Cms; 
     
    /// <summary> 
    /// Summary description for CustomSiteMap 
    /// </summary> 
    ///  
    namespace Telerik.Samples 
        public class CustomSiteMap : StaticSiteMapProvider 
        { 
            /// <summary>Initializes a new instance of the <see cref="T:Telerik.Web.UI.Cms.CmsSiteMapProvider"></see> class. </summary> 
            public override void Initialize(string name, NameValueCollection attributes) 
            { 
                base.Initialize(name, attributes); 
            } 
     
            protected override void Clear() 
            { 
                lock (this
                { 
                    base.Clear(); 
                    this.root = null
                } 
            } 
     
            public override SiteMapNode BuildSiteMap() 
            { 
                if (this.root != null
                    return this.root; 
     
                lock (this
                { 
                    this.root = new SiteMapNode(this"00000000-0000-0000-0000-000000000000", String.Empty, "[My Site Map]"); 
                    CmsManager cmsManager = new CmsManager(); 
                    IList pages = cmsManager.GetPages(Guid.Empty); 
                     
                    foreach (ICmsPage page in pages) 
                    { 
                            SiteMapNode node = new SiteMapNode(this, page.ID.ToString(), page.DefaultUrl.Url, page.MenuName); 
                            base.AddNode(node, root); 
                            this.LoadPagesRecursive(node, page); 
                         
                    } 
     
                    return root; 
                } 
            } 
     
            protected override SiteMapNode GetRootNodeCore() 
            { 
                return this.BuildSiteMap(); 
            } 
     
            private void LoadPagesRecursive(SiteMapNode parentNode, ICmsPage parentPage) 
            { 
                if (parentPage.Pages.Count > 0) 
                { 
                    foreach (ICmsPage page in parentPage.Pages) 
                    {             
                            SiteMapNode node = new SiteMapNode(this, page.ID.ToString(), page.DefaultUrl.Url, page.MenuName); 
                            base.AddNode(node, parentNode); 
                            this.LoadPagesRecursive(node, page);  
                    } 
                } 
            } 
     
            private SiteMapNode root; 
        } 

    As for the group page problem I did the following
    1. Enable Sitefinity localization - with default language "en" and cultures - "en" and "fr"
    2. Created a group page with one page.
    3. Added language list control on a page.
    4. Loaded this page on my default language  - the rad menu control was populated with all pages that I had created in en.
    4. Switch the language from language list control - when I am on the group page  and no errors were thrown. The same page was loaded in the other culture - ft, but the menu was not populated, because I had not created any items for this culture.

    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.
Register for webinar
5 posts, 0 answered