Creating a Localized Form in InfoPath 2007

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

Summary: Learn how to use a design pattern to develop localized form templates for Microsoft Office InfoPath 2007 and InfoPath Forms Services. (17 printed pages)

Ronald Tielke, Microsoft Corporation

February 2009

Applies to: Microsoft Office InfoPath 2007, Microsoft Office Forms Server 2007, Microsoft Office SharePoint Server 2007

Contents

  • Introduction to Localizing InfoPath Form Templates

  • Installing the Sample Form Template

  • Designing Your Form

  • Localizing the Form

  • Creating the Localization Resource Files for the Form

  • Sample .Resx File

  • Adding the Localization Resource Files and Defining Their Data Connection

  • Adding Code to Detect or Specify the Current Locale

  • Localizing the Controls on the Form

  • Testing the Form

  • Error Messages

  • Conclusion

  • Additional Resources

Introduction to Localizing InfoPath Form Templates

Microsoft Office InfoPath 2007 enables you to design and deploy rich forms for use in business processes. When you design forms, the common design practice is to embed text directly in the form. However, when you need localized forms, a different approach is required. The typical design pattern for localization is to move all strings into locale-specific resource files and load the appropriate strings at run time. However, Office InfoPath 2007 lacks native support for locale-specific resource files; as such, guidance has been lacking on how to effectively accomplish localization for InfoPath forms.

This article presents a design pattern for developing a localized form template for InfoPath 2007.

The guidance in this article works for both rich-client forms presented by using the InfoPath 2007 client and Web-based forms presented by using InfoPath Forms Services.

Installing the Sample Form Template

This article references a sample InfoPath form template named LocalizedForm that implements the design pattern. To download the LocalizedForm form template, see the InfoPath 2007 Localizing Form Templates Sample on the MSDN Code Gallery. After downloading the LocalizedForm sample form template, use the following steps to open and preview the solution.

To install the sample form template

  1. Extract all of the files in the LocalizedForm.zip file into a folder on your computer.

  2. In the folder where you extracted the files, right-click LocalizedForm.xsn, and then click Design.

    The following message is displayed:

    "This form template was published to one location and has been saved or moved to a different location. To ensure that forms based on this template work correctly, publish the template again."

    NoteNote

    You do not need to republish the form template at this time to preview it. However, if you do want to test the sample form template in a production environment, you must use the Publish command on the File menu to publish the form template to a new location.

  3. Click OK to close the message.

  4. Click Preview.

    The following message is displayed:

    "InfoPath cannot build the Visual Basic or C# code. The Visual Basic or C# project for this form template cannot be found."

  5. Click Browse, navigate to drive:folder\VSTA\LocalizedForm\, select LocalizedForm.csproj, and then click Open.

    At this point, you can preview the solution. When you are finished, click Close Preview. To view the code in the form template, point to Programming on the Tools menu, and then click Microsoft Visual Studio Tools for Applications.

Designing Your Form

Begin your design pattern work by defining the XML schema of your InfoPath form, and designing its layout. As you define the layout, add inline text, such as labels, messages, and text blocks, and populate controls, such as list boxes, drop-down list boxes, and buttons, by using the language of your locale. You can then add any necessary custom business logic and event handlers by using Microsoft Visual Studio Tools for Applications.

Localizing the Form

After your form template works as you expect, you can start to implement localization for your form. This consists of five main stages:

  1. Creating an XML resource file that contains the display strings for the language of your locale, and then creating additional XML resource files for each locale your form supports.

  2. Adding the XML resource files to the form template as resources, and then defining a secondary data source to enable code and formulas in InfoPath to access the data contained in the resource files.

  3. Adding code to detect or specify the current locale, and then load the appropriate localization resource file.

  4. Converting controls on the form template and adding code or formulas to read display strings from the XML resource files you created.

  5. Deploying and testing the localized form template.

NoteNote

Localizing the InfoPath client, InfoPath Forms Services, or the system messages and dialog boxes that either emits is beyond the scope of this article.

Creating the Localization Resource Files for the Form

After your form template operates as expected, you need to create the localization resource files that contain the display strings for your form, and then define a secondary data connection that will be used to access the data in the files.

Creating a Default Localization Resource File

In the context of this article, a localization resource file is an XML file that contains localized strings and uses the .resx resource file schema as a starting point. The default localization resource file is a .resx resource file that is implemented in the language of your locale. For more information about .resx resource files, see Resources in .Resx File Format

To create a default localization resource file

  1. Use a text editor to create an XML file that has the same content as the example in the Sample .Resx File section and name the file locale.xml (for example, en-US.xml).

  2. After creating a copy of the XML file shown in the Sample .Resx File section, add data elements to the file (following the <!--<data> nodes go here.--> comment) that contain the display strings used in your form. The following sections describe how to this.

Creating Elements for Simple Strings

Simple strings typically include labels, such as the labels that identify text boxes and buttons, and messages used in your form template. To localize simple strings, you create an XML fragment that uses the data and value elements from the .resx file schema.

To add data elements for simple strings to the default localization file

  1. Locate all simple strings used in your form template.

  2. Add an XML fragment for each simple string to the localization resource file by using the following schema, where uniqueResourceID specified for the name attribute is a unique identifier (ID) for the resource string, and the string itself is enclosed in the <value> tags.

    <data name="uniqueResourceID" xml:space="preserve">
      <value>Your string goes here.</value>
    </data>
    

The following example shows the data elements used to specify the strings for two of the labels in the Contact Details section of the LocalizedForm sample form template.

<data name="lblFamilyName" xml:space="preserve">
  <value>Family Name:</value>
</data>
<data name="lblGivenName" xml:space="preserve">
  <value>Given Name:</value>
</data>

Creating Elements for Complex Strings

Complex strings are grouped items that are typically displayed in bound controls, such as list box controls, drop-down list box controls, and in repeating controls, such as repeating table and repeating section controls.

To accommodate complex strings, the form needs an extension to the .resx file schema. The implementation described in the following procedure is only one possible implementation of such an extension. The schema of this extension is designed to make it easy to group, locate, and load groups of strings related to a given control.

NoteNote

Because InfoPath does not validate the .resx schema, you can extend the .resx schema as needed without adversely affecting the functionality of the form template. However, a more .resx-compliant implementation would be required if the file must be loaded into a .resx editor.

To add elements for complex strings to the default localization file

  1. Locate all complex strings used in your form template.

  2. Use the following format to define each set of complex strings in the localization resource file, where controlGroupName is the unique, logical name of the group of strings, and uniqueResourceID specified for the id attribute is a unique ID for each resource string.

    <controlGroupName>
      <value id="uniqueResourceID1" name="Your string1 goes here." />
      <value id="uniqueResourceID2" name="Your string2 goes here." />
      <value id="uniqueResourceID3" name="Your string3 goes here." />
    </controlGroupName>
    

The following example shows the data elements used to display the names of product groups in the repeating section control on the LocalizedForm sample form template.

<productGroups>
  <value id="Compliance Services" name="Compliance Services" />
  <value id="Content Management" name="Content Management" />
  <value id="Data Systems" name="Data Systems" />
  <value id="Services" name="Services" />
  <value id="Software Services" name="Software Services" />
  <value id="Specialized Services" name="Specialized Services" />
</productAreas>

Creating Additional Localization Resource Files

After you complete your default localization resource file, use it as a starting point to create additional localization resource files for each additional locale that you want to support.

To create additional localization resource files

  1. For each locale you want to support, create a copy of your default localization resource file.

  2. Name each file locale.xml (for example, es-ES.xml, ja-JP.xml, de-DE.xml, and so on).

  3. Localize the strings contained in each file to the corresponding locale's language.

Important noteImportant

The XML-based implementation described in the previous sections does not revert to the default localization resource file when a requested resource string is not present in the localization resource file. Because of this, you must define the full set of resource strings in each localization resource file.

Sample .Resx File

The following example shows a .resx file that you can use as the starting point for your localization resource files.

<?xml version="1.0" encoding="utf-8"?>
<root>
  <xsd:schema id="root"  xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> 
    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
    <xsd:element name="root" msdata:IsDataSet="true">
      <xsd:complexType>
        <xsd:choice maxOccurs="unbounded">
          <xsd:element name="metadata">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="value" type="xsd:string" minOccurs="0" />
              </xsd:sequence>
              <xsd:attribute name="name" use="required" type="xsd:string" />
              <xsd:attribute name="type" type="xsd:string" />
              <xsd:attribute name="mimetype" type="xsd:string" />
              <xsd:attribute ref="xml:space" />
            </xsd:complexType>
          </xsd:element>
          <xsd:element name="assembly">
            <xsd:complexType>
              <xsd:attribute name="alias" type="xsd:string" />
              <xsd:attribute name="name" type="xsd:string" />
            </xsd:complexType>
          </xsd:element>
          <xsd:element name="data">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
              </xsd:sequence>
              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
              <xsd:attribute ref="xml:space" />
            </xsd:complexType>
          </xsd:element>
          <xsd:element name="resheader">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
              </xsd:sequence>
              <xsd:attribute name="name" type="xsd:string" use="required" />
            </xsd:complexType>
          </xsd:element>
        </xsd:choice>
      </xsd:complexType>
    </xsd:element>
  </xsd:schema>
  <resheader name="resmimetype">
    <value>text/microsoft-resx</value>
  </resheader>
  <resheader name="version">
    <value>2.0</value>
  </resheader>
  <resheader name="reader">
    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
  </resheader>
  <resheader name="writer">
    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
  </resheader>
  <!--<data> nodes go here.-->
</root>

Adding the Localization Resource Files and Defining Their Data Connection

After you complete all localization resource files, you need to add them to the form template as resource files, and then define a secondary data source that will be used to access the files from code.

Adding the Localization Resource Files to the Form Template

After you complete all localization resource files, you need to add them to the form template as resource files.

To add the localization resource files to the form template

  1. Open the form template in design mode.

  2. On the Tools menu, click Resource Files, and then click Add to add each of the localization resource files to the form template, as shown in Figure 1.

Figure 1. Adding localization resource files

Adding localization resource files

Adding a Secondary Data Source to the Form

This design pattern uses a data connection defined as a secondary data source to connect to the localization resource files and read data from the files.

To add a secondary data source to retrieve data from localization resource files

  1. On the Tools menu, click Data Connections, and then click Add.

  2. Click Create a new connection to, click Receive data, and then click Next.

  3. Click XML document, and then click Next.

  4. Click Resource Files, select your default localization resource file, click OK, and then click Next.

  5. Name the data connection Resources, ensure that the Automatically retrieve data when form is opened check box is selected, and then click Finish, as shown in Figure 2.

Figure 2. Adding a secondary data source

Adding a secondary data source

Extending the Form Schema to Support Localization

Add a string element named locale to the primary data source of your form template to store and access the name of the current locale in use. The default value of this element should be an empty string.

To add a locale element to the primary data source

  1. On the View menu, click Data Source.

  2. Ensure the Main data source is selected, and then click Add a Field or Group.

  3. Name the new element locale, leave the Type and Data type settings at their defaults (Field(element) and Text(string)), select Cannot be blank, and then click OK. The resulting field from the LocalizedForm sample form template is shown in Figure 3.

Figure 3. Adding the locale field

Adding the locale field

Adding Code to Detect or Specify the Current Locale

After you have added the localization resource files to the form template, you need to add code to detect or specify the current locale and to load the appropriate localization resource file.

Adding Code to Initialize the Locale Field

The key to this process is detecting the target locale, which you can do in several ways. Your options are determined by the environment that hosts the form: the InfoPath client or the browser (when you are using a form template deployed to a server running InfoPath Forms Services). Depending on the environment, you can pass this information to the form template by using input arguments, by using query string arguments, or you can detect it during the Loading event of the form. During the Loading event, you can read the locale from a user profile, from the browser capability settings, or from the Locale property of the Microsoft.SharePoint.SPWeb object associated with the site context used to invoke the form.

The sample form uses one technique for InfoPath Form Services and another for the InfoPath client.

Determining the Locale in the InfoPath Client

To easily demonstrate localization in the InfoPath client, the form uses a simple locale drop-down list box control that enables the user to manually specify the locale, as shown in Figure 4.

Figure 4. Locale drop-down list box control

Locale drop-down list box control

The locale drop-down list box control reads its values from an embedded list that contains values for each locale supported by the form, as shown in Figure 5.

Figure 5. Locale drop-down list box control entries

Locale drop-down list box control entries

The locale drop-down list box control is bound to the locale field, as shown in Figure 6.

Figure 6. Locale drop-down list box control binding

Locale drop-down list box control binding

The Changed event handler of the locale field calls the ConfigureResourceFiles function that loads the resource file for the language that the user specified. It then calls the LoadProductGroups function to update all complex controls that depend on localized strings, as shown in the following example.

public void locale_Changed(object sender, XmlEventArgs e)
{
    // Reload the resource (RESX) file for the selected locale.
    ConfigureResourceFiles();
  
    // Update all controls that depend on localized resource strings.
    LoadProductGroups();
}

To see the code for the ConfigureResourceFiles function called by the Changed event handler of the locale field, see the Adding Code to Load the Localization Resource File section.

The following examples show the code for the LoadProductGroups and LoadGroups functions that update all complex controls that depend on localized strings after the ConfigureResourceFiles function has loaded the specified locale's resource file.

private void LoadProductGroups()
{
    LoadGroups("/my:myFields/my:ProductGroups", "/root/productGroups/value");
}
private void LoadGroups(
    string groupXPath, string resourcesGroupXPath)
{
    try
    {
        XPathNavigator mainNav = MainDataSource.CreateNavigator();
        XPathNavigator groupNode = mainNav.SelectSingleNode(
            groupXPath, NamespaceManager);
        // Call the function to remove the empty child node that was used to
        // define the structure of the group.
        ClearDefaultEntries(mainNav, groupXPath + "/my:group");
        // Read localized values from the resource file.
        XPathNavigator resourcesNav =
            DataSources["Resources"].CreateNavigator();
        XPathNodeIterator resourcesGroup =
            resourcesNav.Select(resourcesGroupXPath, NamespaceManager);
        while (resourcesGroup.MoveNext())
        {
            XPathNavigator item = resourcesGroup.Current;
            string xml =
                "<my:group>" +
                "<my:selected>" + "0" + "</my:selected>" +
                "<my:id>" + Common.XmlEncode(
                    Common.SafeGetAttribute(item, "id")) + "</my:id>" +
                "<my:name>" + Common.XmlEncode(
                    Common.SafeGetAttribute(item, "name")) + "</my:name>" +
                "</my:group>";
            // Append localized values to the group.
            groupNode.AppendChild(xml);
        }
    }
    catch (Exception ex)
    {
        string msg = "Problem in LoadGroups(): " + ex.Message;
        Debug.WriteLine(msg);
    }
}
NoteNote

The Postback settings option of the locale drop-down list box control is set to Always.

Determining the Locale in InfoPath Forms Services

When the form is opened from a server running InfoPath Forms Services, the event handler for the form's Loading event can determine the locale by examining the regional settings of the site context used to invoke the form. To do that, your code can use the SPContext.Current property to drill down to the SPWeb.Locale property that returns a System.Globalization.CultureInfo object, which in turn returns the name of the current locale by using the CultureInfo.Name property.

To enable the sample form template to retrieve the current locale

  1. Open the Visual Studio Tools for Applications project of the form template.

  2. On the Project menu, click Add Reference.

  3. On the Browse tab, specify the path to the Microsoft SharePoint Services assembly as %ProgramFiles%\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI\Microsoft.SharePoint.dll.

    NoteNote

    This path points to the location of the Microsoft.SharePoint.dll file in the file system on the server that is running InfoPath Forms Services.

  4. Enable the following compiler directive found at the top of the FormCode.cs file:

    #define WssReferenceIncluded

    NoteNote

    If the capability is not enabled, the form continues to use the locale specified by the locale drop-down list box control.

The Loading event of the form calls the EstablishLocale custom function to detect and establish the locale you want. It then calls additional functions to initialize all complex controls that depend on localized strings, as shown in the following example.

#if WssReferenceIncluded
using Microsoft.SharePoint;
#endif
public void FormEvents_Loading(object sender, LoadingEventArgs e)
{
    // Determine the locale and load the associated resource (RESX) file.
    EstablishLocale();
    ConfigureResourceFiles();
    // Initialize all controls that depend on localized resource strings.
    LoadProductGroups();
}
private void EstablishLocale()
{
    XPathNavigator mainNav = MainDataSource.CreateNavigator();
    XPathNavigator localeNode = mainNav.SelectSingleNode(
        "/my:myFields/my:Support/my:locale", NamespaceManager);
    string localeName = localeNode.Value;
    if (this.Application.Environment.IsBrowser)
    {
#if WssReferenceIncluded
        // SPWeb.Locale maps to the Regional Settings of the current site.
        localeName = SPContext.Current.Web.Locale.Name;
#endif
    }
    if (String.IsNullOrEmpty(localeName))
    {
        localeName = "en-US";
    }
    localeNode.SetValue(localeName.ToLower());
}

Adding Code to Load the Localization Resource File

The ConfigureResourceFiles function is called by both the Loading event handler of the form and the Changed event handler of the locale field that is bound to the locale drop-down list box. It loads the localization resource file associated with the required locale.

private void ConfigureResourceFiles()
{
    XPathNavigator mainNav = MainDataSource.CreateNavigator();
    XPathNavigator localeNode = mainNav.SelectSingleNode(
        "/my:myFields/my:Support/my:locale", NamespaceManager);
    string localeName = localeNode.Value;
    FileQueryConnection dc =
        (FileQueryConnection)DataConnections["Resources"];
    try
    {
        dc.FileLocation = localeName + ".xml";
        dc.Execute();
    }
    catch (Exception ex)
    {
        // By design, the Resources data connection is set to execute 
        // on load. Therefore, ignore any exceptions that occur in 
        // this method because the default file of the Resources data
        // connection has already been loaded.
        Debug.WriteLine(ex.Message);
    }
}

Localizing the Controls on the Form

The following sections show how to convert controls on the form template to read display strings from the XML resource files you created.

Localizing the Simple Controls of the Form

This section discusses how to localize the simple controls in your form that display a single string, such as inline text, labels, and button controls.

To localize inline text such as labels and text blocks, you replace each instance of localizable text with an expression box control, and then define the data source for each control by writing an XPath expression that retrieves the appropriate string from the current localization resource file.

To localize inline text and labels

  1. Replace the inline text or label with an Expression Box control.

  2. Right-click the control, and then click Expression Box Properties.

  3. On the General tab, click Data source, click the Fx (function) button, and then select the Edit XPath check box.

  4. Type a formula in the following format, where DataSourceName is the name of the secondary data connection used for the localization resource files, and uniqueResourceID is the unique ID of the resource string to display, as shown in Figure 7.

    xdXDocument:GetDOM("DataSourceName")/root/data[@name = "uniqueResourceID"]/value

Figure 7. Entering the formula to display the resource string

Entering the formula to display resource string

The following examples show the XPath expressions used to retrieve and display the strings for two of the labels in the Contact Details section of the LocalizedForm sample form template.

xdXDocument:GetDOM("Resources")/root/data[@name = "lblFamilyName"]/value

xdXDocument:GetDOM("Resources")/root/data[@name = "lblGivenName"]/value

The technique for localizing button controls is similar to that used for inline text, except that instead of using an expression box control, you replace the button's Label property text with an XPath expression that retrieves the appropriate string from the current localization resource file.

To localize button controls

  1. Right-click the control, and then click Button Properties.

  2. On the General tab, delete the current value in the Label box, click the Fx (function) button, and then select the Edit XPath check box.

  3. Type a formula in the following format, where DataSourceName is the name of the secondary data connection used for the localization resource files and uniqueResourceID is the unique ID of the resource string to display.

    xdXDocument:GetDOM("DataSourceName")/root/data[@name = "uniqueResourceID"]/value

The following examples show the XPath expressions used to retrieve and display the strings for the two buttons on the LocalizedForm sample form template.

xdXDocument:GetDOM("Resources")/root/data[@name = "cmdSubmit"]/value

xdXDocument:GetDOM("Resources")/root/data[@name = "cmdClose"]/value

Localizing the Complex Controls of the Form

In this context, complex controls are controls that group a collection of distinct strings. List box and drop-down list box controls are typical examples, as are the repeating section and repeating table controls. These controls require a little more care because you need to use the method devised to group the data elements in the localization resource file.

It is possible to localize list box and drop-down list box controls by using the InfoPath user interface. To do so, you need to create the necessary XPath expressions with which to access the display strings from the current localization resource file. The following procedure shows the process used in the LocalizedForm sample template to configure a drop-down list box control. The drop-down list box is bound to the timeframe field in the main data source. This field retrieves the strings to display in the drop-down list from the elements in the timeframes group in the Resources secondary data source.

To localize list box and drop-down list box controls

  1. Right-click the list box or drop-down list box control, and then click Properties.

  2. On the Data tab under List box entries, select Look up values from an external data source, and then select the data source that is used for the localization resource files (for example, Resources).

  3. Click the button to the right of the Entries text box.

  4. Navigate to the control group you want, expand the group, select the value node, and then click OK, as shown for the timeframes control group from the LocalizedForm sample form in Figure 8.

    Figure 8. Selecting the value node

    Selecting the value node

  5. Click the button to the right of the Value text box.

  6. Expand the value node, select the id attribute, and then click OK.

  7. Click the button to the right of the Display name text box

  8. Expand the value node, select the name attribute, and then click OK.

The control is now configured to look up the values to display in the list box or drop-down list box from the specified control group in the localization resource file, as shown in Figure 9.

Figure 9. Configuring the list box to look up values from the localization resource file

Configuring the list box to look up values

It is possible to localize repeating controls (for example, a repeating section or repeating table control). The LocalizedForm sample form template uses a set of repeating section controls bound to the group group under ProductGroups in the main data source to implement an array of check boxes for specifying product groups. Most of the coding is independent of localization and mainly involves the work necessary to construct the repeating entries themselves. Adapting the process to support localized strings is incremental; create an XPathNavigator to access the secondary data source, and then execute an XPath query to obtain the control group you want.

The following LoadGroups function is called by the LoadProductGroups function as LoadGroups("/my:myFields/my:ProductGroups", "/root/productGroups/value"); in the form template's Loading event handler. This populates the values in the set of repeating section controls.

private void LoadGroups(string groupXPath, string resourcesGroupXPath)
{
    XPathNavigator mainNav = MainDataSource.CreateNavigator();
    XPathNavigator groupNode = mainNav.SelectSingleNode(
        groupXPath, NamespaceManager);
    // Remove the empty child node that was used to define the 
    // structure of the group.
    ClearDefaultEntries(mainNav, groupXPath + "/my:group");
   XPathNavigator resourcesNav = DataSources["Resources"].CreateNavigator();
    XPathNodeIterator resourcesGroup = resourcesNav.Select(
        resourcesGroupXPath, NamespaceManager);
    while (resourcesGroup.MoveNext())
    {
        XPathNavigator item = resourcesGroup.Current;
        string xml =
            "<my:group>" +
                "<my:selected>" + "0" + "</my:selected>" +
                "<my:id>" + XmlEncode(SafeGetAttribute(item, "id")) + "</my:id>" +
                "<my:name>" + XmlEncode(SafeGetAttribute(item, "name")) + "</my:name>" +
            "</my:group>";
        groupNode.AppendChild(xml);
    }
}

Localizing by Using Code

It is possible to use code to read specific string resources from the localized resource file. The following example creates an XPathNavigator to access the secondary data source and executes an XPath query to obtain the resource string you want. As in previous examples, replace DataSourceName with the name of the secondary data connection used for the localization resource files, and replace uniqueResourceID with the unique ID of the resource string to display.

XPathNavigator resxNav = DataSources["DataSourceName"].CreateNavigator();
XPathNavigator resourceNode = mainNav.SelectSingleNode(
    "/root/data[@name=\"uniqueResourceID\"]/value",NamespaceManager);
string resourceValueName = resourceNode.Value;

The following example from the LocalizedForm sample form template shows this technique.

XPathNavigator resxNav = DataSources["Resources"].CreateNavigator();
XPathNavigator resourceNode = mainNav.SelectSingleNode(
    "/root/data[@name=\"lblFamilyName\"]/value", NamespaceManager);
string resourceValueName = resourceNode.Value;

Testing the Form

Depending on how you intend to deploy your localized form, you need to test the form in InfoPath and in the browser after deploying the form template to a server running InfoPath Forms Services.

To test the form by using InfoPath

  1. Open the form template in design mode, and then click the Preview button on the toolbar.

  2. Select a locale from the drop-down list box control at the top of the form.

To test the form by using InfoPath Forms Services

  1. On the Tools menu, click Form Options.

  2. Click the Security and Trust category, clear the Automatically determine security level check box, and then click Full Trust.

  3. On the File menu, click Publish to publish the form. Be sure to select the following options in the Publishing Wizard:

    • Select SharePoint Server with or without InfoPath Forms Services, and then specify the URL for a server running InfoPath Forms Services.

    • Select the Enable the form to be filled out by using a browser check box.

    • Select Administrator-approved form template.

  4. On the server, use SharePoint 3.0 Central Administration to upload the form template to your SharePoint farm, and then activate the form to a site collection. For more information about deploying form templates that contain form code, see How to: Deploy Form Templates That Contain Form Code.

  5. The form is now ready to be used by sites within the site collection. Create a few locale sites at the top-level site of the SharePoint site collection and establish a corresponding locale for each site to demonstrate the localization capabilities. Table 1 shows an example.

    Table 1. Locale sites and settings

    Site URL

    Locale Setting in Regional Settings (Site Settings menu)

    //ServerName/en-US

    English (United States)

    //ServerName/de-DE

    German

    //ServerName/ja-JP

    Japanese

    //ServerName/locale

    Add a site for each remaining locale and its corresponding .resx file.

  6. Open localized versions of the form by using URLs of the following format, where locale is the corresponding locale name, such as en-US, de-DE,or ja-JP.

    //ServerName/locale/_layouts/formServer.aspx?XsnLocation=/FormServerTemplates/LocalizedForm.xsn&OpenIn=Browser

    InfoPath Forms Services opens the correct localized version of the form for each locale site.

Error Messages

Use of this design pattern can cause issues with the InfoPath designer. You can safely ignore these issues; however, it is helpful to be aware of them.

Compatibility Issues

The Design Checker may display a random number of "Unsupported control binding" errors when it examines the form, as shown in Figure 10.

Figure 10. Design Checker unsupported control binding errors

Design Checker unsupported control binding errors

Clicking one of these errors displays the message shown in Figure 11.

Figure 11. Unsupported control binding error message

Unsupported control binding error message

Click OK and ignore the message. The form renders on InfoPath Forms Services without any issues.

Publishing Issues

The InfoPath 2007 application may display the error message shown in Figure 12 when you attempt to publish the form.

Figure 12. Publishing errors dialog box

Publishing errors dialog box

Click Ignore Errors and proceed. The form should publish without any issues.

Conclusion

This article presents a design pattern to enable localization of InfoPath form templates. You can use these form templates in both the rich InfoPath client and in the browser for form templates deployed to servers that run InfoPath Forms Services.

Acknowledgements

This article would not have been possible without the gracious assistance of Forrest Dillaway, Microsoft Corporation.

About the Author

Ronald Tielke is a Lead Architect for Microsoft Services in Phoenix, Arizona, focused on Information Worker solutions.

Additional Resources

For more information, see the following resources: