Class localization

  • Thread starter Thread starter Kate
  • Start date Start date
K

Kate

Hello,

If you want to make a VB.NET class truely 'portable' and usable in multiple
cultures then I'm guessing that the class will need to have a resource file
associated with it to contain localized error messages etc.

Does anyone have any examples of such a class or know of references to
documents that talk about such classes ?

Many thanks...

Kate
 
Kate,
I don't have a complete example, what I do is add a .resx file (Project -
Add New Item - Assembly Ressource File) to my project and name it the same
as the class file (Class1.vb & Class1.resx). Making sure to say the resx is
an 'Embedded Resource' under the file properties (click the resx in Solution
Explorer & look at the Properties Window), the default for .resx is to be an
Embedded Resource.

Then within Class1 I use Code similar to the code in the forms designer when
you enable the Form.Localizable setting on a form.

Public Class Class1

Private m_text As String

Public Sub New()
Dim resources As System.Resources.ResourceManager = New
System.Resources.ResourceManager(GetType(Class1))
m_text = resources.GetString("Text")
End Sub

Public Property Text() As String
Get
Return m_text
End Get
Set(ByVal value As String)
m_text = value
End Set
End Property

Public Shared Sub Main()
Dim c1 As New Class1
Debug.WriteLine(c1.Text)
End Sub

End Class

The following sections of MSDN should get you started, including how to
setup the multiple resource files for different languages:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vboriUsingResources.asp

http://msdn.microsoft.com/library/d...n-us/vbcon/html/vboriInternationalization.asp

Hope this helps
Jay
 
Back
Top