Class HtmlHelperTranslationExtensions

Extension methods for the System.Web.Mvc.HtmlHelper class that handles translation scenarios.

Inheritance
System.Object
HtmlHelperTranslationExtensions
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: EPiServer.Shell.Web.Mvc.Html
Assembly: EPiServer.Shell.dll
Version: 8.11.0
Syntax
public static class HtmlHelperTranslationExtensions

Methods

Translate(HtmlHelper, String)

Translates using the current LocalizationService.

Declaration
public static string Translate(this HtmlHelper html, string translationKey)
Parameters
Type Name Description
System.Web.Mvc.HtmlHelper html
System.String translationKey

The xpath to the translated text

Returns
Type Description
System.String

A translated string or a warning text if no translation was found

TranslatedButton(HtmlHelper, String, ShellInputType, String, Object)

Creates an input with the appropriate styles and a translated button text

Declaration
public static string TranslatedButton(this HtmlHelper html, string name, ShellInputType inputType, string translationKey, object htmlAttributes)
Parameters
Type Name Description
System.Web.Mvc.HtmlHelper html
System.String name
ShellInputType inputType
System.String translationKey
System.Object htmlAttributes
Returns
Type Description
System.String

TranslatedLabel(HtmlHelper, String, String)

Creates a HTML label using the supplied lang key

Declaration
public static string TranslatedLabel(this HtmlHelper html, string targetID, string translationKey)
Parameters
Type Name Description
System.Web.Mvc.HtmlHelper html

The html helper to hook the method to

System.String targetID

The label's for attribute value

System.String translationKey

The lang file xpath from where to get label contents

Returns
Type Description
System.String

A HTML label

TranslatedTextBox(HtmlHelper, String, String, Object, Object)

Creates a HTML input text with an associated translated label

Declaration
public static string TranslatedTextBox(this HtmlHelper htmlHelper, string name, string translationKey, object value, object htmlAttributes)
Parameters
Type Name Description
System.Web.Mvc.HtmlHelper htmlHelper

The html helper to hook the method to

System.String name

The name of the input text

System.String translationKey

The lang file xpath from where to get label contents

System.Object value

The text box's value

System.Object htmlAttributes

Html attributes to decorate the input text

Returns
Type Description
System.String

Two HTML elements, a label and an input text

TranslateFallback(HtmlHelper, String, String)

Translate the given string to the current language. Will return supplied fallback string if no match is found.

Declaration
public static string TranslateFallback(this HtmlHelper htmlHelper, string translationKey, string fallback)
Parameters
Type Name Description
System.Web.Mvc.HtmlHelper htmlHelper

The html helper to hook the method to

System.String translationKey

A string to translate

System.String fallback

The string to return if no match was found for key.

Returns
Type Description
System.String

The translated string.

TranslateFormat(HtmlHelper, String, Object[])

Translates using the current LocalizationService.

Declaration
public static string TranslateFormat(this HtmlHelper html, string translationKey, params object[] values)
Parameters
Type Name Description
System.Web.Mvc.HtmlHelper html
System.String translationKey

The xpath to the translated text

System.Object[] values

An array of objects passed to the string.Format method

Returns
Type Description
System.String

A translated string or a warning text if no translation was found

TranslateForScript(HtmlHelper, String)

Translates using the current LocalizationService.

Declaration
public static string TranslateForScript(this HtmlHelper html, string translationKey)
Parameters
Type Name Description
System.Web.Mvc.HtmlHelper html
System.String translationKey

The xpath to the translated text

Returns
Type Description
System.String

A translated string or a warning text if no translation was found