Try our conversational search powered by Generative AI!

Class LanguageManager

LanguageManager handles language specific strings from a XML file.

Inheritance
System.Object
LanguageManager
Implements
System.IDisposable
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.Core
Assembly: EPiServer.dll
Version: 7.19.2
Syntax
[Obsolete("Use EPiServer.Framework.Localization.LocalizationService instead", false)]
public class LanguageManager : IDisposable
Remarks

This class has been obsoleted and it is now recommended that you use the LocalizationService instead. This class will continue to work by using the LocalizationService internally.

You should never need to create your own instance of this class, always use the Instance instance. The simple reason is that this object is very heavyweight and creating a new instance on every request will consume more memory and CPU than you want.

Constructors

LanguageManager()

Initializes a new instance of the LanguageManager class.

Declaration
public LanguageManager()

LanguageManager(LocalizationService)

Initializes a new instance of the LanguageManager class.

Declaration
public LanguageManager(LocalizationService localizationService)
Parameters
Type Name Description
LocalizationService localizationService

The resource locator.

LanguageManager(String)

Constructor for LanguageManager that loads langauge information from the given directory

Declaration
public LanguageManager(string directory)
Parameters
Type Name Description
System.String directory

Path to an directory with language files

Remarks

LanguageManager will watch directory for changes and automatically reload language resources

Properties

Directory

The directory where the language files exists.

Declaration
[Obsolete("This property does affect anything anymore and has no equivalent in the EPiServer.Framework.Localization.LocalizationService.")]
public string Directory { get; set; }
Property Value
Type Description
System.String
Remarks

Changing the directory will cause the language files to be reloaded.

Instance

Gets the single LanguageManager instance.

Declaration
public static LanguageManager Instance { get; set; }
Property Value
Type Description
LanguageManager

LanguageDocument

The document where all language strings are stored.

Declaration
[Obsolete("This property will only return an empty LanguageDocument and has no equivalent in the EPiServer.Framework.Localization.LocalizationService.")]
public LanguageDocument LanguageDocument { get; }
Property Value
Type Description
LanguageDocument

Methods

AllLanguages()

Get all registered languages

Declaration
[Obsolete("Use GetLanguages() instead.", true)]
public string[, ] AllLanguages()
Returns
Type Description
System.String[,]

A two dimensional array containing id and name

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Declaration
public void Dispose()

GetLanguage(String)

Gets a specific language.

Declaration
[Obsolete("This property will only return an empty LanguageNode and has no equivalent in the EPiServer.Framework.Localization.LocalizationService.")]
public LanguageNode GetLanguage(string language)
Parameters
Type Name Description
System.String language

The language.

Returns
Type Description
LanguageNode

The LanguageNode for the requested language; null if language does not exist.

Remarks

The language lookup is case insensitive.

GetLanguages()

Gets a collection with all languages.

Declaration
[Obsolete("Use EPiServer.Framework.Localization.LocalizationService.AvailableLocalizations to retrieve a list of all available languages.")]
public ICollection<LanguageNode> GetLanguages()
Returns
Type Description
System.Collections.Generic.ICollection<LanguageNode>

A collection of LanguageNodes

Reload(String)

Reloads the language manager contents from the language files.

Declaration
[Obsolete("This method does not perform anything anymore and has no equivalent in the EPiServer.Framework.Localization.LocalizationService.")]
public void Reload(string ignoreFile)
Parameters
Type Name Description
System.String ignoreFile

Do not load this file.

Translate(String)

Takes the key and returns the text in current language.

Declaration
[Obsolete("Use EPiServer.Framework.Localization.LocalizationService.GetString(string) instead.")]
public string Translate(string key)
Parameters
Type Name Description
System.String key

A simplified XPath expression

Returns
Type Description
System.String

The translated string

Remarks

The key is typically something like "/admin/settings/heading", where the expression closely follows the folder/file/usage pattern. You can also enter a '#' to automatically constuct a path to the current file. For example when calling Translate("#heading") from the file /templates/mypage.aspx it is equivalent to calling Translate("/templates/mypage/heading").

note

Note: If the key does not begin with a '/' or '#', the key is simply returned as the result. The reason for this behavior is to be able to use EPiServer web controls that use Translate for visible strings but you might not have translations in place or maybe do not want to translate the text.

Translate(String, String)

Takes the key and returns the text in the indicated language.

Declaration
[Obsolete("Use EPiServer.Framework.Localization.LocalizationService.GetStringByCulture(string, CultureInfo) instead.")]
public string Translate(string key, string language)
Parameters
Type Name Description
System.String key

A simplified XPath expression

System.String language

The language ID of the language to translate the text into

Returns
Type Description
System.String

The translated string

Remarks

The key is typically something like "/admin/settings/heading", where the expression closely follows the folder/file/usage pattern. You can also enter a '#' to automatically constuct a path to the current file. For example when calling Translate("#heading") from the file /templates/mypage.aspx it is equivalent to calling Translate("/templates/mypage/heading").

note

Note: If the key does not begin with a '/' or '#', the key is simply returned as the result. The reason for this behavior is to be able to use EPiServer web controls that use Translate for visible strings but you might not have translations in place or maybe do not want to translate the text.

TranslateFallback(String, String)

Takes the key and returns the text in current language.

Declaration
[Obsolete("Use EPiServer.Framework.Localization.LocalizationService.GetString(string, string) instead.")]
public string TranslateFallback(string key, string fallback)
Parameters
Type Name Description
System.String key

A simplified XPath expression. Translate(String, String) for description of this parameter.

System.String fallback

The string to return if no match was found for key

Returns
Type Description
System.String

The translated string

TranslateFallback(String, String, String)

Takes the key and returns the text in the indicated language.

Declaration
[Obsolete("Use EPiServer.Framework.Localization.LocalizationService.GetString(string, string, CultureInfo) instead.")]
public string TranslateFallback(string key, string fallback, string language)
Parameters
Type Name Description
System.String key

A simplified XPath expression. Translate(String, String) for description of this parameter.

System.String fallback

The string to return if no match was found for key

System.String language

The language ID of the language to translate the text into

Returns
Type Description
System.String

The translated string

TranslateForScript(String)

Returns the resource string for a key in the language indicated. The string returned is escaped for script output. I.e. all escape sequences except \n are escaped as well as " and ' to ensure string integrity on the client side. Any \n will be preserved.

Declaration
[Obsolete("Use EPiServer.Framework.Localization.LocalizationService.GetString(string) together with EPiServer.Framework.Localization.ScriptResourceHelper.PrepareResourceForScript(string, bool) instead.")]
public string TranslateForScript(string key)
Parameters
Type Name Description
System.String key

The XPath identifying a localized resource

Returns
Type Description
System.String

The translated string.

Remarks

Translate(String, String) for more information on the format of the string to translate. For more information on how the translated text is made script-safe, see ToScriptSafeString(String).

TranslateForScript(String, Boolean)

Returns a localized string where linebreaks and surrounding whitespace have been removed. Depending on the escape parameter the string will be either escaped for safe javascript output otherwise deliberate linebreaks (\n) are replaced with the newline character.

Declaration
[Obsolete("Use EPiServer.Framework.Localization.LocalizationService.GetString(string) and encode with EPiServer.Framework.Localization.ScriptResourceHelper.PrepareResourceForScript(string, bool) instead.")]
public string TranslateForScript(string key, bool escape)
Parameters
Type Name Description
System.String key

The XPath identifying a localized resource

System.Boolean escape

if set to true the string is escaped for safe script output, otherwise \n are replaced with the newline character.

Returns
Type Description
System.String

The translated string.

Remarks

The string returned may need to be escaped before rendered as a javascript string depending on the escape parameter.

TranslateForScript(String, String)

Returns the resource string for a key in the language indicated. The string returned is escaped for script output. I.e. all escape sequences except \n are escaped as well as " and ' to ensure string integrity on the client side. Any \n will be preserved.

Declaration
[Obsolete("Use EPiServer.Framework.Localization.LocalizationService.GetString(string, CultureInfo) and encode with EPiServer.Framework.Localization.ScriptResourceHelper.PrepareResourceForScript(string, bool) instead.")]
public string TranslateForScript(string key, string language)
Parameters
Type Name Description
System.String key

A string to translate

System.String language

The language ID of the language to translate the text into

Returns
Type Description
System.String

The translated string.

Remarks

Translate(String, String) for more information on the format of the string to translate. For more information on how the translated text is made script-safe, see ToScriptSafeString(String).

TranslateForScript(String, String, Boolean)

Returns a localized string where linebreaks and surrounding whitespace have been removed. Depending on the escape parameter the string will be either escaped for safe javascript output otherwise deliberate linebreaks (\n) are replaced with the newline character.

Declaration
[Obsolete("Use EPiServer.Framework.Localization.LocalizationService.GetString(string, CultureInfo) and encode with EPiServer.Framework.Localization.ScriptResourceHelper.PrepareResourceForScript(string, bool) instead.")]
public string TranslateForScript(string key, string language, bool escape)
Parameters
Type Name Description
System.String key

The XPath identifying a localized resource

System.String language

The language ID of the language to translate the text into

System.Boolean escape

if set to true the string is escaped for safe script output, otherwise \n are replaced with the newline character.

Returns
Type Description
System.String

The translated string.

Remarks

The string returned may need to be escaped before rendered as a javascript string depending on the escape parameter.

TranslateRaw(String)

For internal use. Returns the resource string using the ui culture of the current thread.

Declaration
[Obsolete("Use EPiServer.Framework.Localization.LocalizationService.GetString(string, string) with null as fallback argument instead.")]
public string TranslateRaw(string key)
Parameters
Type Name Description
System.String key

The resource key.

Returns
Type Description
System.String

A localized resource if found, otherwise null.

TranslateRaw(String, String)

For internal use. Returns the resource string.

Declaration
[Obsolete("Use EPiServer.Framework.Localization.LocalizationService.GetStringByCulture(string, string, CultureInfo) with null as fallback argument instead.")]
public string TranslateRaw(string key, string language)
Parameters
Type Name Description
System.String key

The resource key.

System.String language

The culture name.

Returns
Type Description
System.String

A localized resource if found, otherwise null.

Implements

System.IDisposable

Extension Methods

See Also