Tags: CMS12 Optimizely/Episerver

Localized page types and properties in Optimizely CMS 12

In Optimizely CMS you can name your content types, and properties, using the [ContentType()] and [Display()]-attributes, like this.

[ContentType(DisplayName="Bloggpost")]
public class BlogPostPage : PageData
{
    [CultureSpecific]
    [Display(Name = "Tekstinnhold")]
    public virtual XhtmlString MainBody { get; set; }

    ...

}

If you have editors that use different languages, you might want localized content type and property names.

Step 1 – create an xml file for each language

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<languages>
  <language name="norsk" id="no">
    <contenttypes>
      <icontentdata>
        <properties>
          <mainbody>
            <caption>Tekstinnhold</caption>
            <help></help>
          </mainbody>
        </properties>
      </icontentdata>
      <blogpostpage>
        <name>Bloggpost</name>
        <description></description>
      </blogpostpage>
    </contenttypes>
  </language>
</languages>

Step 2 – add the following to startup.cs

services.AddEmbeddedLocalization<Startup>();
services.AddLocalizationProvider<FileXmlLocalizationProvider, NameValueCollection>(o =>
{
        o[FileXmlLocalizationProvider.PhysicalPathKey] = "language";
});

Set the value  PhysicalPathKey to the path where you keep your XML files.

That's all!