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.Mvc.Html;
|
||||||
@using Orchard.UI.Resources;
|
@using Orchard.UI.Resources;
|
||||||
@{
|
@{
|
||||||
@@ -7,10 +7,10 @@
|
|||||||
|
|
||||||
string title = Convert.ToString(Model.Title);
|
string title = Convert.ToString(Model.Title);
|
||||||
string siteName = Convert.ToString(WorkContext.CurrentSite.SiteName);
|
string siteName = Convert.ToString(WorkContext.CurrentSite.SiteName);
|
||||||
bool isRtl = CultureInfo.GetCultureInfo(WorkContext.CurrentCulture).TextInfo.IsRightToLeft;
|
bool isRtl = WorkContext.CurrentCultureInfo().TextInfo.IsRightToLeft;
|
||||||
}
|
}
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="@WorkContext.CurrentCulture" class="static @Html.ClassForPage()">
|
<html lang="@WorkContext.CurrentCulture" class="static @Html.ClassForPage()" dir="@(isRtl?"rtl":"ltr")">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<title>@Html.Title(title, siteName)</title>
|
<title>@Html.Title(title, siteName)</title>
|
||||||
|
|||||||
+24
-24
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Web.Routing;
|
using System.Web.Routing;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
@@ -8,7 +9,7 @@ using Orchard.UI.Admin;
|
|||||||
|
|
||||||
namespace Orchard.Localization.Services {
|
namespace Orchard.Localization.Services {
|
||||||
[OrchardFeature("Orchard.Localization.CutlureSelector")]
|
[OrchardFeature("Orchard.Localization.CutlureSelector")]
|
||||||
public class AdminDirectionalityFactory : ShapeFactoryEvents {
|
public class AdminDirectionalityFactory : ShapeDisplayEvents {
|
||||||
private readonly ILocalizationService _localizationService;
|
private readonly ILocalizationService _localizationService;
|
||||||
private readonly ICultureManager _cultureManager;
|
private readonly ICultureManager _cultureManager;
|
||||||
private readonly WorkContext _workContext;
|
private readonly WorkContext _workContext;
|
||||||
@@ -34,33 +35,32 @@ namespace Orchard.Localization.Services {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Creating(ShapeCreatingContext context) {
|
public override void Displaying(ShapeDisplayingContext context) {
|
||||||
}
|
context.ShapeMetadata.OnDisplaying(displayedContext => {
|
||||||
|
if (!IsActivable()) {
|
||||||
public override void Created(ShapeCreatedContext context) {
|
return;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
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)
|
var culture = (contentItem != null) ? _localizationService.GetContentCulture(contentItem) : _cultureManager.GetSiteCulture();
|
||||||
context.Shape.Attributes.Add("dir", "rtl");
|
|
||||||
|
var cultureInfo = CultureInfo.GetCultureInfo(culture);
|
||||||
|
|
||||||
|
if (cultureInfo.TextInfo.IsRightToLeft)
|
||||||
|
_workContext.Layout.Content.Attributes.Add("dir", "rtl");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var mediaPickerEnabled = @(shellDescriptor.Features.Any(x => x.Name == "Orchard.MediaPicker") ? "true" : "false");
|
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 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';
|
var language = '@language';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -5,36 +5,22 @@ using Orchard.ContentManagement.Aspects;
|
|||||||
using Orchard.Mvc.Html;
|
using Orchard.Mvc.Html;
|
||||||
|
|
||||||
namespace Orchard.Localization {
|
namespace Orchard.Localization {
|
||||||
public static class HtmlLocalizationExtensions {
|
public static class LocalizationExtensions {
|
||||||
/// <summary>
|
public static CultureInfo CurrentCultureInfo(this WorkContext workContext) {
|
||||||
/// The dir attribute specifies the text direction.
|
return CultureInfo.GetCultureInfo(workContext.CurrentCulture);
|
||||||
///
|
|
||||||
/// 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public static string GetTextDirection(this WorkContext workContext) {
|
||||||
/// The dir attribute specifies the text direction of the element's content.
|
return workContext.GetTextDirection(null);
|
||||||
///
|
|
||||||
/// 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 ContentCulture(this HtmlHelper html, IContent content) {
|
public static string GetTextDirection(this WorkContext workContext, IContent content) {
|
||||||
var workContext = html.GetWorkContext();
|
|
||||||
|
|
||||||
var culture = workContext.CurrentSite.SiteCulture;
|
var culture = workContext.CurrentSite.SiteCulture;
|
||||||
if (content != null && content.Has<ILocalizableAspect>()) {
|
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