Share via


How to: Localize Excel Solutions

Applies to

The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office.

Project type

  • Document-level projects

  • Application-level projects

Microsoft Office version

  • Excel 2003

  • Excel 2007

For more information, see Features Available by Application and Project Type.

Localization consists primarily of translating the user interface of your application. Instead of hard coding strings into your application, you should store the strings in a separate file. You can store strings for Microsoft Office Excel user interface elements in the project's default assembly resource file. The file is named MyResources.resx in Visual Basic projects, and Resources.resx in C# projects. Copies of the resource file can then be translated into multiple languages.

Note

Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Visual Studio Settings.

Storing Text in a Resource File

To add text to a resource file

  1. Open the Excel project that you want to localize.

  2. On the Project menu, select <Projectname> Properties.

    The Project Designer opens.

  3. Click Resources in the Project Designer to open the Resources pane.

  4. Select Strings in the Categories combo box.

  5. Add a unique identifier to the Name column and the text to be localized in the Value column for each string you want to localize. For example:

    Name

    Value

    ListCreateUnscheduledOrder

    create unscheduled order

    Note

    You can use the Comment column to provide notes or instructions to the translator.

Retrieving Text from a Resource File

After you have added each string to the resource file, the strings can be loaded at runtime.

To add a value to a cell using a Resource file.

  1. In the Startup event handler of Sheet1, add a NamedRange control to cell A1.

    Dim namedRange1 As Microsoft.Office.Tools.Excel.NamedRange = _
        Me.Controls.AddNamedRange(Me.Range("A1"), "NamedRange1")
    
    Microsoft.Office.Tools.Excel.NamedRange namedRange1 =
        this.Controls.AddNamedRange(this.Range["A1", missing], "namedRange1");
    
  2. Assign a value from the resource file.

    namedRange1.Value2 = My.Resources.ListCreateUnscheduledOrder
    
    namedRange1.Value2 = Properties.Resources.ListCreateUnscheduledOrder;
    

Localizing the Resource File

To localize a resource file

  1. Copy the resource file and name it with the culture code of the target language. For example, to create a file that will be localized into Japanese, copy the Resources.resx file and name it Resources.ja.resx.

  2. Have the resource file translated into the languages you want to support. For example, have the strings in Resources.ja.resx translated into Japanese.

  3. Add the translated resource files to your project so that the project system can compile the resource files into satellite assemblies.

Loading Resources Based on Office User Interface Language

The Microsoft .NET Framework loads resources based on the Microsoft Windows user interface language. Office-based solutions, however, are typically written to load resources based on the Office user interface (UI) language. The first example below demonstrates how to load resources that match the Office UI language, regardless of which version of Office is installed. The second example shows how to override both the Office UI language and the default Microsoft .NET Framework behavior.

To load resources based on Office (multiple language versions of Office)

  • Add the following code to the Startup event handler for the workbook and each of the worksheets.

    System.Threading.Thread.CurrentThread.CurrentUICulture = _
        New System.Globalization.CultureInfo( _
            Application.LanguageSettings.LanguageID( _
                Office.MsoAppLanguageID.msoLanguageIDUI))
    
    System.Threading.Thread.CurrentThread.CurrentUICulture =
        new System.Globalization.CultureInfo(
            Application.LanguageSettings.get_LanguageID(
                Office.MsoAppLanguageID.msoLanguageIDUI));
    

If you do not have multiple language versions of Office, you can force resources to load by assigning the matching culture ID to the CurrentCulture property of the CultureInfo object (or that of the current thread). This can be useful for debugging purposes, or as part of custom code that allows users to select which resources to load.

To load resources based on Office (using the Culture ID)

  • Add the following code to the Startup event handler for the workbook and each of the worksheets. This example passes the culture ID for German (Germany). For a list of culture IDs, see CultureInfo.

    System.Threading.Thread.CurrentThread.CurrentUICulture = _
        New System.Globalization.CultureInfo("de")
    
    System.Threading.Thread.CurrentThread.CurrentUICulture = 
        new System.Globalization.CultureInfo("de");
    

Localizing Custom Controls

You can add custom controls to the actions pane in Visual Studio Tools for Office solutions. You can enable localization of a user control or an actions pane control in the same way you would localize a Windows form. For more information see, Walkthrough: Localizing Windows Forms.

To enable localization of a custom control

  1. From the View menu, select Properties Window.

  2. Select the user control or actions pane control in the designer and change the Localizable property to true.

See Also

Tasks

Walkthrough: Localizing Windows Forms

Concepts

Globalization and Localization of Office Solutions

Other Resources

Globalizing and Localizing Applications

Localizing Applications