forked from DarthFubuMVC/fubumvc
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated FubuCore ref to clean up some trash, added the basic localiza…
…tion support and bootstrapping
- Loading branch information
1 parent
3ba77bb
commit 15aab95
Showing
61 changed files
with
632 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="Bottles" version="0.9.1.156" /> | ||
<package id="Bottles.Deployers.IIS" version="0.9.1.156" /> | ||
<package id="Bottles.Deployment" version="0.9.1.156" /> | ||
<package id="Bottles" version="0.9.1.137" /> | ||
<package id="Bottles.Deployers.IIS" version="0.9.1.137" /> | ||
<package id="Bottles.Deployment" version="0.9.1.137" /> | ||
<package id="CommonServiceLocator" version="1.0" /> | ||
<package id="DotNetZip" version="1.9.1.8" /> | ||
<package id="FubuCore" version="0.9.2.96" /> | ||
<package id="FubuCore" version="0.9.2.93" /> | ||
<package id="HtmlTags" version="1.0.0.23" /> | ||
<package id="structuremap" version="2.6.3" /> | ||
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System.Globalization; | ||
using Bottles; | ||
using FubuCore; | ||
using FubuLocalization; | ||
using FubuLocalization.Basic; | ||
using FubuMVC.Core.Registration.ObjectGraph; | ||
|
||
namespace FubuMVC.Core.Localization | ||
{ | ||
public class BasicLocalizationSupport : IFubuRegistryExtension | ||
{ | ||
private readonly FubuPackageRegistry _internalRegistry = new FubuPackageRegistry(); | ||
private bool _useTheDefaultStorageMechanism = true; | ||
private ObjectDef _localizationLoader; | ||
|
||
public BasicLocalizationSupport() | ||
{ | ||
_internalRegistry.Services(x => | ||
{ | ||
x.SetServiceIfNone(new CultureInfo("en-US")); | ||
x.SetServiceIfNone<ILocalizationCache, LocalizationCache>(); | ||
x.SetServiceIfNone<ILocalizationMissingHandler, LocalizationMissingHandler>(); | ||
x.SetServiceIfNone<ILocalizationProviderFactory, LocalizationProviderFactory>(); | ||
}); | ||
|
||
_internalRegistry.HtmlConvention(x => x.Labels.Builder<LabelBuilder>()); | ||
|
||
} | ||
|
||
public CultureInfo DefaultCulture | ||
{ | ||
set | ||
{ | ||
_internalRegistry.Services(x => x.ReplaceService(value)); | ||
} | ||
} | ||
|
||
void IFubuRegistryExtension.Configure(FubuRegistry registry) | ||
{ | ||
_internalRegistry.As<IFubuRegistryExtension>().Configure(registry); | ||
|
||
registry.Services(x => | ||
{ | ||
if (_useTheDefaultStorageMechanism) | ||
{ | ||
x.AddService<IActivator, RegisterXmlDirectoryLocalizationStorage>(); | ||
} | ||
if (_localizationLoader != null) | ||
{ | ||
x.AddService(typeof (IActivator), _localizationLoader); | ||
} | ||
x.AddService<IActivator, SpinUpLocalizationCaches>(); | ||
}); | ||
|
||
|
||
} | ||
|
||
public void LoadLocalizationWith<T>() where T : IActivator | ||
{ | ||
_localizationLoader = ObjectDef.ForType<T>(); | ||
_useTheDefaultStorageMechanism = false; | ||
} | ||
|
||
public void LocalizationStorageIs<T>() where T : ILocalizationStorage | ||
{ | ||
_internalRegistry.Services(x => x.ReplaceService<ILocalizationStorage, T>()); | ||
_useTheDefaultStorageMechanism = false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using FubuLocalization; | ||
using FubuMVC.Core.UI.Configuration; | ||
using HtmlTags; | ||
|
||
namespace FubuMVC.Core.Localization | ||
{ | ||
public class LabelBuilder : ElementBuilder | ||
{ | ||
protected override bool matches(AccessorDef def) | ||
{ | ||
return true; | ||
} | ||
|
||
public override HtmlTag Build(ElementRequest request) | ||
{ | ||
string header = LocalizationManager.GetHeader(request.Accessor.InnerProperty); | ||
return new HtmlTag("label").Attr("for", request.ElementId).Text(header); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/FubuMVC.Core/Localization/RegisterXmlDirectoryLocalizationStorage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.Collections.Generic; | ||
using Bottles; | ||
using Bottles.Diagnostics; | ||
using FubuLocalization.Basic; | ||
using FubuMVC.Core.Bootstrapping; | ||
using FubuMVC.Core.Packaging; | ||
using FubuMVC.Core.Registration.ObjectGraph; | ||
|
||
namespace FubuMVC.Core.Localization | ||
{ | ||
public class RegisterXmlDirectoryLocalizationStorage : IActivator | ||
{ | ||
private readonly IContainerFacility _facility; | ||
|
||
public RegisterXmlDirectoryLocalizationStorage(IContainerFacility facility) | ||
{ | ||
_facility = facility; | ||
} | ||
|
||
public void Activate(IEnumerable<IPackageInfo> packages, IPackageLog log) | ||
{ | ||
var list = new List<string>(); | ||
log.Trace("Setting up the {0} with directories", typeof(XmlDirectoryLocalizationStorage).Name); | ||
|
||
list.Add(FubuMvcPackageFacility.GetApplicationPath()); | ||
|
||
packages.Each(pak => pak.ForFolder(BottleFiles.WebContentFolder, list.Add)); | ||
|
||
var storage = new XmlDirectoryLocalizationStorage(list); | ||
|
||
_facility.Register(typeof(ILocalizationStorage), ObjectDef.ForValue(storage)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Collections.Generic; | ||
using Bottles; | ||
using Bottles.Diagnostics; | ||
using FubuLocalization.Basic; | ||
|
||
namespace FubuMVC.Core.Localization | ||
{ | ||
public class SpinUpLocalizationCaches : IActivator | ||
{ | ||
private readonly ILocalizationProviderFactory _factory; | ||
|
||
public SpinUpLocalizationCaches(ILocalizationProviderFactory factory) | ||
{ | ||
_factory = factory; | ||
} | ||
|
||
public void Activate(IEnumerable<IPackageInfo> packages, IPackageLog log) | ||
{ | ||
_factory.LoadAll(text => log.Trace(text)); | ||
_factory.ApplyToLocalizationManager(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="Bottles" version="0.9.1.156" /> | ||
<package id="Bottles.Deployment" version="0.9.1.156" /> | ||
<package id="Bottles" version="0.9.1.137" /> | ||
<package id="Bottles.Deployment" version="0.9.1.137" /> | ||
<package id="CommonServiceLocator" version="1.0" /> | ||
<package id="DotNetZip" version="1.9.1.8" /> | ||
<package id="FubuCore" version="0.9.2.96" /> | ||
<package id="FubuLocalization" version="0.9.2.96" /> | ||
<package id="FubuCore" version="0.9.2.93" /> | ||
<package id="FubuLocalization" version="0.9.2.85" /> | ||
<package id="HtmlTags" version="1.0.0.23" /> | ||
<package id="structuremap" version="2.6.3" /> | ||
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="Bottles" version="0.9.1.156" /> | ||
<package id="Bottles.Deployers.IIS" version="0.9.1.156" /> | ||
<package id="Bottles.Deployment" version="0.9.1.156" /> | ||
<package id="Bottles" version="0.9.1.137" /> | ||
<package id="Bottles.Deployers.IIS" version="0.9.1.137" /> | ||
<package id="Bottles.Deployment" version="0.9.1.137" /> | ||
<package id="CommonServiceLocator" version="1.0" /> | ||
<package id="DotNetZip" version="1.9.1.8" /> | ||
<package id="FubuCore" version="0.9.2.96" /> | ||
<package id="FubuCore" version="0.9.2.93" /> | ||
<package id="HtmlTags" version="1.0.0.23" /> | ||
<package id="structuremap" version="2.6.3" /> | ||
</packages> |
Oops, something went wrong.