Notes on translating ContentType, Property, and Group names in EPiServer’s Edit Mode

I ran into a bit of trouble the other day trying to get my current project’s EPiServer installation to display proper translations from our custom language files for the PageType group names when creating new pages. Luckily EPiServer’s Kristoffer Sjöberg quickly helped me getting it sorted :) So, here are my notes on the matter.

EPiServer language files

This is what the EPiServer language file should look like for the translations to work. Make sure that the groups section is placed outside contenttypes directly under language in level (this is where I failed after copying a broken sample on the web).

ContentTypes_EN.xml

<?xml version="1.0" encoding="utf-8" ?>
<languages>
  <language name="english" id="en">

    <groups>
      <foogroup>A group name translation</foogroup>
      <footab>Tab translations also goes here</footab>
    </groups>

    <contenttypes>
      <icontentdata>
        <properties>
          <metadescription>
            <caption>Meta description label</caption>
            <help>Tooltip text.</help>
          </metadescription>
        </properties>
      </icontentdata>

      <startpage>
        <name>Start page</name>
        <description>Tooltip text.</description>
        <properties>
          <mainbody>
            <caption>Main body label</caption>
            <help>Tooltip text.</help>
          </mainbody>
        </properties>
      </startpage>
    </contenttypes>

  </language>
</languages>

Note that you should no longer use attributes for describing group names; like <groups><group name="foogroup">A group name...

The icontentdata section is where you put translations for properties that are common on several page types; for instance, if you have a text property called MetaDescription on a PageType base class used by StartPage and ArticlePage, both will be translated.

PageType specific translations goes under /languages/language/contenttypes/pagetypename as in the XML example above.

The page type classes

The GroupName property of the ContentType attribute on the page type class should be set to the name of the group in the language file. In this case I set it to foogroup since that’s what I called the group in the language file; /languages/language/groups/fooname. The EPiServer edit mode tab translations are also kept in the groups element of the language file; this is mapped to the Name property of the TabDefinition object; for more information on how to set up tabs please refer to this article.

MyWebPageBase.cs

[ContentType(
  GUID = "E4E07838-98DD-4A26-AD49-285DED9D4CFF",
  DisplayName = "Fallback name",
  Description = "Fallback description",
  GroupName = "foogroup"
)]
public class StartPage : MyWebPageBase
{
  [Display(Order = 100)]
  [CultureSpecific]
  public virtual string MainBody { get; set; }
}

The other attribute properties will also map automatically if you follow the XML syntax above. Note that if you don’t have a language file with translations for the currently used edit mode language, EPiServer will instead fall back to whatever is written in the attribute’s DisplayName, Description and GroupName properties. For instance, if you have language files for English and Swedish while your web editor uses German as edit mode language, they will get the texts Fallback name, Fallback description as well as foogroup using the setup above.

MyWebPageBase.cs

public abstract class MyWebPageBase : PageData
{
  [Display(
    Name = "Fallback label",
    Description = "Fallback tooltip"
  )]
  [CultureSpecific]
  public virtual string MetaDescription { get; set; }
}

The properties common to multiple types are no different in how they work. Linus Ekström wrote a good piece on this that helped me a bunch, and of course the breaking changes article is a good read.