Code-behind localization using extension methods (via ResourceManager)

5 posts, 1 answers
  1. Answer
    Telerik Admin
    Telerik Admin avatar
    1679 posts
    Member since:
    Oct 2004

    Posted 16 Sep 2009 Link to this post

    Requirements

    RadControls version

    2009 Q1 +
    .NET version

    3.5
    Visual Studio version

    2005 and later
    programming language

    C#
    browser support

    all browsers supported by RadControls


    PROJECT DESCRIPTION

    Author:
    Walter van Leur  (Walter) 
     
    The solution I’ve attached contains a project “TelerikRadGridLocalization” that does the localization of a RadGrid with the use of resource-files from codebehind. There are two resource-files. One for english and one for dutch language. There is another project (Demo) that demonstrates the use of the localization by showing a RadGrid on the Customers in the Nwind-db.

    How to use:

    §  Add project “TelerikRadGridLocalization” to your solution

    §  Add reference to project “TelerikRadGridLocalization”

    §  Add a RadGrid (for example ID="RadGrid1") to your page (for example default.aspx)

    §  In code-behind of that page (default.aspx.cs):

    ·         Add the following to to the Page_load():

    o    RadGrid1.Localize();
    This does the localization of most RadGrid-elements

    ·         Add the following to the OnPreRenderComplete():

    o    RadGrid1.HeaderContextMenu.Localize();  
    This does the localization of  the HeaderContextMenu


    Example:
    protected void Page_Load(object sender, EventArgs e) 
        RadGrid1.Localize(); 
     
    protected override void OnPreRenderComplete(EventArgs e) 
     
        base.OnPreRenderComplete(e); 
        //Translate the RadGrid's HeaderContextMenu 
        RadGrid1.HeaderContextMenu.Localize(); 
    }

    o    How it works:

    §  In project “TelerikRadGridLocalization” there is a class “RadGridLocalize” which contains extensions-mehods on the Radgrid.
    The method “
    Localize(this RadGrid radGrid)” calls the other localize-methods on the different elements of a Radgrid (such as the FilterMenu, SortingSettings etc…).

    §  Fot the localization of a RadGrid you can do a “RadGrid1.Localize()” in the Page_load of the page. To have the HeaderContextMenu localized you’ll have to do a “RadGrid1.HeaderContextMenu.Localize()” in the OnPreRenderComplete because the HeaderContextMenu isn’t yet available in the Page-Load.

    o    To see the dutch-localization working:

    §  Notice that in web.config the following is set to use the culture of the browser:

    ·         <globalization culture="Auto" uiCulture="Auto" />

    §   Run the solution

    §  Set the language to dutch in the browser:

    ·          Internet Explorer; Tools; Internet Options; Languages

    o     Add language “dutch (nl-NL)”

    o    refresh the page

    §  See the “Screenshot demo in dutch.docx”


  2. Hendrik
    Hendrik avatar
    23 posts
    Member since:
    Jan 2008

    Posted 11 May 2010 Link to this post

    Why the doesn't RadGrid support localization using Recourse files by default? I hope to see this feature being added to RadGrid in the near future. For the time being: great work Walter. Just what I needed/wanted.
  3. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 11 May 2010 Link to this post

    Hello Hendrik,

    You can find sample RadGrid localization file in this code library thread:
    http://www.telerik.com/community/code-library/aspnet-ajax/localization/localization-files-for-radgrid-radcalendar-and-radinput.aspx

    We will expose complete RadGrid for ASP.NET AJAX localization through resource files for the upcoming Q2 2010 release of the product, expected in the middle of July.

    Best regards,
    Sebastian
    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.
  4. Ron
    Ron  avatar
    16 posts
    Member since:
    Aug 2008

    Posted 21 Jun 2011 Link to this post

    Hi,

    Is grid localization using recourse files by default already available? It seems that it's still not working without setting the culture property manually
    Thanks,
    Ron
  5. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 21 Jun 2011 Link to this post

    Hello Ron ,

    Indeed presently you need to set the Culture property of the grid explicitly to pick up the localization strings from resource files (if available).

    However, you may be happy to know that this will not be required for the next version of the control (Q2 2011), expected in the middle of the next month. It will accept the localization of the current thread by default while the Culture property can be used to specify it should differ from that set for the current thread.

    Best regards,
    Sebastian
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Back to Top