Adding a localization extension, and making the directionality for tinymce be based on if the content has a ILocalizationAspect or not. Doing this ensures that you are not affected by the current culture of your site. If you do not has a ILocalizationAspect, then reason dictates that you should always use the site culture, not the current culture and new items are created using the site culture not the current culture.

This commit is contained in:
Nicholas Mayne
2014-08-09 12:17:10 +01:00
parent 43fa4cdc96
commit 0b365cf7f0
5 changed files with 30 additions and 6 deletions

View File

@@ -1,15 +1,15 @@
@using System.Globalization
@using Orchard.ContentManagement
@using Orchard.Environment.Descriptor.Models
@using Orchard.Localization
@{
var shellDescriptor = WorkContext.Resolve<ShellDescriptor>();
var currentCulture = CultureInfo.GetCultureInfo(WorkContext.CurrentCulture);
}
<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 = '@(currentCulture.TextInfo.IsRightToLeft ? "rtl" : "ltr")';
var directionality = '@Html.Directionality((IContent)Model.ContentItem)';
</script>
@{

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NHibernate.Criterion;
using Orchard.ContentManagement.Records;
namespace Orchard.ContentManagement {

View File

@@ -0,0 +1,26 @@
using System.Globalization;
using System.Web.Mvc;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects;
using Orchard.Mvc.Html;
namespace Orchard.Localization {
public static class HtmlLocalizationExtensions {
/// <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) {
var workContext = html.GetWorkContext();
var culture = workContext.CurrentSite.SiteCulture;
if (content.Has<ILocalizableAspect>()) {
culture = content.As<ILocalizableAspect>().Culture;
}
return CultureInfo.GetCultureInfo(culture).TextInfo.IsRightToLeft ? "rtl" : "ltr";
}
}
}

View File

@@ -1,7 +1,5 @@
using System;
using System.Globalization;
using System.Linq;
using System.Web;
using Orchard.Localization.Services;
using Orchard.Logging;

View File

@@ -261,6 +261,7 @@
<Compile Include="FileSystems\Media\FileSystemStorageProvider.cs" />
<Compile Include="FileSystems\Media\IMimeTypeProvider.cs" />
<Compile Include="Indexing\ISearchBits.cs" />
<Compile Include="Localization\HtmlLocalizationExtensions.cs" />
<Compile Include="Localization\Models\DateLocalizationOptions.cs" />
<Compile Include="Localization\Models\DateParts.cs" />
<Compile Include="Localization\Models\DateTimeParts.cs" />