Language Selector Error - General Discussions - General Discussions - Progress Community
 General Discussions

Language Selector Error

  • Language Selector Error
  • Hi,

    when i try to add the language selector widget to my template i receive one error. Please see the attached images.

    I have two languages PT and EN .

  • Hi JV,

    I am not able to replicate this issue locally. Could you attach several screenshots

    1. Language settings screeen
    2. Pages configuration Sitefinity >> Administration >> Settings >> Advanced >> Pages and what has been set for FrontendRootNode

    3. On which language version you create a page.

    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
  • Hi,

    I sent the images in attach.

    My homepage is created in PT and EN but i have other pages that are only created in PT.

  • Hello JV,

    I am not able to replicate the issue with these settings. There is a new build that we uploaded today. Could you download it and try to replicate the issue with it. Let me know if the problem persists and I will try to come up with other suggestions to narrow it down.

    Sincerely yours,
    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
  • Hi,

    I already made the download of the new release and run the upgrade in project manager.

    When i try to add the language selector to one page it works.

    When i try to add the language selector to one page template i get the error.

  • Hi JV,

    The control cannot work on backend pages or templates. Its current implementation allows to use it only with FrontendSiteMap. We will add some logic to catch the exception. The problem should not persists for pages created under FrontendSiteMap

    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
  • OK.
    The error disappear after applying the template to one frontendpage.

    I need to change the "tag" displayed in the language selector for example i don't whant "English" but i whant that "EN" appear to the user (Português --> PT). How can i achieve this, how can i costumize the language selector ?

    thanks,
    JV
  • Hello JV,

    We use CultureInfo and NativeName property of the object. You can change the text of the HtmlGenericControl that us used by creating a custom class that inherits from LanguageSelectorControl. You should override InitializeControls method and rebind the Repeater control - LanguagesRepeater

    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
  • Sorry i think i don't understand 100%.
    Could you send a litle sample in attach?

    thanks,
    JV
  • Hello JV,

    Here is a sample code

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Telerik.Sitefinity.Localization.Web.UI;
    using System.Globalization;
    using Telerik.Sitefinity.Configuration;
    using Telerik.Sitefinity.Modules.Pages.Configuration;
    using Telerik.Sitefinity.Modules.Pages;
    using Telerik.Sitefinity.Abstractions;
    using Telerik.Sitefinity.Model;
    using System.Threading;
     
    namespace Telerik.Sitefinity.Samples
        public class LanguageSelectorControlCustom : LanguageSelectorControl
        
     
            protected override string LayoutTemplateName
            
                get
                
                    return LanguageSelectorControlCustom.customTemplate;
                
            
     
     
            protected override void InitializeControls(Web.UI.GenericContainer container)
            
                //base.InitializeControls(container);
                var settings = ObjectFactory.Resolve<IAppSettings>();
                List<CultureInfo> languages = new List<CultureInfo>();
                if (this.MissingTranslationAction == NoTranslationAction.HideLink)
                
                    languages.AddRange(this.usedLanguages);
                
                else
                
     
                    languages.AddRange(settings.DefinedFrontendLanguages);
                    PageManager pm = PageManager.GetManager();
                    var homePageId = Config.Get<PagesConfig>().HomePageId;
                    if (homePageId != Guid.Empty)
                    
                        this.homePageNode = pm.GetPageNode(homePageId);
                    
                
                CultureInfo currentLanguage = Thread.CurrentThread.CurrentUICulture;
                IEnumerable<CultureInfo> shownLanguages;
                if (this.ShowCurrentLanguage == false && this.SelectorType != LanguageSelectorType.DropDown)
                
                    shownLanguages = languages.Where(ci => ci.Equals(currentLanguage) == false);
                
                else
                
                    shownLanguages = languages;
                
                this.LanguagesRepeater.DataSource = shownLanguages;
                this.LanguagesRepeater.ItemDataBound += new System.Web.UI.WebControls.RepeaterItemEventHandler(LanguagesRepeater_ItemDataBound);
                this.LanguagesRepeater.DataBind();
            
     
            void LanguagesRepeater_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
            
                CultureInfo ci = (CultureInfo)e.Item.DataItem;
                // here format the link you want to see.
            
     
            // you can get the template through reflector.
            private const string customTemplate = "Telerik.Sitefinity.Samples.Templates.PublicControls.LanguageSelectorControl.ascx";
            private List<CultureInfo> usedLanguages;
            private Pages.Model.PageNode homePageNode;
        
     


    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
  • Thank you for the code.

    See the attached code please tell me what i'm doing wrong (i tried to sent one zip file but i was not allowed).
    Sorry but I don't have "Custom Control" experience.

    I registered the atached control in the toolbox but nothing appears.

  • Hello JV,

    1. You have not completed the logic inside ItemDataBound event of the repater

    2. You should use the template below.

    <%@ Control Language="C#" %>
    <%@ Register TagPrefix="sfFields" Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI.Fields" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %>
     
    <div runat="server" id="controlWrapper">
     
        <asp:Panel ID="errorsPanel" runat="server" CssClass="sfErrorSummary" />
     
        <sf:ConditionalTemplateContainer ID="sfLangSelectorConditionalTemplateContainer" runat="server">
            <Templates>
                <sf:ConditionalTemplate Left="SelectorType" Operator="Equal" Right="Horizontal" runat="server">
                    <asp:Repeater ID="languagesRepeater" runat="server">
                        <HeaderTemplate>
                            <ul id="langsWrapper" class="sflanguagesHorizontalList">
                        </HeaderTemplate>
                        <ItemTemplate>
                            <li runat="server" id="langHolder" class="sflanguageItem">
                                <a runat="server" id="langLink" href=""><span runat="server" id="langName"></span></a>
                            </li>
                        </ItemTemplate>
                        <FooterTemplate>
                            </ul>
                        </FooterTemplate>
                    </asp:Repeater>
                </sf:ConditionalTemplate>
                <sf:ConditionalTemplate Left="SelectorType" Operator="Equal" Right="Vertical" runat="server">
                    <asp:Repeater ID="languagesRepeater" runat="server">
                        <HeaderTemplate>
                            <ul id="langsWrapper" class="sflanguagesVerticalList">
                        </HeaderTemplate>
                        <ItemTemplate>
                            <li runat="server" id="langHolder" class="sflanguageItem">
                                <a runat="server" id="langLink" href=""><span runat="server" id="langName"></span></a>
                            </li>
                        </ItemTemplate>
                        <FooterTemplate>
                            </ul>
                        </FooterTemplate>
                    </asp:Repeater>
                </sf:ConditionalTemplate>
                <sf:ConditionalTemplate Left="SelectorType" Operator="Equal" Right="DropDown" runat="server">
                    <div class="sflanguagesDropDown">
                        <asp:DropDownList runat="server" ID="langsSelect"></asp:DropDownList>
                    </div>
                </sf:ConditionalTemplate>
            </Templates>
        </sf:ConditionalTemplateContainer>
    </div>


    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
  • OK Thanks,

    Now in the  LanguagesRepeater_ItemDataBound  

    CultureInfo ci = (CultureInfo)e.Item.DataItem

    i get that  ci is null.

    But in debug mode i see that "shownLanguages" have two itens (English and Portuguese).
    What's wrong ?

    Another thing is that in debug i get that CultureInfo currentLanguage = Thread.CurrentThread.CurrentUICulture;
    is the english but mi page is backend is the PT translation page.

    thanks again.
  • Hi JV,

    You could check the e.Item.DataItem before you made the cast. Also this control cannot work on backend pages as I described in my previous posts. Since it inherits from the base class LanguageSelectorControl there could be some issues.
    CurrentUICulture shows the culture that is used by resource manager for the user interface.

    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