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  |  

AppTheory specializes in solutions based on the DotNetNuke platform and has 2 employees on the DotNetNuke Core Team.
  Need Help?  
Professional technical support for DotNetNuke is available from DotNetNuke Corporation.
 


  Ads  
Active Modules -- Active Forums for DotNetNuke
 


  Sponsors  

Meet Our Sponsors

Salaro -- Skins and more
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.
 


DotNetNuke Forums
 
  Forum  DotNetNuke® Pro...  Language Packs ...  Localization of GridView Including CommandField Buttons
Previous Previous
 
Next Next
New Post 12/29/2006 6:28 AM
User is offline William Severance
811 posts
www.wesnetdesigns.com
7th 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 9:02 AM
User is offline Fuji Nguyen
194 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 2: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 2: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 10: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.

 


Smart-Thinker
DNN Modules for Social Networks for as low as $69 for 6 modules! We also maintain the DotNetNuke Directory - http://DNNDir.com
www.smart-thinker.com
DNN Photo Gallery
Complete Photo Gallery Management!
www.dnnPhotoGallery.com
R2i - Delivering Serious DNN Services & Solutions
Award Winning Design, Skin construction, Custom Modules and Consulting Services for the Enterprise organization. R2i is the DNN:Map module Project Lead and one of the largest DNN service providers with offices in New York City, Virginia and Baltimore.
www.bi4ce.com

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