This content is retired. See latest version here.

Last updated: Nov 24 2015

Localizing the user interface

Setup

To get localization to work, specify a physical localization provider or a virtual one in the web.config file under episerver.framework: 

</episerver.framework>
...
  <localization fallbackBehavior="Echo" fallbackCulture="en">
    <providers>
<add virtualPath="~/Resources/LanguageFiles" name="languageFiles" type="EPiServer.Framework.Localization.XmlResources.FileXmlLocalizationProvider, EPiServer.Framework" />
    </providers>
  </localization>
</episerver.framework>

When you have added the provider, you can add one or more language files in XML format to that location, for example, ContentTypeNames.xml.

The language file can be given any name and you can have each language in a separate file or all in one file. In the language file, however, you need a certain structure.

One language:

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

Two languages:

<?xml version="1.0" encoding="utf-8"?>
<languages>
  <language name="English" id="en">
	…
   </language>
  <language name="Swedish" id="sv">
	…
   </language>
</languages>

Adding localized text

You can localize the text shown in the user interface for your content types. To do this, add localized texts in a convention-based format. The following code example shows how to add localized texts for the content type StandardPage, for example, the attribute name and description or properties for the standard page like MainContentArea.

[ContentType(
    Description = "This text can you have in XML instead"
)]
public class StandardPage : PageData
{
        [Display(
            GroupName = SystemTabNames.Content,
            Name = "This text can you have in XML instead ",
            Description = " This text can you have in XML instead " 
        )]
        public virtual ContentArea MainContentArea { get; set; }	
}

If you have a StandardPage content type with the attributes and properties as in the example above, the structure in the language file would be:

<language name="en">
  <contenttypes>
    <standardpage>
      <description>A description of the page type</description>
      <properties>
        <maincontentarea>
          <caption>Name text from XML</caption>
          <help>Description text from XML</help>
        </ maincontentarea >
      </properties>
    </standardpage>
  </contenttypes>
</language>

You can also add shared fallback translations to base classes, for example PageData. If you have a class StandardPage inheriting from PageData with the property Name, and if the StartPage does not have a translation for the name caption, then the one from PageData will be used. 

public class StandardPage : PageData
{
        public virtual string Name { get; set; }	
}
<language id="en" name="English">
  <contenttypes>
    <pagedata>
      <properties>
        <name>
          <caption>Name text from language file</caption>
        </name>
      </properties>
    </pagedata>
  </contenttypes>
</language>

Note: If you have your own base classes that are not registered as content types, and you want to add translations to these classes, you need to create a UIDescriptor for the base class.

Localizing headers

You can localize headers, such as tabs that are used to group properties, in the top-level section “groups.”

public class StandardPage : PageData
{
        [Display(
            GroupName = SystemTabNames.Content,
        )]
        public virtual ContentArea MainContentArea { get; set; }	
}

public static class SystemTabNames
{
        public const string Content = "Information";
}

Group name on the property MainContentArea is referred to SystemTabNames.Content and, as you can see in example above, SystemTabNames.Content is referring to “Information”.

The correct way here is to add <groups> and then the property name.

<language name="en">
  <groups>
        <information>Group name from XML file</information>
  </groups>
</language>

Comments

article is not complete. Where localization files should be placed in project structure?

The localication files can be in websiteroot/resources/LanguageFiles/ as it is in the example project.