mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Setting RTL on Content dynamically based on the Content or Site Culture
This commit is contained in:
@@ -18,4 +18,5 @@ Features:
|
||||
Orchard.Localization.CutlureSelector:
|
||||
Description: Enables a culture picker to localize the UI.
|
||||
Category: Content
|
||||
Name: Culture Picker
|
||||
Name: Culture Picker
|
||||
Dependencies: Orchard.Localization
|
||||
@@ -68,6 +68,7 @@
|
||||
<Compile Include="Controllers\AdminController.cs" />
|
||||
<Compile Include="Controllers\CutlureSelectorController.cs" />
|
||||
<Compile Include="Providers\CultureSelectorSelector.cs" />
|
||||
<Compile Include="Services\AdminDirectionalityFactory.cs" />
|
||||
<Compile Include="Services\CultureSelectorFactory.cs" />
|
||||
<Compile Include="Services\DefaultCultureStorageProvider.cs" />
|
||||
<Compile Include="Services\ICultureService.cs" />
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
using System.Globalization;
|
||||
using System.Web.Routing;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.DisplayManagement.Implementation;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.UI.Admin;
|
||||
|
||||
namespace Orchard.Localization.Services {
|
||||
[OrchardFeature("Orchard.Localization.CutlureSelector")]
|
||||
public class AdminDirectionalityFactory : ShapeFactoryEvents {
|
||||
private readonly ILocalizationService _localizationService;
|
||||
private readonly ICultureManager _cultureManager;
|
||||
private readonly WorkContext _workContext;
|
||||
|
||||
public AdminDirectionalityFactory(
|
||||
IWorkContextAccessor workContextAccessor,
|
||||
IShapeFactory shapeFactory,
|
||||
ILocalizationService localizationService,
|
||||
ICultureManager cultureManager) {
|
||||
_localizationService = localizationService;
|
||||
_cultureManager = cultureManager;
|
||||
_workContext = workContextAccessor.GetContext();
|
||||
Shape = shapeFactory;
|
||||
}
|
||||
|
||||
dynamic Shape { get; set; }
|
||||
|
||||
private bool IsActivable() {
|
||||
// activate on front-end only
|
||||
if (AdminFilter.IsApplied(new RequestContext(_workContext.HttpContext, new RouteData())))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Creating(ShapeCreatingContext context) {
|
||||
}
|
||||
|
||||
public override void Created(ShapeCreatedContext context) {
|
||||
if (!IsActivable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ContentItem contentItem = context.Shape.ContentItem;
|
||||
|
||||
// if not, check for ContentPart
|
||||
if (contentItem == null) {
|
||||
ContentPart contentPart = context.Shape.ContentPart;
|
||||
if (contentPart != null) {
|
||||
contentItem = contentPart.ContentItem;
|
||||
}
|
||||
}
|
||||
|
||||
var culture = (contentItem != null) ? _localizationService.GetContentCulture(contentItem) : _cultureManager.GetSiteCulture();
|
||||
|
||||
var cultureInfo = CultureInfo.GetCultureInfo(culture);
|
||||
|
||||
if (cultureInfo.TextInfo.IsRightToLeft)
|
||||
context.Shape.Attributes.Add("dir", "rtl");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ namespace Orchard.Localization.Services {
|
||||
_workContext = workContextAccessor.GetContext();
|
||||
Shape = shapeFactory;
|
||||
}
|
||||
|
||||
dynamic Shape { get; set; }
|
||||
|
||||
private bool IsActivable() {
|
||||
@@ -31,7 +32,6 @@ namespace Orchard.Localization.Services {
|
||||
_workContext.Layout.Header.Add(Shape.UICultureSelector());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
@using Orchard.ContentManagement
|
||||
@using Orchard.Localization.Services
|
||||
@using Orchard.Localization.Services
|
||||
@{
|
||||
var currentCulture = WorkContext.CurrentCulture;
|
||||
var supportedCultures = WorkContext.Resolve<ICultureManager>().ListCultures();
|
||||
|
||||
Reference in New Issue
Block a user