Class LocalizedTextService
Inheritance
Namespace: Umbraco.Cms.Core.Services
Assembly: Umbraco.Core.dll
Syntax
public class LocalizedTextService : ILocalizedTextService
Constructors
View SourceLocalizedTextService(IDictionary<CultureInfo, Lazy<IDictionary<string, IDictionary<string, string>>>>, ILogger<LocalizedTextService>)
Initializes a new instance of the LocalizedTextService class with a dictionary source.
Declaration
public LocalizedTextService(IDictionary<CultureInfo, Lazy<IDictionary<string, IDictionary<string, string>>>> source, ILogger<LocalizedTextService> logger)
Parameters
| Type | Name | Description |
|---|---|---|
| IDictionary<CultureInfo, Lazy<IDictionary<string, IDictionary<string, string>>>> | source | A dictionary mapping cultures to lazy-loaded area dictionaries containing key/value translations. |
| ILogger<LocalizedTextService> | logger | The logger instance. |
LocalizedTextService(IDictionary<CultureInfo, Lazy<XDocument>>, ILogger<LocalizedTextService>)
Initializes a new instance of the LocalizedTextService class with an XML source.
Declaration
public LocalizedTextService(IDictionary<CultureInfo, Lazy<XDocument>> source, ILogger<LocalizedTextService> logger)
Parameters
| Type | Name | Description |
|---|---|---|
| IDictionary<CultureInfo, Lazy<XDocument>> | source | A dictionary mapping cultures to lazy-loaded XML documents containing translations. |
| ILogger<LocalizedTextService> | logger | The logger instance. |
LocalizedTextService(Lazy<LocalizedTextServiceFileSources>, ILogger<LocalizedTextService>)
Initializes a new instance of the LocalizedTextService class with file sources.
Declaration
public LocalizedTextService(Lazy<LocalizedTextServiceFileSources> fileSources, ILogger<LocalizedTextService> logger)
Parameters
| Type | Name | Description |
|---|---|---|
| Lazy<LocalizedTextServiceFileSources> | fileSources | The lazy-loaded file sources for localized text. |
| ILogger<LocalizedTextService> | logger | The logger instance. |
Methods
View SourceConvertToSupportedCultureWithRegionCode(CultureInfo)
Tries to resolve a full 4 letter culture from a 2 letter culture name
Declaration
public CultureInfo ConvertToSupportedCultureWithRegionCode(CultureInfo currentCulture)
Parameters
| Type | Name | Description |
|---|---|---|
| CultureInfo | currentCulture | The culture to determine if it is only a 2 letter culture, if so we'll try to convert it, otherwise it will just be returned |
Returns
| Type | Description |
|---|---|
| CultureInfo |
Remarks
TODO: This is just a hack due to the way we store the language files, they should be stored with 4 letters since that is what they reference but they are stored with 2, further more our user's languages are stored with 2. So this attempts to resolve the full culture if possible. This only works when this service is constructed with the LocalizedTextServiceFileSources
GetAllStoredValues(CultureInfo)
Returns all key/values in storage for the given culture
Declaration
public IDictionary<string, string> GetAllStoredValues(CultureInfo culture)
Parameters
| Type | Name | Description |
|---|---|---|
| CultureInfo | culture |
Returns
| Type | Description |
|---|---|
| IDictionary<string, string> |
GetAllStoredValuesByAreaAndAlias(CultureInfo)
Returns all key/values in storage for the given culture
Declaration
public IDictionary<string, IDictionary<string, string>> GetAllStoredValuesByAreaAndAlias(CultureInfo culture)
Parameters
| Type | Name | Description |
|---|---|---|
| CultureInfo | culture |
Returns
| Type | Description |
|---|---|
| IDictionary<string, IDictionary<string, string>> |
GetSupportedCultures()
Returns a list of all currently supported cultures
Declaration
public IEnumerable<CultureInfo> GetSupportedCultures()
Returns
| Type | Description |
|---|---|
| IEnumerable<CultureInfo> |
Localize(string, CultureInfo, IDictionary<string, string?>?)
Localizes a key by parsing the area and alias from the key string.
Declaration
public string Localize(string key, CultureInfo culture, IDictionary<string, string?>? tokens = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The key in the format "area/alias" or just "alias". |
| CultureInfo | culture | The culture to localize for. |
| IDictionary<string, string> | tokens | Optional token replacements. This can be null. |
Returns
| Type | Description |
|---|---|
| string | The localized string, or the key wrapped in brackets if not found. |
Localize(string?, string?, CultureInfo?, IDictionary<string, string?>?)
Localize a key with variables
Declaration
public string Localize(string? area, string? alias, CultureInfo? culture, IDictionary<string, string?>? tokens = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | area | |
| string | alias | |
| CultureInfo | culture | |
| IDictionary<string, string> | tokens | This can be null |
Returns
| Type | Description |
|---|---|
| string |