V10: Fix build warnings in core (#12438)
* Run code cleanup * Start manual cleanup after dotnet format * Finish up manual pass * Fix up missed warnings * Fix after merge * Update src/Umbraco.Core/Cache/ContentTypeCacheRefresher.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/DataTypeCacheRefresher.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/DeepCloneAppCache.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/DomainCacheRefresher.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/MacroCacheRefresher.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/MediaCacheRefresher.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/MemberCacheRefresher.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/MemberGroupCacheRefresher.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Composing/OrderedCollectionBuilderBase.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Configuration/Models/RequestHandlerSettings.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Composing/SetCollectionBuilderBase.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Composing/WeightedCollectionBuilderBase.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/ContentApps/ContentAppFactoryCollectionBuilder.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Dashboards/DashboardCollectionBuilder.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/ContentTypeRefreshedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/ContentTypeSavedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/ContentTypeSavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/DictionaryCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/DataTypeCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/ContentUnpublishingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/DictionaryItemDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/DictionaryItemSavedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/DictionaryItemSavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/DomainCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/LanguageCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MacroCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaEmptiedRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaEmptyingRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaMovedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaMovedToRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaMovedToRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaMovingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaMovingToRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaTreeChangeNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaTreeChangeNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaTypeChangedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaTypeDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaTypeMovedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaTypeMovingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaTypeMovingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaTypeRefreshedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberGroupCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberGroupDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberGroupSavedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberGroupSavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeChangedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeDeletedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeMovedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeMovedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeMovingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeMovingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeRefreshedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeSavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/UriExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MovedToRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MovedToRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MovingToRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MovingToRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PartialViewDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/UriExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/IO/PhysicalFileSystem.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/IO/PhysicalFileSystem.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/IO/ShadowWrapper.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Logging/DisposableTimer.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Install/InstallSteps/UpgradeStep.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Mapping/MapDefinitionCollectionBuilder.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Media/EmbedProviders/EmbedProvidersCollectionBuilder.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PartialViewSavedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Models/ContentEditing/ContentVariationDisplay.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PartialViewSavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PublicAccessCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PublicAccessEntryDeletedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PublicAccessEntryDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PublicAccessEntryDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PublicAccessEntrySavedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PublicAccessEntrySavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PublicAccessEntrySavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/RelationTypeCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/RelationTypeDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/RelationTypeSavedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/RelationTypeSavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/StatefulNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/StylesheetDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/StylesheetSavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Models/DeepCloneHelper.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Models/File.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Models/PropertyGroupExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Models/PropertyGroupExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Fix based on review * Fix after merge Signed-off-by: Zeegaan <nge@umbraco.dk> Co-authored-by: Nikolaj Geisle <niko737@edu.ucl.dk> Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> Co-authored-by: Zeegaan <nge@umbraco.dk>
This commit is contained in:
@@ -1,30 +1,28 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Umbraco.Cms.Core.Dictionary
|
||||
namespace Umbraco.Cms.Core.Dictionary;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a dictionary based on a specific culture
|
||||
/// </summary>
|
||||
public interface ICultureDictionary
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a dictionary based on a specific culture
|
||||
/// Returns the current culture
|
||||
/// </summary>
|
||||
public interface ICultureDictionary
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the dictionary value based on the key supplied
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
string? this[string key] { get; }
|
||||
CultureInfo Culture { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current culture
|
||||
/// </summary>
|
||||
CultureInfo Culture { get; }
|
||||
/// <summary>
|
||||
/// Returns the dictionary value based on the key supplied
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
string? this[string key] { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns the child dictionary entries for a given key
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
IDictionary<string, string> GetChildren(string key);
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns the child dictionary entries for a given key
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
IDictionary<string, string> GetChildren(string key);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
namespace Umbraco.Cms.Core.Dictionary
|
||||
namespace Umbraco.Cms.Core.Dictionary;
|
||||
|
||||
public interface ICultureDictionaryFactory
|
||||
{
|
||||
public interface ICultureDictionaryFactory
|
||||
{
|
||||
ICultureDictionary CreateDictionary();
|
||||
}
|
||||
ICultureDictionary CreateDictionary();
|
||||
}
|
||||
|
||||
@@ -1,142 +1,141 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Umbraco.Cms.Core.Cache;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Extensions;
|
||||
|
||||
namespace Umbraco.Cms.Core.Dictionary
|
||||
namespace Umbraco.Cms.Core.Dictionary;
|
||||
|
||||
/// <summary>
|
||||
/// A culture dictionary that uses the Umbraco ILocalizationService
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// TODO: The ICultureDictionary needs to represent the 'fast' way to do dictionary item retrieval - for front-end and
|
||||
/// back office.
|
||||
/// The ILocalizationService is the service used for interacting with this data from the database which isn't all that
|
||||
/// fast
|
||||
/// (even though there is caching involved, if there's lots of dictionary items the caching is not great)
|
||||
/// </remarks>
|
||||
internal class DefaultCultureDictionary : ICultureDictionary
|
||||
{
|
||||
private readonly ILocalizationService _localizationService;
|
||||
private readonly IAppCache _requestCache;
|
||||
private readonly CultureInfo? _specificCulture;
|
||||
|
||||
/// <summary>
|
||||
/// A culture dictionary that uses the Umbraco ILocalizationService
|
||||
/// Default constructor which will use the current thread's culture
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// TODO: The ICultureDictionary needs to represent the 'fast' way to do dictionary item retrieval - for front-end and back office.
|
||||
/// The ILocalizationService is the service used for interacting with this data from the database which isn't all that fast
|
||||
/// (even though there is caching involved, if there's lots of dictionary items the caching is not great)
|
||||
/// </remarks>
|
||||
internal class DefaultCultureDictionary : ICultureDictionary
|
||||
/// <param name="localizationService"></param>
|
||||
/// <param name="requestCache"></param>
|
||||
public DefaultCultureDictionary(ILocalizationService localizationService, IAppCache requestCache)
|
||||
{
|
||||
private readonly ILocalizationService _localizationService;
|
||||
private readonly IAppCache _requestCache;
|
||||
private readonly CultureInfo? _specificCulture;
|
||||
_localizationService = localizationService ?? throw new ArgumentNullException(nameof(localizationService));
|
||||
_requestCache = requestCache ?? throw new ArgumentNullException(nameof(requestCache));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor which will use the current thread's culture
|
||||
/// </summary>
|
||||
/// <param name="localizationService"></param>
|
||||
/// <param name="requestCache"></param>
|
||||
public DefaultCultureDictionary(ILocalizationService localizationService, IAppCache requestCache)
|
||||
{
|
||||
_localizationService = localizationService ?? throw new ArgumentNullException(nameof(localizationService));
|
||||
_requestCache = requestCache ?? throw new ArgumentNullException(nameof(requestCache));
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructor for testing to specify a static culture
|
||||
/// </summary>
|
||||
/// <param name="specificCulture"></param>
|
||||
/// <param name="localizationService"></param>
|
||||
/// <param name="requestCache"></param>
|
||||
public DefaultCultureDictionary(CultureInfo specificCulture, ILocalizationService localizationService, IAppCache requestCache)
|
||||
{
|
||||
_localizationService = localizationService ?? throw new ArgumentNullException(nameof(localizationService));
|
||||
_requestCache = requestCache ?? throw new ArgumentNullException(nameof(requestCache));
|
||||
_specificCulture = specificCulture ?? throw new ArgumentNullException(nameof(specificCulture));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for testing to specify a static culture
|
||||
/// </summary>
|
||||
/// <param name="specificCulture"></param>
|
||||
/// <param name="localizationService"></param>
|
||||
/// <param name="requestCache"></param>
|
||||
public DefaultCultureDictionary(CultureInfo specificCulture, ILocalizationService localizationService, IAppCache requestCache)
|
||||
{
|
||||
_localizationService = localizationService ?? throw new ArgumentNullException(nameof(localizationService));
|
||||
_requestCache = requestCache ?? throw new ArgumentNullException(nameof(requestCache));
|
||||
_specificCulture = specificCulture ?? throw new ArgumentNullException(nameof(specificCulture));
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns the current culture
|
||||
/// </summary>
|
||||
public CultureInfo Culture => _specificCulture ?? Thread.CurrentThread.CurrentUICulture;
|
||||
|
||||
/// <summary>
|
||||
/// Returns the dictionary value based on the key supplied
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public string? this[string key]
|
||||
{
|
||||
get
|
||||
private ILanguage? Language =>
|
||||
|
||||
// ensure it's stored/retrieved from request cache
|
||||
// NOTE: This is no longer necessary since these are cached at the runtime level, but we can leave it here for now.
|
||||
_requestCache.GetCacheItem(
|
||||
typeof(DefaultCultureDictionary).Name + "Culture" + Culture.Name,
|
||||
() =>
|
||||
{
|
||||
var found = _localizationService.GetDictionaryItemByKey(key);
|
||||
if (found == null)
|
||||
// find a language that matches the current culture or any of its parent cultures
|
||||
CultureInfo culture = Culture;
|
||||
while (culture != CultureInfo.InvariantCulture)
|
||||
{
|
||||
return string.Empty;
|
||||
ILanguage? language = _localizationService.GetLanguageByIsoCode(culture.Name);
|
||||
if (language != null)
|
||||
{
|
||||
return language;
|
||||
}
|
||||
|
||||
culture = culture.Parent;
|
||||
}
|
||||
|
||||
var byLang = found.Translations?.FirstOrDefault(x => x.Language?.Equals(Language) ?? false);
|
||||
if (byLang == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
return byLang.Value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current culture
|
||||
/// </summary>
|
||||
public CultureInfo Culture => _specificCulture ?? System.Threading.Thread.CurrentThread.CurrentUICulture;
|
||||
|
||||
/// <summary>
|
||||
/// Returns the child dictionary entries for a given key
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
/// <remarks>
|
||||
/// NOTE: The result of this is not cached anywhere - the underlying repository does not cache
|
||||
/// the child lookups because that is done by a query lookup. This method isn't used in our codebase
|
||||
/// so I don't think this is a performance issue but if devs are using this it could be optimized here.
|
||||
/// </remarks>
|
||||
public IDictionary<string, string> GetChildren(string key)
|
||||
/// <summary>
|
||||
/// Returns the dictionary value based on the key supplied
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public string? this[string key]
|
||||
{
|
||||
get
|
||||
{
|
||||
var result = new Dictionary<string, string>();
|
||||
|
||||
var found = _localizationService.GetDictionaryItemByKey(key);
|
||||
IDictionaryItem? found = _localizationService.GetDictionaryItemByKey(key);
|
||||
if (found == null)
|
||||
{
|
||||
return result;
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
var children = _localizationService.GetDictionaryItemChildren(found.Key);
|
||||
if (children == null)
|
||||
IDictionaryTranslation? byLang =
|
||||
found.Translations.FirstOrDefault(x => x.Language?.Equals(Language) ?? false);
|
||||
if (byLang == null)
|
||||
{
|
||||
return result;
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
foreach (var dictionaryItem in children)
|
||||
{
|
||||
var byLang = dictionaryItem.Translations?.FirstOrDefault((x => x.Language?.Equals(Language) ?? false));
|
||||
if (byLang != null && dictionaryItem.ItemKey is not null && byLang.Value is not null)
|
||||
{
|
||||
result.Add(dictionaryItem.ItemKey, byLang.Value);
|
||||
}
|
||||
}
|
||||
return byLang.Value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the child dictionary entries for a given key
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
/// <remarks>
|
||||
/// NOTE: The result of this is not cached anywhere - the underlying repository does not cache
|
||||
/// the child lookups because that is done by a query lookup. This method isn't used in our codebase
|
||||
/// so I don't think this is a performance issue but if devs are using this it could be optimized here.
|
||||
/// </remarks>
|
||||
public IDictionary<string, string> GetChildren(string key)
|
||||
{
|
||||
var result = new Dictionary<string, string>();
|
||||
|
||||
IDictionaryItem? found = _localizationService.GetDictionaryItemByKey(key);
|
||||
if (found == null)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
private ILanguage? Language
|
||||
IEnumerable<IDictionaryItem>? children = _localizationService.GetDictionaryItemChildren(found.Key);
|
||||
if (children == null)
|
||||
{
|
||||
get
|
||||
return result;
|
||||
}
|
||||
|
||||
foreach (IDictionaryItem dictionaryItem in children)
|
||||
{
|
||||
IDictionaryTranslation? byLang = dictionaryItem.Translations.FirstOrDefault(x => x.Language?.Equals(Language) ?? false);
|
||||
if (byLang != null && dictionaryItem.ItemKey is not null && byLang.Value is not null)
|
||||
{
|
||||
//ensure it's stored/retrieved from request cache
|
||||
//NOTE: This is no longer necessary since these are cached at the runtime level, but we can leave it here for now.
|
||||
return _requestCache.GetCacheItem<ILanguage?>(typeof (DefaultCultureDictionary).Name + "Culture" + Culture.Name,
|
||||
() => {
|
||||
// find a language that matches the current culture or any of its parent cultures
|
||||
var culture = Culture;
|
||||
while(culture != CultureInfo.InvariantCulture)
|
||||
{
|
||||
var language = _localizationService.GetLanguageByIsoCode(culture.Name);
|
||||
if(language != null)
|
||||
{
|
||||
return language;
|
||||
}
|
||||
culture = culture.Parent;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
result.Add(dictionaryItem.ItemKey, byLang.Value);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,26 @@
|
||||
using Umbraco.Cms.Core.Cache;
|
||||
using Umbraco.Cms.Core.Cache;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
|
||||
namespace Umbraco.Cms.Core.Dictionary
|
||||
namespace Umbraco.Cms.Core.Dictionary;
|
||||
|
||||
/// <summary>
|
||||
/// A culture dictionary factory used to create an Umbraco.Core.Dictionary.ICultureDictionary.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// In the future this will allow use to potentially store dictionary items elsewhere and allows for maximum
|
||||
/// flexibility.
|
||||
/// </remarks>
|
||||
public class DefaultCultureDictionaryFactory : ICultureDictionaryFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// A culture dictionary factory used to create an Umbraco.Core.Dictionary.ICultureDictionary.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// In the future this will allow use to potentially store dictionary items elsewhere and allows for maximum flexibility.
|
||||
/// </remarks>
|
||||
public class DefaultCultureDictionaryFactory : ICultureDictionaryFactory
|
||||
private readonly AppCaches _appCaches;
|
||||
private readonly ILocalizationService _localizationService;
|
||||
|
||||
public DefaultCultureDictionaryFactory(ILocalizationService localizationService, AppCaches appCaches)
|
||||
{
|
||||
private readonly ILocalizationService _localizationService;
|
||||
private readonly AppCaches _appCaches;
|
||||
|
||||
public DefaultCultureDictionaryFactory(ILocalizationService localizationService, AppCaches appCaches)
|
||||
{
|
||||
_localizationService = localizationService;
|
||||
_appCaches = appCaches;
|
||||
}
|
||||
|
||||
public ICultureDictionary CreateDictionary()
|
||||
{
|
||||
return new DefaultCultureDictionary(_localizationService, _appCaches.RequestCache);
|
||||
}
|
||||
_localizationService = localizationService;
|
||||
_appCaches = appCaches;
|
||||
}
|
||||
|
||||
public ICultureDictionary CreateDictionary() =>
|
||||
new DefaultCultureDictionary(_localizationService, _appCaches.RequestCache);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user