2024-09-10 15:17:29 +01:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2023-01-26 13:34:11 +01:00
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Umbraco.Cms.Core.DependencyInjection;
|
2021-02-09 10:22:42 +01:00
|
|
|
using Umbraco.Cms.Core.Events;
|
|
|
|
|
using Umbraco.Cms.Core.Models;
|
|
|
|
|
using Umbraco.Cms.Core.Persistence.Repositories;
|
2021-02-15 11:41:12 +01:00
|
|
|
using Umbraco.Cms.Core.Scoping;
|
2023-01-20 13:40:24 +01:00
|
|
|
using Umbraco.Cms.Core.Services.OperationStatus;
|
2021-02-09 11:26:22 +01:00
|
|
|
using Umbraco.Extensions;
|
2017-12-28 09:18:09 +01:00
|
|
|
|
2022-06-07 15:28:38 +02:00
|
|
|
namespace Umbraco.Cms.Core.Services;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Represents the Localization Service, which is an easy access to operations involving <see cref="Language" /> and
|
|
|
|
|
/// <see cref="DictionaryItem" />
|
|
|
|
|
/// </summary>
|
2023-01-26 13:34:11 +01:00
|
|
|
[Obsolete("Please use ILanguageService and IDictionaryItemService for localization. Will be removed in V15.")]
|
2022-06-07 15:28:38 +02:00
|
|
|
internal class LocalizationService : RepositoryService, ILocalizationService
|
2017-12-28 09:18:09 +01:00
|
|
|
{
|
2022-06-07 15:28:38 +02:00
|
|
|
private readonly IDictionaryRepository _dictionaryRepository;
|
|
|
|
|
private readonly ILanguageRepository _languageRepository;
|
2023-01-26 13:34:11 +01:00
|
|
|
private readonly ILanguageService _languageService;
|
|
|
|
|
private readonly IDictionaryItemService _dictionaryItemService;
|
2023-03-29 08:14:47 +02:00
|
|
|
private readonly IUserIdKeyResolver _userIdKeyResolver;
|
2022-06-07 15:28:38 +02:00
|
|
|
|
2023-03-21 12:41:20 +01:00
|
|
|
[Obsolete("Please use constructor with language, dictionary and user services. Will be removed in V15")]
|
2022-06-07 15:28:38 +02:00
|
|
|
public LocalizationService(
|
|
|
|
|
ICoreScopeProvider provider,
|
|
|
|
|
ILoggerFactory loggerFactory,
|
|
|
|
|
IEventMessagesFactory eventMessagesFactory,
|
|
|
|
|
IDictionaryRepository dictionaryRepository,
|
|
|
|
|
ILanguageRepository languageRepository)
|
2023-01-26 13:34:11 +01:00
|
|
|
: this(
|
|
|
|
|
provider,
|
|
|
|
|
loggerFactory,
|
|
|
|
|
eventMessagesFactory,
|
|
|
|
|
dictionaryRepository,
|
|
|
|
|
languageRepository,
|
|
|
|
|
StaticServiceProvider.Instance.GetRequiredService<ILanguageService>(),
|
2023-03-21 12:41:20 +01:00
|
|
|
StaticServiceProvider.Instance.GetRequiredService<IDictionaryItemService>(),
|
2023-03-29 08:14:47 +02:00
|
|
|
StaticServiceProvider.Instance.GetRequiredService<IUserIdKeyResolver>())
|
2023-01-26 13:34:11 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Obsolete("Please use ILanguageService and IDictionaryItemService for localization. Will be removed in V15.")]
|
|
|
|
|
public LocalizationService(
|
|
|
|
|
ICoreScopeProvider provider,
|
|
|
|
|
ILoggerFactory loggerFactory,
|
|
|
|
|
IEventMessagesFactory eventMessagesFactory,
|
|
|
|
|
IDictionaryRepository dictionaryRepository,
|
|
|
|
|
ILanguageRepository languageRepository,
|
|
|
|
|
ILanguageService languageService,
|
2023-03-21 12:41:20 +01:00
|
|
|
IDictionaryItemService dictionaryItemService,
|
2023-03-29 08:14:47 +02:00
|
|
|
IUserIdKeyResolver userIdKeyResolver)
|
2022-06-07 15:28:38 +02:00
|
|
|
: base(provider, loggerFactory, eventMessagesFactory)
|
|
|
|
|
{
|
|
|
|
|
_dictionaryRepository = dictionaryRepository;
|
|
|
|
|
_languageRepository = languageRepository;
|
2023-01-26 13:34:11 +01:00
|
|
|
_languageService = languageService;
|
|
|
|
|
_dictionaryItemService = dictionaryItemService;
|
2023-03-29 08:14:47 +02:00
|
|
|
_userIdKeyResolver = userIdKeyResolver;
|
2022-06-07 15:28:38 +02:00
|
|
|
}
|
|
|
|
|
|
2017-12-28 09:18:09 +01:00
|
|
|
/// <summary>
|
2022-06-07 15:28:38 +02:00
|
|
|
/// Adds or updates a translation for a dictionary item and language
|
2017-12-28 09:18:09 +01:00
|
|
|
/// </summary>
|
2022-06-07 15:28:38 +02:00
|
|
|
/// <param name="item"></param>
|
|
|
|
|
/// <param name="language"></param>
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// This does not save the item, that needs to be done explicitly
|
|
|
|
|
/// </remarks>
|
2023-01-26 13:34:11 +01:00
|
|
|
[Obsolete("Please use IDictionaryItemService for dictionary item operations. Will be removed in V15.")]
|
2022-06-07 15:28:38 +02:00
|
|
|
public void AddOrUpdateDictionaryValue(IDictionaryItem item, ILanguage? language, string value)
|
2017-12-28 09:18:09 +01:00
|
|
|
{
|
2022-06-07 15:28:38 +02:00
|
|
|
if (item == null)
|
2017-12-28 09:18:09 +01:00
|
|
|
{
|
2022-06-07 15:28:38 +02:00
|
|
|
throw new ArgumentNullException(nameof(item));
|
2017-12-28 09:18:09 +01:00
|
|
|
}
|
|
|
|
|
|
2022-06-07 15:28:38 +02:00
|
|
|
if (language == null)
|
2017-12-28 09:18:09 +01:00
|
|
|
{
|
2022-06-07 15:28:38 +02:00
|
|
|
throw new ArgumentNullException(nameof(language));
|
|
|
|
|
}
|
2017-12-28 09:18:09 +01:00
|
|
|
|
2023-01-26 13:34:11 +01:00
|
|
|
item.AddOrUpdateDictionaryValue(language, value);
|
2022-06-07 15:28:38 +02:00
|
|
|
}
|
2017-12-28 09:18:09 +01:00
|
|
|
|
2022-06-07 15:28:38 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Creates and saves a new dictionary item and assigns a value to all languages if defaultValue is specified.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="key"></param>
|
|
|
|
|
/// <param name="parentId"></param>
|
|
|
|
|
/// <param name="defaultValue"></param>
|
|
|
|
|
/// <returns></returns>
|
2023-01-26 13:34:11 +01:00
|
|
|
[Obsolete("Please use IDictionaryItemService for dictionary item operations. Will be removed in V15.")]
|
2022-06-07 15:28:38 +02:00
|
|
|
public IDictionaryItem CreateDictionaryItemWithIdentity(string key, Guid? parentId, string? defaultValue = null)
|
2023-01-20 13:40:24 +01:00
|
|
|
{
|
|
|
|
|
IEnumerable<IDictionaryTranslation> translations = defaultValue.IsNullOrWhiteSpace()
|
|
|
|
|
? Array.Empty<IDictionaryTranslation>()
|
|
|
|
|
: GetAllLanguages()
|
|
|
|
|
.Select(language => new DictionaryTranslation(language, defaultValue!))
|
|
|
|
|
.ToArray();
|
|
|
|
|
|
2023-01-26 13:34:11 +01:00
|
|
|
Attempt<IDictionaryItem, DictionaryItemOperationStatus> result = _dictionaryItemService
|
2023-03-21 12:41:20 +01:00
|
|
|
.CreateAsync(new DictionaryItem(parentId, key) { Translations = translations }, Constants.Security.SuperUserKey)
|
2023-01-26 13:34:11 +01:00
|
|
|
.GetAwaiter()
|
|
|
|
|
.GetResult();
|
|
|
|
|
// mimic old service behavior
|
|
|
|
|
return result.Success || result.Status == DictionaryItemOperationStatus.CancelledByNotification
|
|
|
|
|
? result.Result
|
2023-01-20 13:40:24 +01:00
|
|
|
: throw new ArgumentException($"Could not create a dictionary item with key: {key} under parent: {parentId}");
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-07 15:28:38 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a <see cref="IDictionaryItem" /> by its <see cref="int" /> id
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id">Id of the <see cref="IDictionaryItem" /></param>
|
|
|
|
|
/// <returns>
|
|
|
|
|
/// <see cref="IDictionaryItem" />
|
|
|
|
|
/// </returns>
|
2023-01-26 13:34:11 +01:00
|
|
|
[Obsolete("Please use IDictionaryItemService for dictionary item operations. Will be removed in V15.")]
|
2022-06-07 15:28:38 +02:00
|
|
|
public IDictionaryItem? GetDictionaryItemById(int id)
|
|
|
|
|
{
|
|
|
|
|
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
2017-12-28 09:18:09 +01:00
|
|
|
{
|
2023-02-01 09:37:37 +01:00
|
|
|
return _dictionaryRepository.Get(id);
|
2017-12-28 09:18:09 +01:00
|
|
|
}
|
2022-06-07 15:28:38 +02:00
|
|
|
}
|
2017-12-28 09:18:09 +01:00
|
|
|
|
2022-06-07 15:28:38 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a <see cref="IDictionaryItem" /> by its <see cref="Guid" /> id
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id">Id of the <see cref="IDictionaryItem" /></param>
|
|
|
|
|
/// <returns>
|
|
|
|
|
/// <see cref="DictionaryItem" />
|
|
|
|
|
/// </returns>
|
2023-01-26 13:34:11 +01:00
|
|
|
[Obsolete("Please use IDictionaryItemService for dictionary item operations. Will be removed in V15.")]
|
2022-06-07 15:28:38 +02:00
|
|
|
public IDictionaryItem? GetDictionaryItemById(Guid id)
|
2023-01-26 13:34:11 +01:00
|
|
|
=> _dictionaryItemService.GetAsync(id).GetAwaiter().GetResult();
|
2017-12-28 09:18:09 +01:00
|
|
|
|
2022-10-05 12:14:43 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a collection <see cref="IDictionaryItem" /> by their <see cref="Guid" /> ids
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ids">Ids of the <see cref="IDictionaryItem" /></param>
|
|
|
|
|
/// <returns>
|
|
|
|
|
/// A collection of <see cref="IDictionaryItem" />
|
|
|
|
|
/// </returns>
|
2023-01-26 13:34:11 +01:00
|
|
|
[Obsolete("Please use IDictionaryItemService for dictionary item operations. Will be removed in V15.")]
|
2022-10-05 12:14:43 +02:00
|
|
|
public IEnumerable<IDictionaryItem> GetDictionaryItemsByIds(params Guid[] ids)
|
2023-01-26 13:34:11 +01:00
|
|
|
=> _dictionaryItemService.GetManyAsync(ids).GetAwaiter().GetResult();
|
2022-10-05 12:14:43 +02:00
|
|
|
|
2022-06-07 15:28:38 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a <see cref="IDictionaryItem" /> by its key
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="key">Key of the <see cref="IDictionaryItem" /></param>
|
|
|
|
|
/// <returns>
|
|
|
|
|
/// <see cref="IDictionaryItem" />
|
|
|
|
|
/// </returns>
|
2023-01-26 13:34:11 +01:00
|
|
|
[Obsolete("Please use IDictionaryItemService for dictionary item operations. Will be removed in V15.")]
|
2022-06-07 15:28:38 +02:00
|
|
|
public IDictionaryItem? GetDictionaryItemByKey(string key)
|
2023-01-26 13:34:11 +01:00
|
|
|
=> _dictionaryItemService.GetAsync(key).GetAwaiter().GetResult();
|
2017-12-28 09:18:09 +01:00
|
|
|
|
2022-10-05 12:14:43 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a collection of <see cref="IDictionaryItem" /> by their keys
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="keys">Keys of the <see cref="IDictionaryItem" /></param>
|
|
|
|
|
/// <returns>
|
|
|
|
|
/// A collection of <see cref="IDictionaryItem" />
|
|
|
|
|
/// </returns>
|
2023-01-26 13:34:11 +01:00
|
|
|
[Obsolete("Please use IDictionaryItemService for dictionary item operations. Will be removed in V15.")]
|
2022-10-05 12:14:43 +02:00
|
|
|
public IEnumerable<IDictionaryItem> GetDictionaryItemsByKeys(params string[] keys)
|
2023-01-26 13:34:11 +01:00
|
|
|
=> _dictionaryItemService.GetManyAsync(keys).GetAwaiter().GetResult();
|
2022-10-05 12:14:43 +02:00
|
|
|
|
2023-01-26 13:34:11 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a list of children for a <see cref="IDictionaryItem"/>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="parentId">Id of the parent</param>
|
|
|
|
|
/// <returns>An enumerable list of <see cref="IDictionaryItem"/> objects</returns>
|
|
|
|
|
[Obsolete("Please use IDictionaryItemService for dictionary item operations. Will be removed in V15.")]
|
|
|
|
|
public IEnumerable<IDictionaryItem> GetDictionaryItemChildren(Guid parentId)
|
|
|
|
|
=> _dictionaryItemService.GetChildrenAsync(parentId).GetAwaiter().GetResult();
|
2017-12-28 09:18:09 +01:00
|
|
|
|
2022-06-07 15:28:38 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a list of descendants for a <see cref="IDictionaryItem" />
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="parentId">Id of the parent, null will return all dictionary items</param>
|
|
|
|
|
/// <returns>An enumerable list of <see cref="IDictionaryItem" /> objects</returns>
|
2023-01-26 13:34:11 +01:00
|
|
|
[Obsolete("Please use IDictionaryItemService for dictionary item operations. Will be removed in V15.")]
|
2022-06-07 15:28:38 +02:00
|
|
|
public IEnumerable<IDictionaryItem> GetDictionaryItemDescendants(Guid? parentId)
|
2023-01-26 13:34:11 +01:00
|
|
|
=> _dictionaryItemService.GetDescendantsAsync(parentId).GetAwaiter().GetResult();
|
2022-06-07 15:28:38 +02:00
|
|
|
|
2023-01-26 13:34:11 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the root/top <see cref="IDictionaryItem"/> objects
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>An enumerable list of <see cref="IDictionaryItem"/> objects</returns>
|
|
|
|
|
[Obsolete("Please use IDictionaryItemService for dictionary item operations. Will be removed in V15.")]
|
|
|
|
|
public IEnumerable<IDictionaryItem> GetRootDictionaryItems()
|
|
|
|
|
=> _dictionaryItemService.GetAtRootAsync().GetAwaiter().GetResult();
|
2017-12-28 09:18:09 +01:00
|
|
|
|
2022-06-07 15:28:38 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if a <see cref="IDictionaryItem" /> with given key exists
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="key">Key of the <see cref="IDictionaryItem" /></param>
|
|
|
|
|
/// <returns>True if a <see cref="IDictionaryItem" /> exists, otherwise false</returns>
|
2023-01-26 13:34:11 +01:00
|
|
|
[Obsolete("Please use IDictionaryItemService for dictionary item operations. Will be removed in V15.")]
|
2022-06-07 15:28:38 +02:00
|
|
|
public bool DictionaryItemExists(string key)
|
2023-01-26 13:34:11 +01:00
|
|
|
=> _dictionaryItemService.ExistsAsync(key).GetAwaiter().GetResult();
|
2017-12-28 09:18:09 +01:00
|
|
|
|
2022-06-07 15:28:38 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Saves a <see cref="IDictionaryItem" /> object
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dictionaryItem"><see cref="IDictionaryItem" /> to save</param>
|
|
|
|
|
/// <param name="userId">Optional id of the user saving the dictionary item</param>
|
2023-01-26 13:34:11 +01:00
|
|
|
[Obsolete("Please use IDictionaryItemService for dictionary item operations. Will be removed in V15.")]
|
2022-06-07 15:28:38 +02:00
|
|
|
public void Save(IDictionaryItem dictionaryItem, int userId = Constants.Security.SuperUserId)
|
2024-09-10 15:17:29 +01:00
|
|
|
{
|
2023-04-14 12:03:25 +02:00
|
|
|
Guid currentUserKey = _userIdKeyResolver.GetAsync(userId).GetAwaiter().GetResult();
|
2023-01-26 13:34:11 +01:00
|
|
|
if (dictionaryItem.Id > 0)
|
2017-12-28 09:18:09 +01:00
|
|
|
{
|
2023-03-21 12:41:20 +01:00
|
|
|
_dictionaryItemService.UpdateAsync(dictionaryItem, currentUserKey).GetAwaiter().GetResult();
|
2017-12-28 09:18:09 +01:00
|
|
|
}
|
2023-01-26 13:34:11 +01:00
|
|
|
else
|
2023-01-20 13:40:24 +01:00
|
|
|
{
|
2023-03-21 12:41:20 +01:00
|
|
|
_dictionaryItemService.CreateAsync(dictionaryItem, currentUserKey).GetAwaiter().GetResult();
|
2023-01-20 13:40:24 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-07 15:28:38 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Deletes a <see cref="IDictionaryItem" /> object and its related translations
|
|
|
|
|
/// as well as its children.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dictionaryItem"><see cref="IDictionaryItem" /> to delete</param>
|
|
|
|
|
/// <param name="userId">Optional id of the user deleting the dictionary item</param>
|
2023-01-26 13:34:11 +01:00
|
|
|
[Obsolete("Please use IDictionaryItemService for dictionary item operations. Will be removed in V15.")]
|
2022-06-07 15:28:38 +02:00
|
|
|
public void Delete(IDictionaryItem dictionaryItem, int userId = Constants.Security.SuperUserId)
|
2023-03-21 12:41:20 +01:00
|
|
|
{
|
2023-04-14 12:03:25 +02:00
|
|
|
Guid currentUserKey = _userIdKeyResolver.GetAsync(userId).GetAwaiter().GetResult();
|
2023-03-21 12:41:20 +01:00
|
|
|
_dictionaryItemService.DeleteAsync(dictionaryItem.Key, currentUserKey).GetAwaiter().GetResult();
|
|
|
|
|
}
|
2017-12-28 09:18:09 +01:00
|
|
|
|
2022-06-07 15:28:38 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a <see cref="Language" /> by its id
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id">Id of the <see cref="Language" /></param>
|
|
|
|
|
/// <returns>
|
|
|
|
|
/// <see cref="Language" />
|
|
|
|
|
/// </returns>
|
2023-01-26 13:34:11 +01:00
|
|
|
[Obsolete("Please use ILanguageService for language operations. Will be removed in V15.")]
|
2022-06-07 15:28:38 +02:00
|
|
|
public ILanguage? GetLanguageById(int id)
|
|
|
|
|
{
|
|
|
|
|
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
2017-12-28 09:18:09 +01:00
|
|
|
{
|
2022-06-07 15:28:38 +02:00
|
|
|
return _languageRepository.Get(id);
|
2017-12-28 09:18:09 +01:00
|
|
|
}
|
2022-06-07 15:28:38 +02:00
|
|
|
}
|
2017-12-28 09:18:09 +01:00
|
|
|
|
2022-06-07 15:28:38 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a <see cref="Language" /> by its iso code
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="isoCode">Iso Code of the language (ie. en-US)</param>
|
|
|
|
|
/// <returns>
|
|
|
|
|
/// <see cref="Language" />
|
|
|
|
|
/// </returns>
|
2023-01-26 13:34:11 +01:00
|
|
|
[Obsolete("Please use ILanguageService for language operations. Will be removed in V15.")]
|
2022-06-07 15:28:38 +02:00
|
|
|
public ILanguage? GetLanguageByIsoCode(string? isoCode)
|
|
|
|
|
{
|
2023-01-26 13:34:11 +01:00
|
|
|
ArgumentException.ThrowIfNullOrEmpty(isoCode);
|
|
|
|
|
return _languageService.GetAsync(isoCode).GetAwaiter().GetResult();
|
2022-06-07 15:28:38 +02:00
|
|
|
}
|
2018-04-11 15:31:21 +02:00
|
|
|
|
2022-06-07 15:28:38 +02:00
|
|
|
/// <inheritdoc />
|
2023-01-26 13:34:11 +01:00
|
|
|
[Obsolete("Please use ILanguageService for language operations. Will be removed in V15.")]
|
2022-06-07 15:28:38 +02:00
|
|
|
public int? GetLanguageIdByIsoCode(string isoCode)
|
2023-01-26 13:34:11 +01:00
|
|
|
=> _languageService.GetAsync(isoCode).GetAwaiter().GetResult()?.Id;
|
2018-04-26 16:03:08 +02:00
|
|
|
|
2022-06-07 15:28:38 +02:00
|
|
|
/// <inheritdoc />
|
2023-01-26 13:34:11 +01:00
|
|
|
[Obsolete("Please use ILanguageService for language operations. Will be removed in V15.")]
|
2022-06-07 15:28:38 +02:00
|
|
|
public string? GetLanguageIsoCodeById(int id)
|
|
|
|
|
{
|
|
|
|
|
using (ScopeProvider.CreateCoreScope(autoComplete: true))
|
2018-04-26 16:03:08 +02:00
|
|
|
{
|
2022-06-07 15:28:38 +02:00
|
|
|
return _languageRepository.GetIsoCodeById(id);
|
2018-04-26 16:03:08 +02:00
|
|
|
}
|
2022-06-07 15:28:38 +02:00
|
|
|
}
|
2018-04-26 16:03:08 +02:00
|
|
|
|
2022-06-07 15:28:38 +02:00
|
|
|
/// <inheritdoc />
|
2023-01-26 13:34:11 +01:00
|
|
|
[Obsolete("Please use ILanguageService for language operations. Will be removed in V15.")]
|
2022-06-07 15:28:38 +02:00
|
|
|
public string GetDefaultLanguageIsoCode()
|
2023-01-26 13:34:11 +01:00
|
|
|
=> _languageService.GetDefaultIsoCodeAsync().GetAwaiter().GetResult();
|
2018-04-26 16:03:08 +02:00
|
|
|
|
2022-06-07 15:28:38 +02:00
|
|
|
/// <inheritdoc />
|
2023-01-26 13:34:11 +01:00
|
|
|
[Obsolete("Please use ILanguageService for language operations. Will be removed in V15.")]
|
2022-06-07 15:28:38 +02:00
|
|
|
public int? GetDefaultLanguageId()
|
|
|
|
|
{
|
|
|
|
|
using (ScopeProvider.CreateCoreScope(autoComplete: true))
|
2017-12-28 09:18:09 +01:00
|
|
|
{
|
2022-06-07 15:28:38 +02:00
|
|
|
return _languageRepository.GetDefaultId();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets all available languages
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>An enumerable list of <see cref="ILanguage" /> objects</returns>
|
2023-01-26 13:34:11 +01:00
|
|
|
[Obsolete("Please use ILanguageService for language operations. Will be removed in V15.")]
|
2022-06-07 15:28:38 +02:00
|
|
|
public IEnumerable<ILanguage> GetAllLanguages()
|
2023-01-26 13:34:11 +01:00
|
|
|
=> _languageService.GetAllAsync().GetAwaiter().GetResult();
|
2017-12-28 09:18:09 +01:00
|
|
|
|
2022-06-07 15:28:38 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Saves a <see cref="ILanguage" /> object
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="language"><see cref="ILanguage" /> to save</param>
|
|
|
|
|
/// <param name="userId">Optional id of the user saving the language</param>
|
2023-01-26 13:34:11 +01:00
|
|
|
[Obsolete("Please use ILanguageService for language operations. Will be removed in V15.")]
|
2022-06-07 15:28:38 +02:00
|
|
|
public void Save(ILanguage language, int userId = Constants.Security.SuperUserId)
|
|
|
|
|
{
|
2023-04-14 12:03:25 +02:00
|
|
|
Guid currentUserKey = _userIdKeyResolver.GetAsync(userId).GetAwaiter().GetResult();
|
2023-01-26 13:34:11 +01:00
|
|
|
Attempt<ILanguage, LanguageOperationStatus> result = language.Id > 0
|
2023-03-21 12:41:20 +01:00
|
|
|
? _languageService.UpdateAsync(language, currentUserKey).GetAwaiter().GetResult()
|
|
|
|
|
: _languageService.CreateAsync(language, currentUserKey).GetAwaiter().GetResult();
|
2017-12-28 09:18:09 +01:00
|
|
|
|
2023-01-26 13:34:11 +01:00
|
|
|
// mimic old Save behavior
|
|
|
|
|
if (result.Status == LanguageOperationStatus.InvalidFallback)
|
|
|
|
|
{
|
2023-02-01 09:37:37 +01:00
|
|
|
throw new InvalidOperationException($"Cannot save language {language.IsoCode} with fallback {language.FallbackIsoCode}.");
|
2018-09-13 14:59:45 +02:00
|
|
|
}
|
2022-06-07 15:28:38 +02:00
|
|
|
}
|
2018-09-13 14:59:45 +02:00
|
|
|
|
2022-06-07 15:28:38 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Deletes a <see cref="ILanguage" /> by removing it (but not its usages) from the db
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="language"><see cref="ILanguage" /> to delete</param>
|
|
|
|
|
/// <param name="userId">Optional id of the user deleting the language</param>
|
2023-01-26 13:34:11 +01:00
|
|
|
[Obsolete("Please use ILanguageService for language operations. Will be removed in V15.")]
|
2022-06-07 15:28:38 +02:00
|
|
|
public void Delete(ILanguage language, int userId = Constants.Security.SuperUserId)
|
2023-03-21 12:41:20 +01:00
|
|
|
{
|
2023-04-14 12:03:25 +02:00
|
|
|
Guid currentUserKey = _userIdKeyResolver.GetAsync(userId).GetAwaiter().GetResult();
|
2023-03-21 12:41:20 +01:00
|
|
|
_languageService.DeleteAsync(language.IsoCode, currentUserKey).GetAwaiter().GetResult();
|
|
|
|
|
}
|
2017-12-28 09:18:09 +01:00
|
|
|
|
2023-01-26 13:34:11 +01:00
|
|
|
[Obsolete("Please use IDictionaryItemService for dictionary item operations. Will be removed in V15.")]
|
2022-06-07 15:28:38 +02:00
|
|
|
public Dictionary<string, Guid> GetDictionaryItemKeyMap()
|
|
|
|
|
{
|
|
|
|
|
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
|
|
|
|
{
|
|
|
|
|
return _dictionaryRepository.GetDictionaryItemKeyMap();
|
2017-12-28 09:18:09 +01:00
|
|
|
}
|
2022-06-07 15:28:38 +02:00
|
|
|
}
|
2017-12-28 09:18:09 +01:00
|
|
|
}
|