More in this section

Forums / General Discussions / Issues With Language selector...

Issues With Language selector...

7 posts, 0 answered
  1. Vaiga
    Vaiga avatar
    26 posts
    Registered:
    27 Feb 2012
    27 Feb 2012
    Link to this post
    Hi All,
      Am new with sitefinity and am using sitefinity 4.4.I have some doubts.Can any one give me
      answers for my doubts.
        
       1. I am using widget "Language selector". And want to remove country name from html because I am using flags. How Is it possible?.
     
    2. Do I have to manually translate the pages from one to another language or does   Sitefinity manage that itself [Which is same Google transilations].

    Regards
     Sanoop
  2. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    27 Feb 2012
    Link to this post
    Hi Sanoop,

    Regarding your questions:

    1. I had the same challenge and ended up building my own LanguageSelector. I'm sure it is possible somehow, but because of time, it suited my better to build something specific for my website. If you want an example, let me know.
    2. You have to manually translate the pages into the desired languages.

    Regards,
    Daniel
  3. Vaiga
    Vaiga avatar
    26 posts
    Registered:
    27 Feb 2012
    27 Feb 2012
    Link to this post

    Hi Daniel
               Thanks for your response.. Can you please give me a sample code.

    Regards

    Sanoop
         
  4. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    27 Feb 2012
    Link to this post
    Hi Sanoop,

    Sure, here you go:

    LanguageSelector.ascx
    <ul class="language-list">
        <asp:Repeater ID="LanguagesRepeater" runat="server">
            <ItemTemplate>
                <li runat="server" id="activeLanguage">
                    <asp:HyperLink ID="lnkLanguage" runat="server"></asp:HyperLink>
                </li>
            </ItemTemplate>
        </asp:Repeater>
    </ul>

    LanguageSelector.cs
    public partial class LanguageSelector : System.Web.UI.UserControl {
     
            protected void Page_Load(object sender, EventArgs e) {
                BindData();
            }
     
            private void BindData() {
     
                var settings = AppSettings.CurrentSettings;
                List<CultureInfo> languages = new List<CultureInfo>();
                languages.AddRange(settings.DefinedFrontendLanguages);
                PageManager pm = PageManager.GetManager();
                var homePageId = Config.Get<PagesConfig>().HomePageId;
                if (homePageId != Guid.Empty) {
                    this.homePageNode = pm.GetPageNode(homePageId);
                }
     
                IEnumerable<CultureInfo> shownLanguages;
                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, RepeaterItemEventArgs e) {
     
                CultureInfo ci = (CultureInfo)e.Item.DataItem;
                var lnkLanguage = e.Item.FindControl("lnkLanguage") as HyperLink;
                lnkLanguage.CssClass = ci.DisplayName.ToLower();
     
                // Set hyperlink properties
                UrlLocalizationService s = ObjectFactory.Resolve<UrlLocalizationService>();
                var currentPage = GetCurrentPage();
                if (currentPage.AvailableCultures.Contains(ci)) {
                    lnkLanguage.NavigateUrl = s.ResolvePageUrl(currentPage, ci);
                } else {
                    lnkLanguage.NavigateUrl = s.ResolvePageUrl(currentPage, AppSettings.CurrentSettings.DefaultFrontendLanguage);
                }
     
                var activeLanguage = e.Item.FindControl("activeLanguage") as HtmlGenericControl;
                if (ci == Thread.CurrentThread.CurrentCulture)
                    activeLanguage.Attributes.Add("class", "active");
                else
                    activeLanguage.Attributes.Clear();
            }
     
            /// <summary>
            /// Get the current page
            /// </summary>
            /// <returns></returns>
            private PageNode GetCurrentPage() {
                try {
                    PageManager pm = PageManager.GetManager();
                    var actualSitemapNode = SiteMapBase.GetActualCurrentNode();
                    var homePageId = Config.Get<PagesConfig>().HomePageId;
     
                    Guid nodeId;
                    if (actualSitemapNode != null)
                        nodeId = actualSitemapNode.Id;
                    else
                        nodeId = homePageId;
     
                    return pm.GetPageNode(nodeId);
                } catch (Exception ex) {
                    throw ex;
                }
            }
     
            private Telerik.Sitefinity.Pages.Model.PageNode homePageNode;
     
        }

    Just register the new widget in your toolbox somewhere.
    Of course you should do some styling on the <ul> to show your flags.

    Regards,
    Daniel
  5. Pretty
    Pretty avatar
    8 posts
    Registered:
    08 Feb 2012
    29 Feb 2012
    Link to this post
    Hi Team,
              I have the some issues with language selector.am using sitefinity 4.4.am add language selector widjet to my application and add two languages from admin side one English and another Spanish.Set English language as default.
              After this settings,on 'Pages' page i have 2 options under transilation menu one for English and another for Spanish.In this English is active and Spanish is not active.When i select the Spanish,ask me to create new page.Am do the same and select 'copy content from other language' option.Now on that page under transilation menu  both English and Spanish options are active.Then when i select view page in Spanish language,content of that page is still in English language and also some content is missing.Give me some good solutions for resolve my issues.
         
                I have one more doubt,in my application it contains more than 300 page which is in English language.Do i needs to  create seperate pages for Spanish lanuguage.

    Regards
       Pretty


  6. Vaiga
    Vaiga avatar
    26 posts
    Registered:
    27 Feb 2012
    01 Mar 2012
    Link to this post
    Hi Daniel,
         First thanks for your sample code,but still facing some trouble....
                    Am created a new user control and just copy paste your sample code.But there is some issues with namespaces.Can you please send me all the needed name spaces for your sample code.
     Anyway once  again thanks for your valuable instructions....
    Regards
    Sanoop


     
      
  7. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    01 Mar 2012
    Link to this post
    Hi Sanoop,
    You probably can resolve them all from the Telerik.Sitefinity namespace?
    Anyway, hereby the namespaces I use inside this widget:

    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.Linq;
    using System.Threading;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using Telerik.Sitefinity.Abstractions;
    using Telerik.Sitefinity.Configuration;
    using Telerik.Sitefinity.Localization.UrlLocalizationStrategies;
    using Telerik.Sitefinity.Modules.Pages;
    using Telerik.Sitefinity.Modules.Pages.Configuration;
    using Telerik.Sitefinity.Pages.Model;
    using Telerik.Sitefinity.Web;

    Cheers,
    Daniel
7 posts, 0 answered