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

Forums / General Discussions / Language selector

Language selector

10 posts, 0 answered
  1. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    30 Jan 2011
    Link to this post
    Hi all,

    I'm curious how to start with this:

    I want to use the Language Selector widget inside my template. I do not want to use the default layout, but for each language I want to show an image (which is the country flag).

    I'm sure this would be possible, but what is the best practice in this?

    How can I create a custom template for this, and what should be in it?

    Regards,
    Daniel
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    31 Jan 2011
    Link to this post
    Hi Daniel,

    This is possible with a custom control where you can set the flag inside ItemDataBound or ItemCreated events of the repeater. Please check this post.

    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
  3. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    31 Jan 2011
    Link to this post
    Hi Ivan,

    Should I set this up as a module, like e.g. the NewsRotator or Jobs modules, or as a widget?
    Which example can I take as lead?

    Regards,
    Daniel
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    31 Jan 2011
    Link to this post
    Hello Daniel,

    It should be a widget.

    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
  5. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    31 Jan 2011
    Link to this post
    Hi Ivan,

    Okay, I have managed to:

    - Create a new widget with a repeater that shows the languages
    - For each language a flag is shown instead of text

    The only thing now is how to concat the right URL's for the links?
    If I click on a language, what should happen? Can I get these URL's from somewhere?

    Regards,
    Daniel
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    03 Feb 2011
    Link to this post
    Hi Daniel,

    Create an instance of ObjectFactory.Resolve<UrlLocalizationService>();. Then you can use ResolvePageUrl method - Returns the URL for the specified language version of the specified page, using the current url strategy. This method will work for pages in SPLIT mode - it will return correct URL for the desired language no matter which of the different language nodes you specify as an argument.

    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
  7. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    03 Feb 2011
    Link to this post
    Hi Ivan,

    Thanks for the help.
    I've set up this code in my ItemDataBound of the Repeater:

    /// <summary>
            /// Fires on ItemDataBound
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            protected void languagesRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
            {
                try
                {
                    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                    {
                        CultureInfo item = e.Item.DataItem as CultureInfo;
                        Image imgLanguage = e.Item.FindControl("imgLanguage") as Image;
                        HyperLink lnkLanguage = e.Item.FindControl("lnkLanguage") as HyperLink;
     
                        // Set image properties
                        imgLanguage.ImageUrl = "~/Assets/Img/Lang/" + item.TwoLetterISOLanguageName + ".jpg";
                        imgLanguage.ToolTip = item.DisplayName;
     
                        // Set hyperlink properties
                        UrlLocalizationService s = ObjectFactory.Resolve<UrlLocalizationService>();
                        lnkLanguage.NavigateUrl = s.ResolvePageUrl(GetCurrentPage(), item);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

    The function 'GetCurrentPage' returns NULL, so there is no current node. How can I achieve this?

    /// <summary>
    /// Get the current pagenode
    /// </summary>
    /// <returns></returns>
    private PageNode GetCurrentPage()
    {
       try
       {
          SiteMapNode currentNode = SiteMapBase.GetCurrentProvider().CurrentNode();
          PageSiteNode node = (PageSiteNode)currentNode;
          return App.WorkWith().Pages().Where(p => p.UrlName == node.UrlName).Get().FirstOrDefault();
       }
       catch (Exception ex)
       {
          throw ex;
       }
    }

    Also, if I use:

    PageSiteNode p = SiteMapBase.GetActualCurrentNode();

    ... it returns NULL.

    What can this be?

    Thanks!
    Daniel


  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    03 Feb 2011
    Link to this post
    Hello Daniel,

    Try using this code

    var actualSitemapNode = SiteMapBase.GetActualCurrentNode();
     
     PageManager pm = PageManager.GetManager();
     
     var homePageId = Config.Get<PagesConfig>().HomePageId;
     IEnumerable<CultureInfo> availableLanguages = null;
     
     Guid nodeId;
     if (actualSitemapNode != null)
     {
         nodeId = actualSitemapNode.Id;
     }
     else
     {
         nodeId = homePageId;
     }
     
     
     this.node = pm.GetPageNode(nodeId);
     
     if (actualSitemapNode != null)
     {
         availableLanguages = actualSitemapNode.AvailableLanguages;
     }
     else
     {
         availableLanguages = this.node.AvailableCultures;
     }

    The node should exist on the current language.

    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
  9. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    03 Feb 2011
    Link to this post
    Thanks Ivan, that worked!
    Is this all I have to do to select another language? I also have seen some code examples where the CultureInfo was set on the current thread?

    Regards,
    Daniel
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    04 Feb 2011
    Link to this post
    Hello Daniel,

    You should set the CurrrentUICulture to get the pages for the proper language.

    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
10 posts, 0 answered