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

Forums / Developing with Sitefinity / Language selection by flag icon

Language selection by flag icon

23 posts, 0 answered
  1. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    19 Dec 2008
    Link to this post
    Hello Telerik Team

    Instead of using the language selector as listbox I want to select the language by clicking a flag icon (uk flag for english, german flag for german etc)

    I implement it by adding the language prefix to the url.  But I want to know if there is a better way.
    Hope you can help.

    Regards
    Luc
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    20 Dec 2008
    Link to this post
    Hi Luc Baeten,

    Thank you for using our services.

    I also thing that working with the prefix in the url is a good way to do this. I am sending you a user control that represents this behavior in PathPrefix and QueryString persistenceMode.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. s
    s avatar
    3 posts
    Registered:
    03 May 2011
    11 May 2011
    Link to this post
    Hello,

    This control no longer works in version 4.1. Do you have any update for this control? I also need a language selector by flag for the FrontEnd.

    Many thanks
    SP
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    11 May 2011
    Link to this post
    Hi ,

    Yes, because this control is for Sitefinity 3.x. For Sitefinity 4.0 you need to inherit from LanguageSelectorControl

    All the best,
    Ivan Dimitrov
    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
  5. s
    s avatar
    3 posts
    Registered:
    03 May 2011
    11 May 2011
    Link to this post
    I tried that but it's throwing errors, for instance the property "Items" in "this.Items" does not exist. Do you have a code sample?

    Thanks for your prompt reply!
  6. Ibrahim Mehdi
    Ibrahim Mehdi  avatar
    5 posts
    Registered:
    10 Sep 2012
    12 May 2011
    Link to this post
    Thanks Ivan! I have followed your suggestion and it worked perfectly for me.
  7. P
    P avatar
    6 posts
    Registered:
    08 May 2011
    17 May 2011
    Link to this post
    I have the same error. Is it possible to provide a sample?

    Thank you, 
    Alex
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    18 May 2011
    Link to this post
    Hi ,

    Here is a sample code that show show to override the behavior of the public control.

    Kind regards,
    Ivan Dimitrov
    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
  9. s
    s avatar
    3 posts
    Registered:
    03 May 2011
    23 May 2011
    Link to this post
    Hello Ivan,

    I tried to follow the code (copy & paste) in the post you referred, but still can't put it to work.

    When I add the custom control to the template page it throws the following error:

    'SitefinityWebApp.Custom.Controls.LanguageSelectorControl' is not allowed here because it does not extend class 'System.Web.UI.UserControl'

    How do I get around this?
    Thanks
  10. P
    P avatar
    6 posts
    Registered:
    08 May 2011
    23 May 2011
    Link to this post
    Hi

    I receive the same error 'SitefinityWebApp.Custom.Controls.LanguageSelectorControl' is not allowed here because it does not extend class 'System.Web.UI.UserControl' using your code. I have to mention that control is installed in the toolbox. See attachemnts.

    Please give me a solution

    Tranks,
    Alex
  11. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    25 May 2011
    Link to this post
    Hi ,

    You should use a custom control, not a  user control.

    Kind regards,
    Ivan Dimitrov
    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
  12. P
    P avatar
    6 posts
    Registered:
    08 May 2011
    25 May 2011
    Link to this post
    Hi

    I really don't understand what kind of custom control should I use. In all of your samples of how to create new widgets, you are telling us to create user-controls.
    Please provide a fully functional sample so I can understand what and where I'm doing wrong

    Thanks, 
    Alex Pistalu
  13. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    26 May 2011
    Link to this post
    Hello,

    The sample here I am showing how to create custom control that inherits from the base class. This is the same link that is posted several posts above.

    Regards,
    Ivan Dimitrov
    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
  14. P
    P avatar
    6 posts
    Registered:
    08 May 2011
    28 May 2011
    Link to this post
    Hello

    After using your sample code, I set the custom language control into a template used by all the pages. At runtime I receive the following error:

    The current type, Telerik.Sitefinity.Model.IAppSettings, is an interface and cannot be constructed. Are you missing a type mapping?

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.InvalidOperationException: The current type, Telerik.Sitefinity.Model.IAppSettings, is an interface and cannot be constructed. Are you missing a type mapping?

    Source Error: 

    Line 29:         {
    Line 30:             //base.InitializeControls(container);
    Line 31:             var settings = ObjectFactory.Resolve<IAppSettings>();
    Line 32:             List<CultureInfo> languages = new List<CultureInfo>();
    Line 33:             if (this.MissingTranslationAction == NoTranslationAction.HideLink)

    I had to change  with this var settings = ObjectFactory.Resolve<AppSettings>(); After that I had exceptions on repeater's name that it seems to be languagesRepeater_horizontal and languagesRepeater_vertical.
    After changing that I get null value for this.usedLanguages  even though I have 3 languages enabled for that certain frontend page and here I'm stuck.
    Sitefinity is a good solution but when it comes to extending existing page controls let's say, it is really a black box.
    Is it possible to have access cu ascx files of your controls? 
    My problem is that I have to start to use sitefinity for building web sites for my customers, but I'm not sure if this is such a good ideea if I have to extend existing controls and have no access to source code. I cannot wait 48 hours to get your help in this situation.
    Thank you, 
    Alex
  15. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    30 May 2011
    Link to this post
    Hello ,

    You can get the source code if you have Professional or Enterprise edition.  Let me know which template you need and I will attach it here. There are some templates that you can edit directly from the UI using Widget Templates editor. Also you can use Reflector to extract each template.

    Kind regards,
    Ivan Dimitrov
    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
  16. P
    P avatar
    6 posts
    Registered:
    08 May 2011
    30 May 2011
    Link to this post
    Hello 
    I need the template for LanguageSelectorControl. It seems that the one you posted is not up to date.

    Thanks, 
    Alex
  17. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    30 May 2011
    Link to this post
    Hi,

    Here is the latest template

    <%@ 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_horizontal" runat="server">
                        <HeaderTemplate>
                            <ul id="langsWrapper" class="sflanguagesHorizontalList">
                        </HeaderTemplate>
                        <ItemTemplate>
                            <li runat="server" id="langHolder" class="sflanguageItem">
                                <a runat="server" id="langLink" href="" class="sflanguageLnk"><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_vertical" runat="server">
                        <HeaderTemplate>
                            <ul id="langsWrapper" class="sflanguagesVerticalList">
                        </HeaderTemplate>
                        <ItemTemplate>
                            <li runat="server" id="langHolder" class="sflanguageItem">
                                <a runat="server" id="langLink" href="" class="sflanguageLnk"><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="sflanguagesDropDownList">
                        <asp:DropDownList runat="server" ID="langsSelect" CssClass="sflanguagesDropDown"></asp:DropDownList>
                    </div>
                </sf:ConditionalTemplate>
            </Templates>
        </sf:ConditionalTemplateContainer>
    </div>



    All the best,
    Ivan Dimitrov
    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
  18. P
    P avatar
    6 posts
    Registered:
    08 May 2011
    30 May 2011
    Link to this post
    Using this template with the LanguageSelectionControlCustom extension ,I get the following exceptions:

    Resolution of the dependency failed, type = "Telerik.Sitefinity.Model.IAppSettings", name = "(none)".
    Exception occurred while: while resolving.
    Exception is: InvalidOperationException - The current type, Telerik.Sitefinity.Model.IAppSettings, is an interface and cannot be constructed. Are you missing a type mapping?
  19. Stefano
    Stefano avatar
    29 posts
    Registered:
    14 Jun 2011
    07 Jul 2011
    Link to this post
    I have the same error:

    The current type, Telerik.Sitefinity.Model.IAppSettings, is an interface and cannot be constructed. Are you missing a type mapping?



    What can I do?
  20. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    07 Jul 2011
    Link to this post
    Hi Stefano,

    Try using var settings = AppSettings.CurrentSettings; instead.

    Kind regards,
    Ivan Dimitrov
    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
  21. Stefano
    Stefano avatar
    29 posts
    Registered:
    14 Jun 2011
    13 Jul 2011
    Link to this post
    I tried to use var settings = AppSettings.CurrentSettings;  but I have a new error.
  22. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    13 Jul 2011
    Link to this post
    Hi Stefano,

    Please check whether this.usedLanguages is null. It looks like you are trying to add a null item to the list of languages.

    Kind regards,
    Ivan Dimitrov
    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
  23. Stefano
    Stefano avatar
    29 posts
    Registered:
    14 Jun 2011
    13 Jul 2011
    Link to this post

    This is my code:

    namespace LanguagesSelectorControl.WebControl
    {
        public class LanguageSelectorControlCustom : LanguageSelectorControl
        {
      
            protected override string LayoutTemplateName
            {
                get
                {
                    return LanguageSelectorControlCustom.customTemplate;
                }
            }
      
      
      
      
            protected override void InitializeControls(GenericContainer container)
            {
                //base.InitializeControls(container);
                var settings = AppSettings.CurrentSettings;
                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 = "LanguagesSelectorControl.WebControl.Resources.LanguageSelectorControl.ascx";
            private List<CultureInfo> usedLanguages   ;
            private PageNode homePageNode;
        }
      
      
      
    }

    I have to assign something:
    private List<CultureInfo> usedLanguages   ?
Register for webinar
23 posts, 0 answered