Export (0) Print
Expand All

How to: Retrieve Localized Resources in Visual Basic

The My.Resources object provides the localized application resources (if available) based on the culture settings of the computer on which the application runs. You can override the computer's culture settings by setting the My.Application.UICulture Property.

The runtime identifies a localized resource by its culture signature, or name. The project's default resource file, Resources.resx, determines the properties that the My.Resources object displays. To provide localized resources, you need to:

  • Copy and rename the resource file to Resources.CultureSignature.resx

  • Localize the strings and any files referenced by the resource file

  • Add the localized resource file to your project

The My.Resources object exposes each resource as a read-only property. The property name is the same as the resource name, and the property type is determined by the resource classification. For more information, see My.Resources Object and Resources in Applications.

Each culture has a unique name, which is a combination of a two-letter lowercase culture name associated with a language and, if required, a two-letter uppercase subculture name associated with a country or region. The subculture name follows the culture name, separated by a dash (-). Examples include ja-JP for Japanese in Japan, en-US for US English, or de-DE for German in Germany (as opposed to an alternate, such as de-AT for German in Austria). For more information about culture names, see CultureInfo.

This example retrieves the French-culture version of the application's string resource named Message.

To change the culture that the My.Resources object uses, this example uses the My.Application.ChangeUICulture Method.

Sub ShowLocalizedMessage()
    Dim culture As String = My.Application.UICulture.Name
    My.Application.ChangeUICulture("fr-FR")
    MsgBox(My.Resources.Message)
    My.Application.ChangeUICulture(culture)
End Sub

For this example to work, your application must have a string named Message in the application's resource file, and the application should have the French-culture version of that resource file, Resources.fr-FR.resx. For more information, see How to: Add or Remove Resources.

If the application does not have the French-culture version of that resource file, the My.Resource object retrieves the resource from the default-culture resource file.

Community Additions

ADD
Show:
© 2014 Microsoft