Loading...
 
Skip to main content

Multi-Language Add-In for Visual Studio


Translating an attribute

so I was looking for a solution to the problem of translating an attribute and got the link
http://www.jollans.com/tiki2/tiki-view_forum_thread.php?forumId=1&comments_parentId=451&highlight=DisplayName,

from what I understand the work would be done only by the tool(Add-In) with a few exceptions. Even using the attribute for the example "CategoryAttribute" not getting success. You could help me?

Best regards

Germany

I'm not clear whether you are trying to localize an attribute with my Add-In, or just looking for way to localize attributes.

This is how it works with the Add-In.

Suppose I have a property, with some attributes:

Copy to clipboard
<Category("General")> _ <DisplayName("Help file")> _ <Description("This is the location of the help file for the Add-In")> _ Public Property HelpFileName As String Get return mHelpFileName End Get Set ( ByVal NewName As String ) mHelpFileName = NewName End Set End Property

The three attributes here are ones which you might use with a PropertyGrid. I think that this is probably the most common reason to want to localize attributes.

To localize these attributes, the Add-In automatically generates some wrapper classes. Here are the definitions in VB. If you are using C#, the Add-In will generate equivalent definitions in C#.

Copy to clipboard
Friend Class ml_DescriptionAttribute Inherits System.ComponentModel.DescriptionAttribute Sub New ( ByVal StringID As Integer, ByVal text As String ) MyBase.New ( ml_string ( StringID, text ) ) End Sub End Class Friend Class ml_CategoryAttribute Inherits System.ComponentModel.CategoryAttribute Sub New ( ByVal StringID As Integer, ByVal text As String ) MyBase.New ( ml_string ( StringID, text ) ) End Sub End Class Friend Class ml_DisplayNameAttribute Inherits System.ComponentModel.DisplayNameAttribute Sub New ( ByVal StringID As Integer, ByVal text As String ) MyBase.New ( ml_string ( StringID, text ) ) End Sub End Class

Then the Add-In will replace the original attributes with the new ones:

Copy to clipboard
<ml_Category(1738,"General")> _ <ml_DisplayName(1739,"Help file")> _ <ml_Description(1740,"This is the location of the help file for the Add-In")> _ Public Property HelpFileName As String Get return mHelpFileName End Get Set ( ByVal NewName As String ) mHelpFileName = NewName End Set End Property

The new attributes are simply wrappers on the original attributes, but they are able to fetch the localized name in the constructor.

You can't simply replace the original string with a call to ml_string(), or a resource name because it won't compile.

If you are not using the Add-In, and you want to specify a resource string in the attribute definition, you could write an alternative wrapper class, e.g. res_CategoryAttribute, which takes the resource name as a parameter to the constructor.

I hope that that makes some sense.

By the way, version 5 of the Add-In supports named resources as an alternative to the ml_string() function, but I haven't extended this support to Attributes yet.

Phil


Germany

Hi

it should be fixed in version 5.0x.0017, which I have just uploaded.

Phil