mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
More work to RTL/LTR conversion
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
@using System.Globalization
|
||||
@using Orchard.Localization
|
||||
@using Orchard.Mvc.Html;
|
||||
@using Orchard.UI.Resources;
|
||||
@{
|
||||
@@ -7,10 +7,10 @@
|
||||
|
||||
string title = Convert.ToString(Model.Title);
|
||||
string siteName = Convert.ToString(WorkContext.CurrentSite.SiteName);
|
||||
bool isRtl = CultureInfo.GetCultureInfo(WorkContext.CurrentCulture).TextInfo.IsRightToLeft;
|
||||
bool isRtl = WorkContext.CurrentCultureInfo().TextInfo.IsRightToLeft;
|
||||
}
|
||||
<!DOCTYPE html>
|
||||
<html lang="@WorkContext.CurrentCulture" class="static @Html.ClassForPage()">
|
||||
<html lang="@WorkContext.CurrentCulture" class="static @Html.ClassForPage()" dir="@(isRtl?"rtl":"ltr")">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>@Html.Title(title, siteName)</title>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Web.Routing;
|
||||
using Orchard.ContentManagement;
|
||||
@@ -8,7 +9,7 @@ using Orchard.UI.Admin;
|
||||
|
||||
namespace Orchard.Localization.Services {
|
||||
[OrchardFeature("Orchard.Localization.CutlureSelector")]
|
||||
public class AdminDirectionalityFactory : ShapeFactoryEvents {
|
||||
public class AdminDirectionalityFactory : ShapeDisplayEvents {
|
||||
private readonly ILocalizationService _localizationService;
|
||||
private readonly ICultureManager _cultureManager;
|
||||
private readonly WorkContext _workContext;
|
||||
@@ -34,33 +35,32 @@ namespace Orchard.Localization.Services {
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Creating(ShapeCreatingContext context) {
|
||||
}
|
||||
|
||||
public override void Created(ShapeCreatedContext context) {
|
||||
if (!IsActivable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (context.ShapeType != "Zone")
|
||||
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;
|
||||
public override void Displaying(ShapeDisplayingContext context) {
|
||||
context.ShapeMetadata.OnDisplaying(displayedContext => {
|
||||
if (!IsActivable()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (context.ShapeMetadata.Type != "Zone")
|
||||
return;
|
||||
|
||||
var culture = (contentItem != null) ? _localizationService.GetContentCulture(contentItem) : _cultureManager.GetSiteCulture();
|
||||
ContentItem contentItem = context.Shape.ContentItem;
|
||||
|
||||
var cultureInfo = CultureInfo.GetCultureInfo(culture);
|
||||
// if not, check for ContentPart
|
||||
if (contentItem == null) {
|
||||
ContentPart contentPart = context.Shape.ContentPart;
|
||||
if (contentPart != null) {
|
||||
contentItem = contentPart.ContentItem;
|
||||
}
|
||||
}
|
||||
|
||||
if (cultureInfo.TextInfo.IsRightToLeft)
|
||||
context.Shape.Attributes.Add("dir", "rtl");
|
||||
var culture = (contentItem != null) ? _localizationService.GetContentCulture(contentItem) : _cultureManager.GetSiteCulture();
|
||||
|
||||
var cultureInfo = CultureInfo.GetCultureInfo(culture);
|
||||
|
||||
if (cultureInfo.TextInfo.IsRightToLeft)
|
||||
_workContext.Layout.Content.Attributes.Add("dir", "rtl");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@
|
||||
<script type="text/javascript">
|
||||
var mediaPickerEnabled = @(shellDescriptor.Features.Any(x => x.Name == "Orchard.MediaPicker") ? "true" : "false");
|
||||
var mediaLibraryEnabled = @(shellDescriptor.Features.Any(x => x.Name == "Orchard.MediaLibrary") ? "true" : "false");
|
||||
var directionality = '@Html.Directionality((IContent)Model.ContentItem)';
|
||||
var directionality = '@WorkContent.GetTextDirection((IContent)Model.ContentItem)';
|
||||
var language = '@language';
|
||||
</script>
|
||||
|
||||
|
||||
@@ -5,36 +5,22 @@ using Orchard.ContentManagement.Aspects;
|
||||
using Orchard.Mvc.Html;
|
||||
|
||||
namespace Orchard.Localization {
|
||||
public static class HtmlLocalizationExtensions {
|
||||
/// <summary>
|
||||
/// The dir attribute specifies the text direction.
|
||||
///
|
||||
/// Returns rtl or ltr based on if your content has an ILocalizableAspect or not.
|
||||
/// </summary>
|
||||
/// <returns>Returns rtl or ltr</returns>
|
||||
public static string Directionality(this HtmlHelper html) {
|
||||
return html.Directionality(null);
|
||||
public static class LocalizationExtensions {
|
||||
public static CultureInfo CurrentCultureInfo(this WorkContext workContext) {
|
||||
return CultureInfo.GetCultureInfo(workContext.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The dir attribute specifies the text direction of the element's content.
|
||||
///
|
||||
/// Returns rtl or ltr based on if your content has an ILocalizableAspect or not.
|
||||
/// </summary>
|
||||
/// <returns>Returns rtl or ltr</returns>
|
||||
public static string Directionality(this HtmlHelper html, IContent content) {
|
||||
return CultureInfo.GetCultureInfo(html.ContentCulture(content)).TextInfo.IsRightToLeft ? "rtl" : "ltr";
|
||||
public static string GetTextDirection(this WorkContext workContext) {
|
||||
return workContext.GetTextDirection(null);
|
||||
}
|
||||
|
||||
public static string ContentCulture(this HtmlHelper html, IContent content) {
|
||||
var workContext = html.GetWorkContext();
|
||||
|
||||
public static string GetTextDirection(this WorkContext workContext, IContent content) {
|
||||
var culture = workContext.CurrentSite.SiteCulture;
|
||||
if (content != null && content.Has<ILocalizableAspect>()) {
|
||||
return content.As<ILocalizableAspect>().Culture;
|
||||
culture = content.As<ILocalizableAspect>().Culture;
|
||||
}
|
||||
|
||||
return culture;
|
||||
return CultureInfo.GetCultureInfo(culture).TextInfo.IsRightToLeft ? "rtl" : "ltr"; ;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user