kendo UI for asp.net 核心是否为其按钮上的文本提供默认本地化?

Does kendo UI for asp.net core provide default localization for text on its buttons?

我读过 the article about localization。据我了解,kendo 为不同文化的按钮中的文本提供了本地化。我做了文章里写的,指定俄语,但是按钮没有翻译。

_Layout:

@using Microsoft.AspNetCore.Mvc.Localization
@inject IViewLocalizer _localizer

@{
    const string appName = "Accounter";
}

<!DOCTYPE html>
<html lang="ru">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>@_localizer[(string)ViewData["Title"]] - @appName</title>

    <link rel="apple-touch-icon" sizes="180x180" href="icons/apple-touch-icon.png">
    <link rel="icon" type="image/png" sizes="32x32" href="icons/favicon-32x32.png">
    <link rel="icon" type="image/png" sizes="16x16" href="icons/favicon-16x16.png">
    @* <link rel="manifest" href="icons/site.webmanifest"> *@

    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"
          integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous"/>


    <script src="~/lib/jquery/dist/jquery.min.js"></script>
    <script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
    <script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>

    <script src="~/js/layout.js"></script>


    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2022.1.412/styles/kendo.bootstrap-v4.min.css"/>
    <script src="https://kendo.cdn.telerik.com/2022.1.412/js/kendo.all.min.js"></script>
    <script src="https://kendo.cdn.telerik.com/2022.1.412/js/kendo.aspnetmvc.min.js"></script>

    <script src="https://kendo.cdn.telerik.com/2022.1.412/js/cultures/kendo.culture.ru.min.js"></script>
    <script src="https://kendo.cdn.telerik.com/2022.1.412/js/cultures/kendo.culture.en.min.js"></script>
    <script>kendo.culture("ru");</script>
    
    <link rel="stylesheet" href="~/css/site.css"/>
</head>
<body>
<header>
    <nav class="navbar navbar-expand navbar-light">
        <div class="container">
            <a class="navbar-brand" asp-action="Index" asp-controller="GeneralInformation">@appName</a>
            <div class="navbar-nav">
                @if (User.Identity.IsAuthenticated)
                {
                    <a class="nav-link text-dark" asp-controller="Authentication" asp-action="LogOut">@_localizer["Log out"]</a>
                }
                else
                {
                    <a class="nav-link text-dark" asp-controller="Authentication" asp-action="Index">@_localizer["Log in"]</a>
                }
            </div>
            <partial name="_SelectLanguagePartial"/>
        </div>
    </nav>
</header>
<div></div>
<div class="pt-5 backdrop">
    <div class="container rounded-3 p-3">
        <main role="main">
            @RenderBody()
        </main>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
        integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous">
</script>

@await RenderSectionAsync("Scripts", false)
</body>
</html>

网格的使用:

@{
var grid = Html.Kendo().Grid<UserVM>()
    .Name("Grid")
    .DataSource(dataSource => dataSource
        .Ajax()
        .Events(events => events.Error("gridError"))
        .PageSize(10)
        .ServerOperation(false)
        .Model(model =>
        {
            model.Id(e => e.Id);
            model.Field(e => e.Role).DefaultValue((RoleVM)ViewData["DefaultRole"]);
        })
        .Read("Read", "GeneralInformation")
        .Create("Read", "GeneralInformation")
        .Update("Update", "GeneralInformation")
        .Destroy("Delete", "GeneralInformation")
    )
    .Columns(columns =>
    {
        columns.Bound(e => e.FullName).Title(_userLocalizer["Full name"]);
        columns.Bound(e => e.Role.Name).Title(_userLocalizer["Role"]).EditorTemplateName("RoleEditor");
        columns.Bound(e => e.Position).Title(_userLocalizer["Position"]);
        columns.Bound(e => e.PhoneNumber).Title(_userLocalizer["Phone number"]);
        columns.Bound(e => e.Email).Title(_userLocalizer["Email"]);
    })
    .Editable(GridEditMode.InLine)
    .Sortable()
    .Pageable(pager => pager
        .Input(true)
        .PageSizes(true)
    )
    .Scrollable(scroll => scroll
        .Virtual(GridVirtualizationMode.RowsAndColumns)
    );

    if (User.IsInRole("Administrator"))
    {
        grid
            .Columns(columns =>
            {
                columns.Command(command =>
                {
                    command.Edit().HtmlAttributes(new { @class = "mb-2 mb-xxl-0" });
                    command.Destroy();
                });
            })
            .ToolBar(toolbar => { toolbar.Create(); });
    }

    if (!User.IsInRole("Employee"))
    {
        grid.ToolBar(toolbar => { toolbar.Search(); });
    }
}

@grid

在控制器中设置文化:

public override void OnActionExecuting(ActionExecutingContext context)
{
    CultureInfo.DefaultThreadCurrentCulture = CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("ru");
    base.OnActionExecuting(context);
}

再次尝试在视图中添加区域性:

@{
   var culture = System.Globalization.CultureInfo.CurrentCulture;
}

<script>
        kendo.culture("@culture");
</script>

是的,它提供本地化,但仅限于按钮上的文本。搜索字段上的提示文本未翻译。俄语本地化的问题是正确的文化名称是 ru-RU。所以需要改成这样:

public override void OnActionExecuting(ActionExecutingContext context)
{
    CultureInfo.DefaultThreadCurrentCulture = CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("ru-RU");
    base.OnActionExecuting(context);
}
<script src="https://kendo.cdn.telerik.com/2022.1.412/js/cultures/kendo.culture.ru-RU.min.js"></script>
<script>kendo.culture("ru-RU");</script>