This is a migrated thread and some comments may be shown as answers.

Column command localization in grid dont work

1 Answer 113 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michel
Top achievements
Rank 1
Michel asked on 29 Jun 2016, 05:35 PM

I use UI for ASP.NET MVC Q2 2016.

I cannot figure out how to localize the edit and destroy button in the column command of my grid.

My app is using asp.net core rc2

I have include the localization feature using resource.

The default culture is en-US as stated in startup.cs

    options.DefaultRequestCulture = new RequestCulture(culture: "en-US", uiCulture: "en-US");

In the Model I manage the localization with resources file "...en-US.resx"

    public class TA_ACCESSORY_ACC
    {

    [MaxLength(ApplicationDbOperation.DM_SHORTTEXT, ErrorMessage = "idsMaxError")]
    [Display(ResourceType = typeof(ApplicationResources),Name = "idsName")]
    public string NAME_ACC { get; set; }

   }

The column of the grid are well translated from french to English but the button command still remain in french.

Any help will be very appreciated.

 

1 Answer, 1 is accepted

Sort by
0
Michel
Top achievements
Rank 1
answered on 29 Jun 2016, 07:35 PM

It is not so difficult when you have found.

In Startup.cs

...........
   // Add the localization services to the services container
   services.AddLocalization(options => options.ResourcesPath = "Resources");

...........
In Solution explorer
  Add a folder "Resources", add a subfolder in it "Views" add a subfolder in it "MyModel"
  In this folder add a resource file with the name of the cshtml file containing the grid you want to localize "Index.fr.res" for french localization of index.cshtml view of the MyModel class and include the string you want to translate :
    <data name="idsName" xml:space="preserve">
     <value>Nom</value>
    </data>

In the index.cshtml view file add these lines
  @using Microsoft.AspNetCore.Mvc.Localization
  @inject IViewLocalizer Localizer
...

  @(Html.Kendo().Grid(Model)
      .Name("myGrid")
      .Columns(columns =>
      {
        columns.Bound(model => model.MyField);
        columns.Command(commands =>
        {
            commands.Edit().Text(@Localizer["idsName"].Value);
        }).Title("Commands").Width(200);
    })
   .Editable(editable => editable.Mode(GridEditMode.PopUp))
   .DataSource(dataSource => dataSource
   .Ajax())
   )

Tags
Grid
Asked by
Michel
Top achievements
Rank 1
Answers by
Michel
Top achievements
Rank 1
Share this question
or