Is there a way to localize entries of the navigational breadcrumb?

1 Answer 27 Views
Breadcrumb
kva
Top achievements
Rank 2
Iron
Iron
Iron
kva asked on 01 Sep 2023, 09:05 AM
I have the following breadcrumb:
    @(Html.Kendo().Breadcrumb()
        .Name("breadcrumb")
        .BindToLocation(true)
        .Navigational(true))
When I go to route /Directory/Users/Managers it will show entries: Directory, Users, Managers. Is there a way to localize them to my language?

1 Answer, 1 is accepted

Sort by
1
Accepted
Vasko
Telerik team
answered on 05 Sep 2023, 11:51 AM

Hello,

In order to make the Breadcrumb Items text display in your language (or whatever language you want), you'll have to check what is the selected language culture of your application on the server:

  • In the Controller that loads the current View, create some ViewBag string variables that hold the desired Breadcrumb item text, you can use if ... else or switch() statements to check what the current selected culture is (here I'm using Spanish and English for example):
    using Kendo.Mvc;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.AspNetCore.Mvc.Filters;
    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.Linq;
    using System.Threading.Tasks;
    
    namespace breadcrumb.Controllers
    {
        public class HomeController : Controller
        {
            public IActionResult Index()
            {
                if (/*! Check for a specific language culture */)
                {
                    ViewBag.item1Text = "Hola";
                    ViewBag.item2Text = "Amigo";
    
                }
                else if (/*! Check for another specific language culture */)
                {
                    ViewBag.item1Text = "Hi";
                    ViewBag.item2Text = "Friend";
                }
    
                return View();
            }
        }
    }
    
  • In the given View, use the ViewBag.item1Text, ViewBag.item2Text in the Breadcrumb (in this example, my given View is the Index page): 
    @(Html.Kendo().Breadcrumb()
        .Name("breadcrumb")
        .Items(items =>
        {
            items.Add()
                .Type(BreadcrumbItemType.RootItem)
                .Text(ViewBag.item1Text)
                .ShowText(true)
                .Icon("home");
            items.Add()
                .Type(BreadcrumbItemType.Item)
                .Text(ViewBag.item2Text);
        })
    )

This approach will work with whatever language culture you set in the if () statement to be checked.
I hope this response is helpful. Feel free to contact us again if more questions arise.

Kind regards,
Vasko
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages. If you're new to the Telerik family, be sure to check out our getting started resources, as well as the only REPL playground for creating, saving, running, and sharing server-side code.
Tags
Breadcrumb
Asked by
kva
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Vasko
Telerik team
Share this question
or