Created CultureDictionaryFactoryResolver for use in the new MVC views which returns a ICultureDictionary.
This allows us in the future to use any type of data source for the dictionary. Have obsoleted the old ICultureDictionary in the macro engines project (where it doesn't belong anyways). The new one doesn't expose the 'Language' property to the front-end because this is a business logic class which means designers can just delete a whole language from the db by calling 'Delete' on the object !
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
using Umbraco.Core.ObjectResolution;
|
||||
|
||||
namespace Umbraco.Core.Dictionary
|
||||
{
|
||||
/// <summary>
|
||||
/// Resolves the current CultureDictionaryFactory
|
||||
/// </summary>
|
||||
internal class CultureDictionaryFactoryResolver : SingleObjectResolverBase<CultureDictionaryFactoryResolver, ICultureDictionaryFactory>
|
||||
{
|
||||
internal CultureDictionaryFactoryResolver(ICultureDictionaryFactory factory)
|
||||
: base(factory)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Can be used by developers at runtime to set their ICultureDictionaryFactory at app startup
|
||||
/// </summary>
|
||||
/// <param name="factory"></param>
|
||||
public void SetContentStore(ICultureDictionaryFactory factory)
|
||||
{
|
||||
Value = factory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the ICultureDictionaryFactory
|
||||
/// </summary>
|
||||
public ICultureDictionaryFactory Factory
|
||||
{
|
||||
get { return Value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
23
src/Umbraco.Core/Dictionary/ICultureDictionary.cs
Normal file
23
src/Umbraco.Core/Dictionary/ICultureDictionary.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Umbraco.Core.Dictionary
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a dictionary based on a specific culture
|
||||
/// </summary>
|
||||
internal interface ICultureDictionary
|
||||
{
|
||||
/// <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 current culture
|
||||
/// </summary>
|
||||
CultureInfo Culture { get; }
|
||||
}
|
||||
}
|
||||
7
src/Umbraco.Core/Dictionary/ICultureDictionaryFactory.cs
Normal file
7
src/Umbraco.Core/Dictionary/ICultureDictionaryFactory.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Umbraco.Core.Dictionary
|
||||
{
|
||||
internal interface ICultureDictionaryFactory
|
||||
{
|
||||
ICultureDictionary CreateDictionary();
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace Umbraco.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a dictionary based on a specific culture
|
||||
/// </summary>
|
||||
internal interface ICultureDictionary
|
||||
{
|
||||
string this[string key] { get; }
|
||||
CultureInfo Language { get; }
|
||||
}
|
||||
}
|
||||
@@ -55,8 +55,10 @@
|
||||
<Compile Include="Configuration\FileSystemProviderElementCollection.cs" />
|
||||
<Compile Include="Configuration\FileSystemProvidersSection.cs" />
|
||||
<Compile Include="CoreBootManager.cs" />
|
||||
<Compile Include="Dictionary\CultureDictionaryFactoryResolver.cs" />
|
||||
<Compile Include="Dictionary\ICultureDictionaryFactory.cs" />
|
||||
<Compile Include="DocumentPropertyExtensions.cs" />
|
||||
<Compile Include="ICultureDictionary.cs" />
|
||||
<Compile Include="Dictionary\ICultureDictionary.cs" />
|
||||
<Compile Include="Models\IDocument.cs" />
|
||||
<Compile Include="Models\IDocumentProperty.cs" />
|
||||
<Compile Include="ActionsResolver.cs" />
|
||||
|
||||
@@ -2,31 +2,31 @@ using Umbraco.Core.ObjectResolution;
|
||||
|
||||
namespace Umbraco.Web
|
||||
{
|
||||
/// <summary>
|
||||
/// An object resolver to return the IContentStore
|
||||
/// </summary>
|
||||
internal class ContentStoreResolver : SingleObjectResolverBase<ContentStoreResolver, IContentStore>
|
||||
{
|
||||
internal ContentStoreResolver(IContentStore contentStore)
|
||||
: base(contentStore)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Can be used by developers at runtime to set their IContentStore at app startup
|
||||
/// An object resolver to return the IContentStore
|
||||
/// </summary>
|
||||
/// <param name="contentStore"></param>
|
||||
public void SetContentStore(IContentStore contentStore)
|
||||
internal class ContentStoreResolver : SingleObjectResolverBase<ContentStoreResolver, IContentStore>
|
||||
{
|
||||
Value = contentStore;
|
||||
}
|
||||
internal ContentStoreResolver(IContentStore contentStore)
|
||||
: base(contentStore)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the IContentStore
|
||||
/// </summary>
|
||||
public IContentStore ContentStore
|
||||
{
|
||||
get { return Value; }
|
||||
/// <summary>
|
||||
/// Can be used by developers at runtime to set their IContentStore at app startup
|
||||
/// </summary>
|
||||
/// <param name="contentStore"></param>
|
||||
public void SetContentStore(IContentStore contentStore)
|
||||
{
|
||||
Value = contentStore;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the IContentStore
|
||||
/// </summary>
|
||||
public IContentStore ContentStore
|
||||
{
|
||||
get { return Value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
48
src/Umbraco.Web/Dictionary/UmbracoCultureDictionary.cs
Normal file
48
src/Umbraco.Web/Dictionary/UmbracoCultureDictionary.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Dynamic;
|
||||
using System.Globalization;
|
||||
using umbraco.cms.businesslogic;
|
||||
using umbraco.cms.businesslogic.language;
|
||||
|
||||
namespace Umbraco.Web.Dictionary
|
||||
{
|
||||
|
||||
internal class DefaultCultureDictionary : Umbraco.Core.Dictionary.ICultureDictionary
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the dictionary value based on the key supplied
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public string this[string key]
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
return new global::umbraco.cms.businesslogic.Dictionary.DictionaryItem(key).Value(Language.id);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//NOTE: SD: I'm not sure why this is here but was copied from the UmbracoCultureDictionary in the macroEngines project
|
||||
// which previously seems to have worked so I'm leaving it for now.
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current culture
|
||||
/// </summary>
|
||||
public CultureInfo Culture
|
||||
{
|
||||
get { return System.Threading.Thread.CurrentThread.CurrentUICulture; }
|
||||
}
|
||||
|
||||
private Language Language
|
||||
{
|
||||
get { return Language.GetByCultureCode(System.Threading.Thread.CurrentThread.CurrentUICulture.Name); }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace Umbraco.Web.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>
|
||||
internal class DefaultCultureDictionaryFactory : Umbraco.Core.Dictionary.ICultureDictionaryFactory
|
||||
{
|
||||
public Umbraco.Core.Dictionary.ICultureDictionary CreateDictionary()
|
||||
{
|
||||
return new DefaultCultureDictionary();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Web.Mvc;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Dictionary;
|
||||
using Umbraco.Web.Routing;
|
||||
|
||||
namespace Umbraco.Web.Mvc
|
||||
@@ -35,11 +36,12 @@ namespace Umbraco.Web.Mvc
|
||||
public dynamic CurrentPage { get; private set; }
|
||||
|
||||
private ICultureDictionary _cultureDictionary;
|
||||
public string GetDictionary(string key)
|
||||
public string GetDictionaryValue(string key)
|
||||
{
|
||||
if (_cultureDictionary == null)
|
||||
{
|
||||
_cultureDictionary = new UmbracoCultureDictionary();
|
||||
var factory = CultureDictionaryFactoryResolver.Current.Factory;
|
||||
_cultureDictionary = factory.CreateDictionary();
|
||||
}
|
||||
return _cultureDictionary[key];
|
||||
}
|
||||
|
||||
@@ -239,6 +239,8 @@
|
||||
<Link>Properties\SolutionInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="ApplicationEventsResolver.cs" />
|
||||
<Compile Include="Dictionary\UmbracoCultureDictionary.cs" />
|
||||
<Compile Include="Dictionary\UmbracoCultureDictionaryFactory.cs" />
|
||||
<Compile Include="IApplicationEvents.cs" />
|
||||
<Compile Include="umbraco.presentation\LibraryCacheRefresher.cs" />
|
||||
<Compile Include="umbraco.presentation\umbraco\nodeFactory\UmbracoSiteMapProviderAccessUpdate.cs" />
|
||||
|
||||
@@ -3,6 +3,8 @@ using System.Collections.Generic;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Dictionary;
|
||||
using Umbraco.Web.Dictionary;
|
||||
using Umbraco.Web.Media.ThumbnailProviders;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.Routing;
|
||||
@@ -151,6 +153,9 @@ namespace Umbraco.Web
|
||||
|
||||
ThumbnailProvidersResolver.Current = new ThumbnailProvidersResolver(
|
||||
PluginManager.Current.ResolveThumbnailProviders());
|
||||
|
||||
CultureDictionaryFactoryResolver.Current = new CultureDictionaryFactoryResolver(
|
||||
new DefaultCultureDictionaryFactory());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,4 +21,3 @@ using System.Runtime.InteropServices;
|
||||
[assembly: Guid("207a5ae9-5f35-4dec-a649-d3cf4d0efbd9")]
|
||||
|
||||
[assembly: InternalsVisibleTo("Umbraco.Tests")]
|
||||
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
using umbraco.cms.businesslogic.language;
|
||||
using System;
|
||||
using umbraco.cms.businesslogic.language;
|
||||
|
||||
namespace umbraco.MacroEngines {
|
||||
|
||||
public interface ICultureDictionary {
|
||||
string this[string key] { get; }
|
||||
Language Language { get; }
|
||||
}
|
||||
namespace umbraco.MacroEngines
|
||||
{
|
||||
[Obsolete("This class has been superceded by Umbraco.Core.Dictionary.ICultureDictionary")]
|
||||
public interface ICultureDictionary
|
||||
{
|
||||
string this[string key] { get; }
|
||||
Language Language { get; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,30 +1,55 @@
|
||||
using System;
|
||||
using System.Dynamic;
|
||||
using System.Globalization;
|
||||
using umbraco.cms.businesslogic;
|
||||
using umbraco.cms.businesslogic.language;
|
||||
|
||||
namespace umbraco.MacroEngines {
|
||||
namespace umbraco.MacroEngines
|
||||
{
|
||||
|
||||
public class UmbracoCultureDictionary : DynamicObject, ICultureDictionary {
|
||||
//TODO: This is legacy code now since we have the Umbraco.Core.Dictionary.ICultureDictionary and we have a DefaultCultureDictionary
|
||||
// in the Umbraco.Web project. We need to keep this here though because the new ICultureDictionary is different and
|
||||
// doesn't expose the 'Language' property because this is really poor design since the Language object exposes business
|
||||
// logic methods and designers could just call 'Delete' on the object and it will actually remove it from the database!! yikes.
|
||||
|
||||
public string this[string key] {
|
||||
get {
|
||||
try {
|
||||
return new Dictionary.DictionaryItem(key).Value(Language.id);
|
||||
} catch (Exception) { }
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
[Obsolete("This class has been superceded by Umbraco.Web.Dictionary.DefaultCultureDictionary")]
|
||||
public class UmbracoCultureDictionary : DynamicObject, ICultureDictionary, Umbraco.Core.Dictionary.ICultureDictionary
|
||||
{
|
||||
|
||||
public Language Language {
|
||||
get { return Language.GetByCultureCode(System.Threading.Thread.CurrentThread.CurrentUICulture.Name); }
|
||||
}
|
||||
public string this[string key]
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
return new Dictionary.DictionaryItem(key).Value(Language.id);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override bool TryGetMember(GetMemberBinder binder, out object result) {
|
||||
result = this[binder.Name];
|
||||
return true;
|
||||
}
|
||||
CultureInfo Umbraco.Core.Dictionary.ICultureDictionary.Culture
|
||||
{
|
||||
get
|
||||
{
|
||||
return new CultureInfo(Language.CultureAlias);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public Language Language
|
||||
{
|
||||
get { return Language.GetByCultureCode(System.Threading.Thread.CurrentThread.CurrentUICulture.Name); }
|
||||
}
|
||||
|
||||
public override bool TryGetMember(GetMemberBinder binder, out object result)
|
||||
{
|
||||
result = this[binder.Name];
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Umbraco.Web\Umbraco.Web.csproj">
|
||||
<Project>{651E1350-91B6-44B7-BD60-7207006D7003}</Project>
|
||||
<Name>umbraco.presentation</Name>
|
||||
<Name>Umbraco.Web</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user