How to internationalize Content Type Definition

From Sense/Net Wiki
Jump to: navigation, search
  •  
  •  
  •  
  •  
  • 100%
  • 6.2
  • Enterprise
  • Community
  • Planned

Overview

Localized CTD

One of the main features of Sense/Net ECMS is the dynamic Content Type system. Content types are composed of fields that will appear on the user interface when a user edits a content - e.g. fills a form or creates a new article. If you are building a portal for different locales you may want to present the same forms or other user interfaces in different languages. This article describes a way for portal builders and developers to localize content types.

Details

To localize a content type you have to provide the necessary resource keys in the Content Type Definition xml (CTD). This means providing string resource keys for field display names and descriptions, or even option values of choice fields. You may use any resource class names and resource keys you defined previously. In this example we assume you have a content type named CustomArticle that has a field with the name CustomField.

Defining string resources

You may define a string resource for the CustomField field for the English language (en) in the following way:

  <ResourceClass name="Ctd-CustomArticle">
    <Languages>
      ...
      <Language cultureName="en">
        <data name="CustomField-DisplayName" xml:space="preserve">
          <value>Custom field</value>
        </data>
      ...


You may choose any resource class and resource key name that XML lets you, there are no naming conventions here. You may also put the resources to any resource file - see Localization article for more info.

Localize the CTD

If you defined the string resources, you can insert the resource references into the CTD. The following example demonstrates how you would do this in case of a CustomArticle content type:

<Fields>
  ...
  <Field name="CustomField" type="ShortText">
    <DisplayName>$Ctd-CustomArticle,CustomField-DisplayName</DisplayName>
    <Description>$Ctd-CustomArticle,CustomField-Description</Description>
  </Field>
  ...
</Fields>

The format of the string resource key is the same as in other parts of the portal:

$<ResourceClass>,<ResourceKey>

The following screenshot displays a Site content edit page translated to Hungarian:

Localized Site edit page

Localize choice field manual options

It is possible to localize the option texts of a choice field. These options will be visible on the GUI in a dropdown control (or any list control you choose). The values of the options are not localizable as they will be used to store the actual values in the database.

<Field name="MyChoiceField" type="Choice">
  <DisplayName>$Ctd-CustomArticle,MyChoiceField-DisplayName</DisplayName>
  <Description>$Ctd-CustomArticle,MyChoiceField-Description</Description>
  <Configuration>
    <Options>
      <Option selected="true" value="0">$Ctd-CustomArticle,MyChoiceField-Default</Option>
      <Option value="1">$Ctd-CustomArticle,MyChoiceField-One</Option>
      <Option value="2">$Ctd-CustomArticle,MyChoiceField-Two</Option>
    </Options>
  </Configuration>
</Field>

Localize choice field enum options

The choice field can be built up using an Enumeration defined in source code. If that is the case, you do not have to modify the CTD to localize the options of the field. The system will try to find string resources for the options using the following naming convention:

$Ctd,Enum-<ContentTypeName>-<FieldName>-<EnumValue>

For example:

$Ctd,Enum-SmartFolder-EnableAutofilters-Enabled

You still have to provide the necessary string resources as demonstrated in the beginning of this article. The only restriction here is that they have to be in the Ctd resource class and must follow the naming convention above.

<ResourceClass name="Ctd">
    <Languages>
	  ...
      <Language cultureName="en">
        <data name="Enum-SmartFolder-EnableAutofilters-Default" xml:space="preserve">
          <value>Default</value>
        </data>
        <data name="Enum-SmartFolder-EnableAutofilters-Enabled" xml:space="preserve">
          <value>Enabled</value>
        </data>
        <data name="Enum-SmartFolder-EnableAutofilters-Disabled" xml:space="preserve">
          <value>Disabled</value>
        </data>
		...


In the examples above we used the default resource class name Ctd. Tthe system tries to find the string resources in this class by default. You can override this behavior by providing a different resource class name as the resourceClass attribute of the Enum xml node in the CTD.


<Options>
  <Enum type="SenseNet.Search.FilterStatus" resourceClass="MyResourceClassName" />
</Options>

Related links

References

This page does not have external references.