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

Multilingual column header text

4 Answers 362 Views
GridView
This is a migrated thread and some comments may be shown as answers.
pierre-jean
Top achievements
Rank 1
Veteran
Iron
pierre-jean asked on 12 Dec 2016, 06:37 PM
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

4 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 13 Dec 2016, 07:48 AM
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.
0
pierre-jean
Top achievements
Rank 1
Veteran
Iron
answered on 13 Dec 2016, 04:12 PM
OK thanks I hope ther wiil be soon a better solution than the programmatically one
0
Andrea
Top achievements
Rank 1
answered on 16 Dec 2016, 11:27 AM

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

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 19 Dec 2016, 12:23 PM
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.
Tags
GridView
Asked by
pierre-jean
Top achievements
Rank 1
Veteran
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
pierre-jean
Top achievements
Rank 1
Veteran
Iron
Andrea
Top achievements
Rank 1
Share this question
or