Sitecore MVC Forms
Localization
About
Tobias Studer

Senior Application Engineer @ Unic

@studert
Kevin Brechbühl

Senior Application Architect @ Unic

Sitecore Technology MVP 2015

@aquasonic

Blog: http://ctor.io
Agenda
• ASP.NET MVC Forms Translations
• Localization with Sitecore
• DisplayNames with Sitecore
• Serverside Validation with Sitecore
• Clientside Validation with Sitecore
• Summary
• Q&A
ASP.NET MVC Forms
Translations
• View Models with Data Annotations
• Define label with [Display]
• Define validators with e.g. [Required]
• Ways of translations
• Default validation message or property name
• Statically set a message/name
• Use .NET resource files for translation
<Talk code to me>
Localization with Sitecore
• Sitecore Dictionaries
• Key/Phrase pair as a Sitecore item
• Translate.Text(string key)
DisplayNames with Sitecore
• Ways of translations
• Pass translation to @Html.LabelFor(…)
• Create a custom attribute
• Create a custom ModelMetadataProvider
<Talk code to me>
Serverside Validation with
Sitecore
• Using custom attribute
• Use a custom attribute for each validator
• Inherit from the default ValidationAttribute
• Override: FormatErrorMessage()
• Pros: Supports placeholders and default .NET messages
• Cons: Own class for each validator
<Talk code to me>
Clientside Validation with
Sitecore
• Create custom adapters
• Register them on startup
• Add JavaScript dependencies

Microsoft.jQuery.Unobtrusive.Validation

jQuery.Validation

jQuery
<Talk code to me>
But wait, isn’t
there…
Yes, there is!
The Ultimate Solution
• Add serverside translations to your
custom adapters
• Override: Validate()
• Replace ModelValidationResult
message
<Talk code to me>
Summary
• Create a ModelMetadataProvider to
translate labels
• Create DataAnnotationsModelValidators
to translate validation errors on the client and
the server
• Create ValidationAttributes if you need
custom validation which support placeholders
to translate validation errors
Resources
https://github.com/SUGCH/SitecoreMVCFormsLocalization
Q&A
Thank y u

Sitecore MVC Forms Localization