Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDNN Open Source...DNN Open Source...Provider and Extension ForumsProvider and Extension ForumsLanguage PacksLanguage PacksLocalization of GridView Including CommandField ButtonsLocalization of GridView Including CommandField Buttons
Previous
 
Next
New Post
12/29/2006 9:28 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
Team Lead - DotNetNuke Gallery Module Project (Not Actively Being Developed)
Extensions Forge Projects . . .
Current: UserExport, ContentDeJour, ePrayer, DNN NewsTicker, By Invitation
Coming Soon: FRBO-For Rent By Owner
 
New Post
4/22/2007 11:02 AM
 

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 4:14 AM
 

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 4:30 AM
 

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 1:56 PM
 

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

give that a try

 
Previous
 
Next
HomeHomeDNN Open Source...DNN Open Source...Provider and Extension ForumsProvider and Extension ForumsLanguage PacksLanguage PacksLocalization of GridView Including CommandField ButtonsLocalization of GridView Including CommandField Buttons


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, 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 DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out