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

[Solved] localization of column title using resource files

9 Answers 156 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Marco
Top achievements
Rank 1
Marco asked on 06 Apr 2010, 02:53 PM
hello i was wondering if someone have implemented a localization of column titles and how you do that?

i was thinking in controller to get column names using a $.getJSON passing the key of recourse file.

then on controller action i will use a resource manager to retrieve the string to client side.

but i'm not sure that this would be the better way to achieve this.

it would be a great help to me if you explain how are do doing this.

Best Regards
Marco

9 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 06 Apr 2010, 06:16 PM
Hi Marco,

You can use title property of the column to localize column header. Here is a code snippet showing how to achieve this:
columns.Bound(o => o.OrderDate).Title("Localized value");

Regards,
Georgi Krustev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Marco
Top achievements
Rank 1
answered on 06 Apr 2010, 10:16 PM
hello Georgi,

maybe i misunderstood.

i know that its possible to set the title using title property, but what i really want to know is a way to be able to call resource files in property title.

is there a way to do something like    
columns.Bound(o => o.OrderDate).Title("App_GlobalResources.Resources.resourseKey");

like we do on client templates 

columns.Bound(o => o.OrderDate).ClientTemplate("<#= o.xpto #>")

i know that this does't make any sense because client template get an object from gridModel.

but i i'm asking for the best way to do client localization.

what i'm thinking is a way to use a $.get or $.getJSON to call a action on a base controller passing the key of .resx file, and retrieve the localized string to view

something like 

columns.Bound(o => o.OrderDate).Title($.getJSON('baseController/getString'{key:'sameKey'}));
but this way i think the response will be a xml http response and not a string. to get a string i should use a callback function.

but this way it would be more difficult because i would need to get the html header of column...

Can you please tell me what should be the best way to achieve this.

I hope to be clear enough, if not please say it.
i can try a better way to explain myself.

Best Regards 
Marco  





0
Atanas Korchev
Telerik team
answered on 07 Apr 2010, 07:42 AM
Hello Marco,

You should use the built-in ASP.NET localization. Check this stackoverflow entry for addtiional info.

Greetings,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Marco
Top achievements
Rank 1
answered on 07 Apr 2010, 10:33 AM
hello Atanas,

I have my application already localized using resource files. my only problem is how to call resources in the title property.

can you please post a sample, i have tried several approaches  but none of then works.

i always get an error when trying to render the view.

Hope you could help me.

Regards
Marco


0
Atanas Korchev
Telerik team
answered on 07 Apr 2010, 11:06 AM
Hello Marco,

Did you check the provided URL? It links to a very detailed blog post which shows how to use the resx files. You can also check this forum post which shows a different approach (using Resources.*). This forum post also discusses a valid approach. With all approaches you just need to set the Title of the column - all of them provide some API to return a localized string value based on some key.

By the way how are you using the resource strings in your ASP.NET MVC application (when not localizing the grid)?

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Marco
Top achievements
Rank 1
answered on 07 Apr 2010, 12:17 PM
yes i have seen the post you mentioned and i have tried to localize your grid using it.

but whit no success.

i have added the namespace of resources to my webconfig and i'm able to use resouce files 
for example 

<label title="<%=Resources.Welcome%>">Test</label>

and this is working

I think the problem is on this chars <%= when i try to put it inside title column i always get an error when rendering grid.

error: Newline in constant

could you show me a sample how to do this on grid column title?

Best Regards
0
Atanas Korchev
Telerik team
answered on 07 Apr 2010, 02:15 PM
Hi Marco,

The sample would be

columns.Bound(c => c.CustomerID).Title(Resources.Welcome)

There is no need for <%= %> as it is used only for outputting values to the result HTML (it is a shortcut to Response.Write actually).

Greetings,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Marco
Top achievements
Rank 1
answered on 07 Apr 2010, 02:35 PM
Hello Atanas, thats exactly what i need.

thanks a lot.

do you know what this exception means?
system.Resources.MissingManifestResourceException 

now this exception is being launch.

Best Regards
Marco
0
Atanas Korchev
Telerik team
answered on 07 Apr 2010, 03:09 PM
Hello Marco,

No, I do not. Please try searching in google for that exception.

Sincerely yours,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Marco
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Marco
Top achievements
Rank 1
Atanas Korchev
Telerik team
Share this question
or