Customizing Datatypes

Localizing Forms

When you localize your website (for example, from English to Danish), by default, the input forms rendered by Forms Renderer will only display their labels and validation messages in the main language (for example, English).

To have the form labels and validation messages in the language of the localized website, you should:

  1. Create a .NET resource file for each language used.
  2. Translate corresponding strings in each file.
  3. Set specific properties of the data type used by the Forms Renderer to these strings.

Note: The system validation messages that appear when validation fails on the user’s input in the field cannot be localized. However, you can have them automatically replaced with your user-friendly messages by providing Help texts for the data type fields used in your forms. These user-friendly messages can be localized.

Creating Resource File for Main Language

To create a resource file for the main language:

  1. Open your website in Visual Studio.
  2. Open or add the App_GlobalResources folder in the root of your website.
  3. Add a new .NET resource file (.resx) there. (Right-click App_GlobalResources in Visual Studio’s Solution Explorer > Add > Resource File).
  4. In Visual Studio’s Resource Editor add as many strings as you need for localization.

Alternatively, you can create the file locally with the minimum XML (see below) or already with the localized strings and upload it to the App_GlobalResources folder.

  1. Locally create a .NET resource file (.resx) and name it something appropriate, for example, “MainContactForm.resx”.
  2. Copy the following XML into this file:
    <root> 
      <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> 
      <!-- strings go here --> 
      <data name="NameLabel" xml:space="preserve">
        <value>Name</value>
        <comment>This is a sample comment, not displayed on the site. This is optional.
        </comment>
      </data> 
      <data name="NameHelp" xml:space="preserve">
        <value>Enter your first and last name.</value>
      </data> 
    </root>

    Listing 1: .NET resource file content

    This file will serve as a resource file for your main language. When properly configured, the string values in this file will appear as labels and validation messages on forms in the main language.

  3. Edit the file and add as many <data> elements as you need for each string you want to localize.

    As the file is XML-formatted, you can edit it in any XML editor. We recommend that you use Visual Studio to edit this file because it has a more convenient built-in resource editor.

    As you can see in the above XML, each string is represented by a <data> element, the name attribute of which specifies the name of the string you will refer to when localizing forms. As the name suggests, the <value> element specifies the value of this string, i.e. the string itself, which the user will see on a form.

  4. Log into the CMS Console.
  5. From the System perspective, expand the root of the website ( / ) and then, open or create the App_GlobalResources folder in the root.
  6. Upload your resource file there. (Select App_GlobalResources, click Upload File on the toolbar and follow the steps in the wizard.)

Important! Please avoid creating an empty .resx file in this folder because it may cause an error on your website. Either create it in Visual Studio, or upload a local file with valid XML.

Creating Resource Files for Other Languages

For each language the website is localized to, you should create a localized copy of the resource file in the main language.

Use the following file naming pattern for each localized resource file:

<resource_name>.<culture_name>.resx

For example, if you have a Danish version of your English website, its resource file must be named “MainContactForm.da-DK.resx”.

For information on culture names, please see https://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo(vs.71).aspx.

Translating Strings in Localized Resource Files

Once you have created localized resource files, you should translate the strings.

For this, you should edit the file and replace the string values in the main language with the strings in the target language.

Note: Changes in the App_GlobalResources folder make ASP.NET (and hence C1 CMS) restart, which can make the application feel unresponsive right after updates.

Using Resource Strings in Data Type Field Properties

Once your resource files for the main and other languages are ready, you should use the resource strings in the Label and Help properties of the data type fields.

As the name suggests, the Label’s value is used in the labels of forms.

If provided, the Help text is used instead of the system validation messages for fields.

The reference to a resource string in those properties must comply with a specific format:

${Resource, Resources.<resource_file_name>.<string_name>}

<resource_file_name> stands for the name of the resource file without the culture name (e.g. “en-us”) and extension (“.resx”)

  • <string_name> stands for the string name attached to the resource file name and separated from the resource file name with a period (“.”).

For example, if you want to refer to the string named NameLabel in the MainContactForm.da-dk.resx resource file, you should build the following value:

${Resources.MainContactForm.NameLabel}

To specify resource strings for labels and messages on forms:

  1. Edit the data type used by the Forms Renderer for the form you want to localize.
  2. Open the Fields tab and select a field under the Datatype fields.
  3. Refer to the string from the resource file in proper format in the field’s Label property, for example:

    ${Resource, Resources.MainContactForm.NameLabel}

  4. Likewise, refer to the corresponding resource string in the Help property of the field, for example:

    ${Resource, Resources.MainContactForm.NameHelp}

    Figure 5: Using resource strings in Label and Help properties

  5. Repeat Steps 3-4 for the Label and Help properties of each data type field.

Now you can open a page with a form on your localized website and see the labels and messages translated into the language used.

Troubleshooting

If you are experiencing an ASP.NET error screen (for example, “your resource cannot be located”), make sure that you have:

  • Upgraded to the latest version of the Forms Renderer add-on.
  • Correctly named the file for the main language (without the culture name) and other languages (with the culture name)
  • Correctly referred to the resource file and the string name in the data type field properties (Label and Help)