mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
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:
@@ -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>
|
||||
|
||||
@{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NHibernate.Criterion;
|
||||
using Orchard.ContentManagement.Records;
|
||||
|
||||
namespace Orchard.ContentManagement {
|
||||
|
||||
26
src/Orchard/Localization/HtmlLocalizationExtensions.cs
Normal file
26
src/Orchard/Localization/HtmlLocalizationExtensions.cs
Normal 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";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using Orchard.Localization.Services;
|
||||
using Orchard.Logging;
|
||||
|
||||
|
||||
@@ -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" />
|
||||
|
||||
Reference in New Issue
Block a user