Class LocalizationService
Provides the base class for service for localized resources for a specific culture.
Inheritance
Inherited Members
Namespace: EPiServer.Framework.Localization
Assembly: EPiServer.Framework.dll
Version: 8.11.0Syntax
public abstract class LocalizationService
Constructors
LocalizationService(ResourceKeyHandler)
Initializes a new instance of the Localization
Declaration
protected LocalizationService(ResourceKeyHandler keyHandler)
Parameters
Type | Name | Description |
---|---|---|
Resource |
keyHandler | The handler used to manipulate resource keys. |
Fields
MissingMessageFormat
The formatting string that is used when a key is missing for a language.
Declaration
public static readonly string MissingMessageFormat
Field Value
Type | Description |
---|---|
System. |
Properties
AvailableLocalizations
Gets all available localizations that the Localization
Declaration
public abstract IEnumerable<CultureInfo> AvailableLocalizations { get; }
Property Value
Type | Description |
---|---|
System. |
Remarks
An available localizations does not need to contain any translations.
Available languages should never contain the System.
Current
Gets the current Localization
Declaration
public static LocalizationService Current { get; }
Property Value
Type | Description |
---|---|
Localization |
Remarks
This is a shortcut to the Servicenull
.
FallbackBehavior
Gets or sets the fallback behavior to use when no resource is found.
Declaration
public virtual FallbackBehaviors FallbackBehavior { get; set; }
Property Value
Type | Description |
---|---|
Fallback |
The fallback behavior. |
Remarks
The value can be set by configuration (Localization
If
If
The reason for the possibility to use an echo behavior is to be able to use EPiServer web controls that use Translate for visible strings, where you might not have translations in place, or maybe do not want to translate the text.
FallbackCulture
Gets or sets the fallback culture to use if a resource is not found for the requested culture.
Declaration
public virtual CultureInfo FallbackCulture { get; set; }
Property Value
Type | Description |
---|---|
System. |
The fallback culture to use. |
Remarks
Note that the Fallback
KeyHandler
Gets the handler that is used to manipulate resource keys.
Declaration
protected ResourceKeyHandler KeyHandler { get; }
Property Value
Type | Description |
---|---|
Resource |
Methods
GetAllStrings()
Gets all localized strings for the current UI culture.
Declaration
public IEnumerable<ResourceItem> GetAllStrings()
Returns
Type | Description |
---|---|
System. |
All resource strings for the current UI culture. |
GetAllStrings(String)
Gets all localized strings for the current UI culture below the specified key.
Declaration
public IEnumerable<ResourceItem> GetAllStrings(string resourceKey)
Parameters
Type | Name | Description |
---|---|---|
System. |
resourceKey | The key that represents the localized string to get. |
Returns
Type | Description |
---|---|
System. |
All localized strings for the current UI culture below the specified key. |
Remarks
If the key is empty, all strings will be returned.
GetresourceKey
.
GetAllStringsByCulture(CultureInfo)
Gets all localized strings for the specified culture.
Declaration
public IEnumerable<ResourceItem> GetAllStringsByCulture(CultureInfo culture)
Parameters
Type | Name | Description |
---|---|---|
System. |
culture | The requested culture for the localized strings. |
Returns
Type | Description |
---|---|
System. |
All localized strings for the given culture. |
GetAllStringsByCulture(String, CultureInfo)
Gets all localized strings for the specified culture below the specified key.
Declaration
public virtual IEnumerable<ResourceItem> GetAllStringsByCulture(string resourceKey, CultureInfo culture)
Parameters
Type | Name | Description |
---|---|---|
System. |
resourceKey | The key that represents the localized string to get. |
System. |
culture | The requested culture for the localized strings. |
Returns
Type | Description |
---|---|
System. |
All localized strings below the specified key. |
Remarks
If the key is empty, all strings will be returned.
GetresourceKey
.
GetAllStringsByCulture(String, String[], CultureInfo)
Gets all localized strings for the specified culture below the specified key.
Declaration
protected abstract IEnumerable<ResourceItem> GetAllStringsByCulture(string originalKey, string[] normalizedKey, CultureInfo culture)
Parameters
Type | Name | Description |
---|---|---|
System. |
originalKey | The original key that was passed into any GetString method. |
System. |
normalizedKey | The |
System. |
culture | The requested culture for the localized strings. |
Returns
Type | Description |
---|---|
System. |
All localized strings below the specified key. |
GetString(String)
Gets the localized string for the specified key in the current UI culture.
Declaration
public string GetString(string resourceKey)
Parameters
Type | Name | Description |
---|---|---|
System. |
resourceKey | The key that represents the localized string to get. |
Returns
Type | Description |
---|---|
System. |
A localized string. |
Remarks
The resourceKey
is default 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 GetString("#heading") from the file /templates/mypage.aspx it is
equivalent to calling GetString("/templates/mypage/heading").
The return value when no match for resourceKey
is found is dependent on the value
of the Fallback
GetString(String, FallbackBehaviors)
Gets the localized string for the specified key in the current UI culture using the provided fallback behavior.
Declaration
public string GetString(string resourceKey, FallbackBehaviors fallbackBehavior)
Parameters
Type | Name | Description |
---|---|---|
System. |
resourceKey | The key that represents the localized string to get. |
Fallback |
fallbackBehavior | The fallback behavior to use if the resource is not found. |
Returns
Type | Description |
---|---|
System. |
A localized string. |
Remarks
GetresourceKey
.
GetString(String, String)
Gets the localized string for the specified key in the current UI culture.
Declaration
public string GetString(string resourceKey, string fallback)
Parameters
Type | Name | Description |
---|---|---|
System. |
resourceKey | The key that represents the localized string to get. |
System. |
fallback | The string to return if no match was found for |
Returns
Type | Description |
---|---|
System. |
A localized string or |
Remarks
GetresourceKey
.
GetStringByCulture(String, FallbackBehaviors, CultureInfo)
Gets the localized string for the specified key in the specified culture using the provided fallback behavior.
Declaration
public virtual string GetStringByCulture(string resourceKey, FallbackBehaviors fallbackBehavior, CultureInfo culture)
Parameters
Type | Name | Description |
---|---|---|
System. |
resourceKey | The key that represents the localized string to get. |
Fallback |
fallbackBehavior | The fallback behavior to use if the resource is not found. |
System. |
culture | The requested culture for the localized string. |
Returns
Type | Description |
---|---|
System. |
A localized string. |
Remarks
GetresourceKey
.
GetStringByCulture(String, CultureInfo)
Gets the localized string for the specified key in the specified culture using the standard fallback behavior.
Declaration
public string GetStringByCulture(string resourceKey, CultureInfo culture)
Parameters
Type | Name | Description |
---|---|---|
System. |
resourceKey | The key that represents the localized string to get. |
System. |
culture | The requested culture for the localized string. |
Returns
Type | Description |
---|---|
System. |
A localized string. |
GetStringByCulture(String, String, CultureInfo)
Gets the localized string for the specified key in the specified culture.
Declaration
public string GetStringByCulture(string resourceKey, string fallback, CultureInfo culture)
Parameters
Type | Name | Description |
---|---|---|
System. |
resourceKey | The key that represents the localized string to get. |
System. |
fallback | The string to return if no match was found for |
System. |
culture | The requested culture for the localized string. |
Returns
Type | Description |
---|---|
System. |
A localized string or |
Remarks
GetresourceKey
.
LoadString(String[], String, CultureInfo)
Gets the localized string for the specified key in the specified culture.
Declaration
protected abstract string LoadString(string[] normalizedKey, string originalKey, CultureInfo culture)
Parameters
Type | Name | Description |
---|---|---|
System. |
normalizedKey | The |
System. |
originalKey | The original key that was passed into any GetString method. |
System. |
culture | The requested culture for the localized string. |
Returns
Type | Description |
---|---|
System. |
A localized string or |
Remarks
Any implementation must make sure that if no resource is found for the given key and culture,
null
must be returned.
NormalizeKey(String)
Normalizes the resource key to an array of key parts split on forward slash (/). If the key starts with a hash (#), it will use the current request path to resolve the key.
Declaration
protected virtual string[] NormalizeKey(string resourceKey)
Parameters
Type | Name | Description |
---|---|---|
System. |
resourceKey | The resource key to normalize. The key must start with '/' or '#' for the key to be normalized. |
Returns
Type | Description |
---|---|
System. |
An normalized array with key parts. |
Remarks
Raises the Key
OnKeyNormalized(ResourceKeyNormalizedEventArgs)
Raises the Key
Declaration
protected virtual void OnKeyNormalized(ResourceKeyNormalizedEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
Resource |
args | The Resource |
TryGetString(String, out String)
Tries to get the localized string for the specified key in the current UI culture.
Declaration
public bool TryGetString(string resourceKey, out string localizedString)
Parameters
Type | Name | Description |
---|---|---|
System. |
resourceKey | The key that represents the localized string to get. |
System. |
localizedString | The localized string that if found will be populated. If not found it will be set to null. |
Returns
Type | Description |
---|---|
System. |
|
Remarks
GetresourceKey
.
TryGetStringByCulture(String, CultureInfo, out String)
Tries to get the localized string for the specified key in the specified culture.
Declaration
public virtual bool TryGetStringByCulture(string resourceKey, CultureInfo culture, out string localizedString)
Parameters
Type | Name | Description |
---|---|---|
System. |
resourceKey | The key that represents the localized string to get. |
System. |
culture | The requested culture for the localized string. |
System. |
localizedString | The localized string that if found will be populated. If not found it will be set to null. |
Returns
Type | Description |
---|---|
System. |
|
Remarks
GetresourceKey
.
TryGetStringByCulture(String, String[], CultureInfo, out String)
Tries to get the localized string for the specified key in the specified culture.
Declaration
protected virtual bool TryGetStringByCulture(string originalKey, string[] normalizedKey, CultureInfo culture, out string localizedString)
Parameters
Type | Name | Description |
---|---|---|
System. |
originalKey | The original key that was passed into any GetString method. |
System. |
normalizedKey | The |
System. |
culture | The requested culture for the localized string. |
System. |
localizedString | The localized string that if found will be populated. If not found it will be set to null. |
Returns
Type | Description |
---|---|
System. |
|
Events
ResourceKeyNormalized
Occurs when a resource key has been normalized. At this time you have the opportunity to modify the contents of this array.
Declaration
public event EventHandler<ResourceKeyNormalizedEventArgs> ResourceKeyNormalized
Event Type
Type | Description |
---|---|
System. |
Remarks
If you modify the contents of the normalized array, you should always ensure that it is not null.