Small width layout Medium width layout Maximum width layout Small text Medium text Large text
     Search
Downloads Downloads Directory Directory Forums Forums Forge Forge Blogs Blogs        Marketplace Marketplace Careers Program Careers
Community › Forums Register  |  

ExactTarget - What's Your Score
  Need Help?  
Professional technical support for DotNetNuke is available from DotNetNuke Corporation.
 


  Ads  
Webhost4Life - $4.95 Windows Hosting
 


  Sponsors  

Meet Our Sponsors

OnyakTech
The best choice for your web site host, email hosting, and domain registration.
CrystalTech Web Hosting™
Webhost4life, specialists in DNN hosting
Mad Development is a full service interactive agency focusing on the merge of design, technology, e-commerce, and affiliate marketing by providing total website solutions.
MadCap Software, Inc.
 


DotNetNuke Forums
 
  Forum  DotNetNuke® Pro...  Language Packs ...  Localization of GridView Including CommandField Buttons
Previous Previous
 
Next Next
New Post 12/29/2006 5:28 AM
User is offline William Severance
582 posts
www.wesnetdesigns.com
8th Ranked




Localization of GridView Including CommandField Buttons 
Modified By William Severance  on 12/29/2006 9:29:19 AM)

Needing to localize a GridView control's header text as well as the captions on the buttons in a CommandField, I wrote the following:

Public Shared Sub LocalizeGridView(ByVal gv As GridView, ByVal ResourceFile As String)
     Dim key As String
     Dim localizedText As String
     Dim pi As System.Reflection.PropertyInfo

     For Each col As DataControlField In gv.Columns
           key = col.HeaderText
           If key <> "" Then
               localizedText = Localization.GetString(key & ".Header", ResourceFile)
               If localizedText <> "" Then
                   col.HeaderText = localizedText
               End If
           End If

           'Localize text of Cancel, Delete, Edit, Insert, Select, New, Update buttons
           If TypeOf col Is CommandField Then
                Dim cmdField As CommandField = DirectCast(col, CommandField)
                For Each cmdName As String In New String() {"Cancel", "Delete", "Edit", "Insert", "Select", "New", "Update"}
                      pi = cmdField.GetType.GetProperty(cmdName & "Text", GetType(String))
                      key = CType(pi.GetValue(cmdField, Nothing), String)
                      If Not String.IsNullOrEmpty(key) Then
                          localizedText = Localization.GetString(key & ".CommandText", ResourceFile)
                          If localizedText <> "" Then
                               pi.SetValue(cmdField, localizedText, Nothing)
                          End If
                      End If
               Next
          End If
     Next
End Sub

In the local resource file, the keys for Header text should end with .Header while the keys for the CommandField button captions should end with .CommandText. In a CommandField, the EditText, CancelText, etc. default to "Edit", "Cancel", etc. so unless the defaults are overridden in the CommandField declaration, use keys of "Edit.CommandText", "Cancel.CommandText", etc. in the resource file.

I'm not sure if my use of reflection in getting and setting the captions of the CommandField buttons is the most efficient performance wise, it was quick to write using fewer statements.

Hope this is helpful to someone!


Bill, WESNet Designs
 
New Post 4/22/2007 8:02 AM
User is offline Fuji Nguyen
189 posts
9th Ranked




Re: Localization of GridView Including CommandField Buttons 

First thank your for sharing the code.  Using reflection is very cool.  I tried and it worked great.


Fuji Nguyen
FREE Visitor Hit Counter
Visit opensource.indyneinc.com for detail.
 
New Post 8/30/2007 1:14 AM
User is offline Cyber In Love
2 posts
10th Ranked


Re: Localization of GridView Including CommandField Buttons 

Could you show me the way to translate in to C# language.

I tried to translate:

 private void LocalizeGridView(GridView gv)
        {
            string key;
            string localizedText;
            System.Reflection.PropertyInfo pi;
            foreach (DataControlField col in gv.Columns)
            {
                key = col.HeaderText;
                if (key != "")
                {
                    localizedText = Localization.GetString(key + ".Header", this.LocalResourceFile);
                    if (localizedText != "")
                    {
                        col.HeaderText = localizedText;
                    }
                }
                //Localize text of Cancel, Delete, Edit, Insert, Select, New, Update buttons
                if (col is CommandField)
                {
                    CommandField cmdField = (CommandField)col;
                    string[] strCommandName = new string[4] {"Cancel", "Delete", "Edit", "Update"};
                    foreach (string cmdName in strCommandName)
                    {
                         pi = cmdField.GetType.GetProperty(cmdName & "Text", GetType(String))
                        key = pi.GetValue(cmdField, null).ToString();
                        if (string.IsNullOrEmpty(key) == false)
                        {
                            localizedText = Localization.GetString(key + ".CommandText", this.LocalResourceFile);
                            if (localizedText != "")
                            {
                                pi.SetValue(cmdField, localizedText, null);
                            }
                        }
                    }
                }
            }

}

 

Help me convert red code !

 

 
New Post 8/30/2007 1:30 AM
User is offline Cyber In Love
2 posts
10th Ranked


Re: Localization of GridView Including CommandField Buttons 

 imagemaker wrote

Needing to localize a GridView control's header text as well as the captions on the buttons in a CommandField, I wrote the following:

Public Shared Sub LocalizeGridView(ByVal gv As GridView, ByVal ResourceFile As String)
Dim key As String
Dim localizedText As String
Dim pi As System.Reflection.PropertyInfo

For Each col As DataControlField In gv.Columns
key = col.HeaderText
If key <> "" Then
localizedText = Localization.GetString(key & ".Header", ResourceFile)
If localizedText <> "" Then
col.HeaderText = localizedText
End If
End If

'Localize text of Cancel, Delete, Edit, Insert, Select, New, Update buttons
If TypeOf col Is CommandField Then
Dim cmdField As CommandField = DirectCast(col, CommandField)
For Each cmdName As String In New String() {"Cancel", "Delete", "Edit", "Insert", "Select", "New", "Update"}
pi = cmdField.GetType.GetProperty(cmdName & "Text", GetType(String))
key = CType(pi.GetValue(cmdField, Nothing), String)
If Not String.IsNullOrEmpty(key) Then
localizedText = Localization.GetString(key & ".CommandText", ResourceFile)
If localizedText <> "" Then
pi.SetValue(cmdField, localizedText, Nothing)
End If
End If
Next
End If
Next
End Sub

In the local resource file, the keys for Header text should end with .Header while the keys for the CommandField button captions should end with .CommandText. In a CommandField, the EditText, CancelText, etc. default to "Edit", "Cancel", etc. so unless the defaults are overridden in the CommandField declaration, use keys of "Edit.CommandText", "Cancel.CommandText", etc. in the resource file.

I'm not sure if my use of reflection in getting and setting the captions of the CommandField buttons is the most efficient performance wise, it was quick to write using fewer statements.

Hope this is helpful to someone!

 

Could you show me the way to translate all into C Sharp language !

Thank so much !

 
New Post 1/14/2008 9:56 AM
User is offline a_stylez
1 posts
10th Ranked


Re: Localization of GridView Including CommandField Buttons 

pi = cmdField.GetType().GetProperty(cmdName + "Text", typeof(String));

give that a try

 
Previous Previous
 
Next Next
  Forum  DotNetNuke® Pro...  Language Packs ...  Localization of GridView Including CommandField Buttons
 


Forum Policy

These Discussion Forums are dedicated to the discussion of the DotNetNuke Web Application Framework.

For the benefit of the community and to protect the integrity of the project, please observe the following posting guidelines:

1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DotNetNuke.
2. Discussion or promotion of DotNetNuke product releases under a different brand name are strictly prohibited.
3. No Flaming or Trolling.
4. No Profanity, Racism, or Prejudice.
5. Site Moderators have the final word on approving/removing a thread or post or comment.
6. English language posting only, please.

 


MaximumASP
MaximumASP provides a wide array of web hosting plans to fit any hosting need. We also provide software and services needed to keep it running optimally.
MaximumASP.com
Mad Development: dotnetnuke design and development
We are an expert Dotnetnuke shop specializing in developing solutions that merge the requirements of design and branding, content management, ecommerce, search engine optimization and business logic.
www.MadDevelopment.com
telerik
telerik r.a.d.controls suite is the most innovative and comprehensive toolset for ASP.NET development, tailored for seamless integration with the DotNetNuke project. This integrated collection of controls allows professionals to build web-solutions with the UI richness and responsiveness of desktop applications.
dnn.telerik.com

DotNetNuke Corporation   Terms Of Use  Privacy Statement
DotNetNuke®, DNN®, and the DotNetNuke logo are trademarks of DotNetNuke Corporation
Hosted by MaximumASP