---
title: Localizing content on MVC sites
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

To serve content in multiple languages on your MVC site, you first need to set up [functionality that detects and sets the current culture](https://docs.kentico.com/k12sp/multilingual-websites/setting-up-multilingual-mvc-projects.md) for each request. You can then [assign cultures to your site](https://docs.kentico.com/k12sp/multilingual-websites/setting-up-multilingual-websites.md) in Kentico, and localize the content displayed on the site's pages.

## Localizing site content

When [retrieving page content](https://docs.kentico.com/k12sp/developing-websites/retrieving-content-in-mvc-applications/displaying-page-content.md), load the correct culture version of pages based on the current culture of the request.

For individual text strings displayed on the site (which are not stored within page fields), we recommend using multilingual [resource strings](https://docs.kentico.com/k12sp/multilingual-websites/setting-up-a-multilingual-user-interface/working-with-resource-strings.md). You can create and edit the strings in the **Localization** application of the Kentico administration interface.

To retrieve localized strings in the MVC application, add a using statement for the _CMS.Helper&#x73;_&#x6E;amespace, and use the _ResHelper_ class:

```csharp

@using CMS.Helpers;
...
<h2>@ResHelper.GetString("SiteName.OurProducts")</h2>

```

```csharp

@using CMS.Helpers;
...
@{
    ViewBag.Title = ResHelper.GetString("SiteName.OurProducts");
}

```

## Localizing validation results and model properties

The default approach to validating the data model of MVC applications is to decorate the model and its properties with attributes from the [System.ComponentModel.DataAnnotations](https://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations\(v=vs.100\).aspx) namespace. You use the attributes to define common validation patterns, such as range checking, string length and required fields.

The _Kentico.AspNet.Mvc_ [integration package](https://docs.kentico.com/k12sp/developing-websites/starting-with-mvc-development/installing-kentico-integration-packages.md) provides a feature that allows you to use localized [Kentico resource string keys](https://docs.kentico.com/k12sp/multilingual-websites/setting-up-a-multilingual-user-interface/working-with-resource-strings.md) as error messages in data annotation attributes. The strings are localized based on the current culture context of the current visitor. The _Kentico.LanguagePack.English_ [integration package](https://docs.kentico.com/k12sp/developing-websites/starting-with-mvc-development/installing-kentico-integration-packages.md) (installed with the _Kentico.AspNet.Mvc_ integration package) contains a _.resx_ filewith the resource strings used in the English localization of Kentico. Aside from that, you can also use the standard resource strings stored in the database.

The feature supports localization of the following data annotation attributes:

- _Display_
- _DisplayName_
- _DataType_
- _MaxLength_
- _MinLength_
- _Range_
- _RegularExpression_
- _Required_
- _StringLength_

### Enabling data annotation localization

To enable localization of data annotations in your MVC application:

1. Open your MVC project in Visual Studio.
2. Enable the localization feature by calling the **UseDataAnnotationsLocalization()** method of the _ApplicationBuilder_ instance.

   - Enable the feature at the start of your application's life cycle, for example in the **Application\_Start** method of your project's **Global.asax** file.

     > **Info:** MVC projects created by the [installer](https://docs.kentico.com/k12sp/installation/installing-kentico-mvc-projects.md) contain the _ApplicationConfig_ class, whose _RegisterFeatures_ method is called in the _Application\_Start_ method by default. You can use this class to encapsulate all of your _ApplicationBuilder_ code (enabling and configuring of Kentico MVC features).

     ```csharp

     using Kentico.Web.Mvc;

     ...

     protected void Application_Start()
     {
         ...

         // Gets the ApplicationBuilder instance
         // Allows you to enable and configure selected Kentico MVC integration features
         ApplicationBuilder builder = ApplicationBuilder.Current;

         // Enables the data annotation localization feature
         builder.UseDataAnnotationsLocalization();

         ...
     }

     ```

If the feature is enabled, validation results and display names of model properties are localized using Kentico localization services.

```csharp

public class MessageModel
{
...
     [Required(ErrorMessage = "General.RequiresMessage")]
     [Display(Name = "General.Message")]
     [DataType(DataType.MultilineText)]
     [MaxLength(500, ErrorMessage = "General.MaxlengthExceeded")]
     public string MessageText
     {
         get;
         set;
     }
...
}

```

> **Note:** **Note**: Individual error messages are processed by the _System.String.Format_ method and support composite formatting. That is, the strings themselves can contain format items that are specific to each validation attribute and represent their parameters. For example, the _minimum length_ for the _MinLenghtAttribute_ or the _minimum_ and _maximum_ for the _RangeAttribute_.
