Class LocalizationService
Represents the Localization Service, which is an easy access to operations involving Language and DictionaryItem
Namespace:System.Dynamic.ExpandoObject
Assembly:Umbraco.Core.dll
Syntax
public class LocalizationService : ScopeRepositoryService, ILocalizationService, IService
Constructors
LocalizationService(IDatabaseUnitOfWorkProvider, RepositoryFactory, ILogger, IEventMessagesFactory)
Declaration
public LocalizationService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IEventMessagesFactory eventMessagesFactory)
Parameters
Type | Name | Description |
---|---|---|
IDatabaseUnitOfWorkProvider | provider | |
RepositoryFactory | repositoryFactory | |
ILogger | logger | |
IEventMessagesFactory | eventMessagesFactory |
Methods
AddOrUpdateDictionaryValue(IDictionaryItem, ILanguage, String)
Adds or updates a translation for a dictionary item and language
Declaration
public void AddOrUpdateDictionaryValue(IDictionaryItem item, ILanguage language, string value)
Parameters
Type | Name | Description |
---|---|---|
IDictionaryItem | item | |
ILanguage | language | |
System.String | value |
Remarks
This does not save the item, that needs to be done explicitly
CreateDictionaryItemWithIdentity(String, Nullable<Guid>, String)
Creates and saves a new dictionary item and assigns a value to all languages if defaultValue is specified.
Declaration
public IDictionaryItem CreateDictionaryItemWithIdentity(string key, Guid? parentId, string defaultValue = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | |
System.Nullable<System.Guid> | parentId | |
System.String | defaultValue |
Returns
Type | Description |
---|---|
IDictionaryItem |
Delete(IDictionaryItem, Int32)
Deletes a IDictionaryItem object and its related translations as well as its children.
Declaration
public void Delete(IDictionaryItem dictionaryItem, int userId = 0)
Parameters
Type | Name | Description |
---|---|---|
IDictionaryItem | dictionaryItem | IDictionaryItem to delete |
System.Int32 | userId | Optional id of the user deleting the dictionary item |
Delete(ILanguage, Int32)
Deletes a ILanguage by removing it (but not its usages) from the db
Declaration
public void Delete(ILanguage language, int userId = 0)
Parameters
Type | Name | Description |
---|---|---|
ILanguage | language | ILanguage to delete |
System.Int32 | userId | Optional id of the user deleting the language |
DictionaryItemExists(String)
Checks if a IDictionaryItem with given key exists
Declaration
public bool DictionaryItemExists(string key)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | Key of the IDictionaryItem |
Returns
Type | Description |
---|---|
System.Boolean | True if a IDictionaryItem exists, otherwise false |
GetAllLanguages()
Gets all available languages
Declaration
public IEnumerable<ILanguage> GetAllLanguages()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<ILanguage> | An enumerable list of ILanguage objects |
GetDictionaryItemById(Guid)
Gets a IDictionaryItem by its System.Guid id
Declaration
public IDictionaryItem GetDictionaryItemById(Guid id)
Parameters
Type | Name | Description |
---|---|---|
System.Guid | id | Id of the IDictionaryItem |
Returns
Type | Description |
---|---|
IDictionaryItem | DictionaryItem |
GetDictionaryItemById(Int32)
Gets a IDictionaryItem by its System.Int32 id
Declaration
public IDictionaryItem GetDictionaryItemById(int id)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | id | Id of the IDictionaryItem |
Returns
Type | Description |
---|---|
IDictionaryItem | IDictionaryItem |
GetDictionaryItemByKey(String)
Gets a IDictionaryItem by its key
Declaration
public IDictionaryItem GetDictionaryItemByKey(string key)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | Key of the IDictionaryItem |
Returns
Type | Description |
---|---|
IDictionaryItem | IDictionaryItem |
GetDictionaryItemChildren(Guid)
Gets a list of children for a IDictionaryItem
Declaration
public IEnumerable<IDictionaryItem> GetDictionaryItemChildren(Guid parentId)
Parameters
Type | Name | Description |
---|---|---|
System.Guid | parentId | Id of the parent |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IDictionaryItem> | An enumerable list of IDictionaryItem objects |
GetDictionaryItemDescendants(Nullable<Guid>)
Gets a list of descendants for a IDictionaryItem
Declaration
public IEnumerable<IDictionaryItem> GetDictionaryItemDescendants(Guid? parentId)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.Guid> | parentId | Id of the parent, null will return all dictionary items |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IDictionaryItem> | An enumerable list of IDictionaryItem objects |
GetDictionaryItemKeyMap()
Declaration
public Dictionary<string, Guid> GetDictionaryItemKeyMap()
Returns
Type | Description |
---|---|
System.Collections.Generic.Dictionary<System.String, System.Guid> |
GetLanguageByCultureCode(String)
Gets a Language by its culture code
Declaration
public ILanguage GetLanguageByCultureCode(string cultureName)
Parameters
Type | Name | Description |
---|---|---|
System.String | cultureName | Culture Name - also refered to as the Friendly name |
Returns
Type | Description |
---|---|
ILanguage | Language |
GetLanguageById(Int32)
Gets a Language by its id
Declaration
public ILanguage GetLanguageById(int id)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | id | Id of the Language |
Returns
Type | Description |
---|---|
ILanguage | Language |
GetLanguageByIsoCode(String)
Gets a Language by its iso code
Declaration
public ILanguage GetLanguageByIsoCode(string isoCode)
Parameters
Type | Name | Description |
---|---|---|
System.String | isoCode | Iso Code of the language (ie. en-US) |
Returns
Type | Description |
---|---|
ILanguage | Language |
GetRootDictionaryItems()
Gets the root/top IDictionaryItem objects
Declaration
public IEnumerable<IDictionaryItem> GetRootDictionaryItems()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IDictionaryItem> | An enumerable list of IDictionaryItem objects |
Save(IDictionaryItem, Int32)
Saves a IDictionaryItem object
Declaration
public void Save(IDictionaryItem dictionaryItem, int userId = 0)
Parameters
Type | Name | Description |
---|---|---|
IDictionaryItem | dictionaryItem | IDictionaryItem to save |
System.Int32 | userId | Optional id of the user saving the dictionary item |
Save(ILanguage, Int32)
Saves a ILanguage object
Declaration
public void Save(ILanguage language, int userId = 0)
Parameters
Type | Name | Description |
---|---|---|
ILanguage | language | ILanguage to save |
System.Int32 | userId | Optional id of the user saving the language |
Events
DeletedDictionaryItem
Occurs after Delete
Declaration
public static event TypedEventHandler<ILocalizationService, DeleteEventArgs<IDictionaryItem>> DeletedDictionaryItem
Event Type
Type | Description |
---|---|
TypedEventHandler<ILocalizationService, DeleteEventArgs<IDictionaryItem>> |
DeletedLanguage
Occurs after Delete
Declaration
public static event TypedEventHandler<ILocalizationService, DeleteEventArgs<ILanguage>> DeletedLanguage
Event Type
Type | Description |
---|---|
TypedEventHandler<ILocalizationService, DeleteEventArgs<ILanguage>> |
DeletingDictionaryItem
Occurs before Delete
Declaration
public static event TypedEventHandler<ILocalizationService, DeleteEventArgs<IDictionaryItem>> DeletingDictionaryItem
Event Type
Type | Description |
---|---|
TypedEventHandler<ILocalizationService, DeleteEventArgs<IDictionaryItem>> |
DeletingLanguage
Occurs before Delete
Declaration
public static event TypedEventHandler<ILocalizationService, DeleteEventArgs<ILanguage>> DeletingLanguage
Event Type
Type | Description |
---|---|
TypedEventHandler<ILocalizationService, DeleteEventArgs<ILanguage>> |
SavedDictionaryItem
Occurs after Save
Declaration
public static event TypedEventHandler<ILocalizationService, SaveEventArgs<IDictionaryItem>> SavedDictionaryItem
Event Type
Type | Description |
---|---|
TypedEventHandler<ILocalizationService, SaveEventArgs<IDictionaryItem>> |
SavedLanguage
Occurs after Save
Declaration
public static event TypedEventHandler<ILocalizationService, SaveEventArgs<ILanguage>> SavedLanguage
Event Type
Type | Description |
---|---|
TypedEventHandler<ILocalizationService, SaveEventArgs<ILanguage>> |
SavingDictionaryItem
Occurs before Save
Declaration
public static event TypedEventHandler<ILocalizationService, SaveEventArgs<IDictionaryItem>> SavingDictionaryItem
Event Type
Type | Description |
---|---|
TypedEventHandler<ILocalizationService, SaveEventArgs<IDictionaryItem>> |
SavingLanguage
Occurs before Save
Declaration
public static event TypedEventHandler<ILocalizationService, SaveEventArgs<ILanguage>> SavingLanguage
Event Type
Type | Description |
---|---|
TypedEventHandler<ILocalizationService, SaveEventArgs<ILanguage>> |