Multilingual column header text

5 posts, 0 answers
  1. pierre-jean
    pierre-jean avatar
    146 posts
    Member since:
    Apr 2011

    Posted 12 Dec 2016 Link to this post

    I am building an Winforms application where the user can select his interface language (en, fr) I managed to translate about all items but not the grid column header texts.
    Is there a way to load the column headers from a resource file ? Or how should it be done ?

    Thanks in advance

  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    4077 posts

    Posted 13 Dec 2016 Link to this post

    Hello Pierre-Jean,

    Thank you for writing.  

    This a known issue when localizing RadGridView's column headers. You can track its progress, subscribe for status changes and add your comments on the following link - feedback item.

    Currently, the possible solution that I can suggest is to set the HeaderText programmatically according to the current language.

    I hope this information helps. Should you have further questions I would be glad to help.

    Regards,
    Dess
    Telerik by Progress
    Telerik UI for WinForms is ready for Visual Studio 2017 RC! Learn more.
  3. pierre-jean
    pierre-jean avatar
    146 posts
    Member since:
    Apr 2011

    Posted 13 Dec 2016 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    OK thanks I hope ther wiil be soon a better solution than the programmatically one
  4. Andrea
    Andrea avatar
    75 posts
    Member since:
    Oct 2012

    Posted 16 Dec 2016 in reply to pierre-jean Link to this post

    Hi my approach is to store model's translation by using DisplayAttributes,

    for example

    class XYZ{
    [Display(Name = "MyDisplayName", ResourceType=typeof(MyResourceFileName))]
    public String ArbitrationLong
    {
        get; set;
    }

    ///...

    }


    then on the resource file MyResourceFileName add the  properties translation.

    the above tecnique is quite useful, many tools automatically interpret them correctly, if you will use your class on an ASP.NET MVC all the helpers will automatically translate your labels, and also the telerik kendo ui grid is able to automatically use the correct grid header if your model have such attributes.

    To return to telerik grid on winforms, at the time i don't think the telerik grid for winforms is automatically able to use the model's attributes, but you just need the above snippet they are few lines of code  : It works for ITypedList datasources, otherwise you could retrieve the properties using reflection, what you have to modify is the first row on the above snippet all the other code remain the same, you can store the above snipped in any static function and call it as is, it needs a list of properties and a grid as parameters.

        var props = (TheList as ITypedList).GetItemProperties(null);
     
        foreach (var column in theGrid.Columns)
        {
            var cprop = props.Find(column.FieldName, true);
            if (cprop != null)
            {
                var display = cprop.Attributes.OfType<DisplayAttribute>().FirstOrDefault();
                if (display != null)
                {
                    if (display.ResourceType == null)
                        column.HeaderText = display.Name;
                    else
                    {
                        var dprop = display.ResourceType.GetProperty(display.Name, BindingFlags.Public | BindingFlags.Static);
                        if (dprop == null)
                            column.HeaderText = display.Name;
                        else
                            column.HeaderText = dprop.GetValue(null, null).ToString();
                    }
                }
            }
        }

    Best Regards

  5. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    4077 posts

    Posted 19 Dec 2016 Link to this post

    Hello Andrea, 

    Thank you for writing back. 

    The provided sample code snippet is greatly appreciated. We will consider it when addressing the feedback item.

    If you have any additional questions, please let me know. 

    Regards,
    Dess
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top