mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-22 03:37:25 +08:00
Move implementation of CultureConditions to CultureRuleProvider class
This commit is contained in:
@@ -1,70 +0,0 @@
|
||||
using Orchard.Events;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
|
||||
namespace Orchard.Localization.Conditions {
|
||||
public interface IConditionProvider : IEventHandler {
|
||||
void Evaluate(dynamic evaluationContext);
|
||||
}
|
||||
|
||||
public class CultureCondition : IConditionProvider {
|
||||
|
||||
private readonly WorkContext _workContext;
|
||||
|
||||
public CultureCondition(WorkContext workContext) {
|
||||
_workContext = workContext;
|
||||
}
|
||||
|
||||
public void Evaluate(dynamic evaluationContext) {
|
||||
if (String.Equals(evaluationContext.FunctionName, "culturecode", StringComparison.OrdinalIgnoreCase))
|
||||
ProcessCultureCode(evaluationContext);
|
||||
|
||||
if (String.Equals(evaluationContext.FunctionName, "culturelcid", StringComparison.OrdinalIgnoreCase))
|
||||
ProcessCultureId(evaluationContext);
|
||||
|
||||
if (String.Equals(evaluationContext.FunctionName, "cultureisrtl", StringComparison.OrdinalIgnoreCase))
|
||||
ProcessCurrentCultureIsRtl(evaluationContext);
|
||||
|
||||
if (String.Equals(evaluationContext.FunctionName, "culturelang", StringComparison.OrdinalIgnoreCase))
|
||||
ProcessLanguageCode(evaluationContext);
|
||||
}
|
||||
|
||||
private void ProcessCurrentCultureIsRtl(dynamic ruleContext) {
|
||||
var currentUserCulture = CultureInfo.GetCultureInfo(_workContext.CurrentCulture);
|
||||
|
||||
var isRtl = ((object[])ruleContext.Arguments)
|
||||
.Cast<bool>()
|
||||
.SingleOrDefault();
|
||||
|
||||
ruleContext.Result = (isRtl == currentUserCulture.TextInfo.IsRightToLeft);
|
||||
}
|
||||
|
||||
private void ProcessCultureCode(dynamic ruleContext) {
|
||||
var currentUserCulture = CultureInfo.GetCultureInfo(_workContext.CurrentCulture);
|
||||
|
||||
ruleContext.Result = ((object[])ruleContext.Arguments)
|
||||
.Cast<string>()
|
||||
.Select(CultureInfo.GetCultureInfo)
|
||||
.Any(c => c.Name == currentUserCulture.Name);
|
||||
}
|
||||
|
||||
private void ProcessLanguageCode(dynamic ruleContext) {
|
||||
var currentUserCulture = CultureInfo.GetCultureInfo(_workContext.CurrentCulture);
|
||||
|
||||
ruleContext.Result = ((object[])ruleContext.Arguments)
|
||||
.Cast<string>()
|
||||
.Select(CultureInfo.GetCultureInfo)
|
||||
.Any(c => c.Name == currentUserCulture.TwoLetterISOLanguageName);
|
||||
}
|
||||
|
||||
private void ProcessCultureId(dynamic ruleContext) {
|
||||
var currentUserCulture = CultureInfo.GetCultureInfo(_workContext.CurrentCulture);
|
||||
|
||||
ruleContext.Result = ((object[])ruleContext.Arguments)
|
||||
.Cast<int>()
|
||||
.Select(CultureInfo.GetCultureInfo)
|
||||
.Any(c => c.Name == currentUserCulture.Name);
|
||||
}
|
||||
}
|
||||
}
|
@@ -65,7 +65,6 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AdminMenu.cs" />
|
||||
<Compile Include="Conditions\CultureCondition.cs" />
|
||||
<Compile Include="Extensions\Constants.cs" />
|
||||
<Compile Include="Controllers\AdminController.cs" />
|
||||
<Compile Include="Controllers\TransliterationAdminController.cs" />
|
||||
|
@@ -8,7 +8,12 @@ namespace Orchard.Localization.RuleEngine {
|
||||
void Process(dynamic ruleContext);
|
||||
}
|
||||
|
||||
public class CultureRuleProvider : IRuleProvider {
|
||||
public interface IConditionProvider : IEventHandler {
|
||||
void Evaluate(dynamic evaluationContext);
|
||||
}
|
||||
|
||||
public class CultureRuleProvider : IRuleProvider, IConditionProvider
|
||||
{
|
||||
private readonly WorkContext _workContext;
|
||||
|
||||
public CultureRuleProvider(WorkContext workContext) {
|
||||
@@ -33,6 +38,25 @@ namespace Orchard.Localization.RuleEngine {
|
||||
}
|
||||
}
|
||||
|
||||
public void Evaluate(dynamic evaluationContext)
|
||||
{
|
||||
if (String.Equals(evaluationContext.FunctionName, "culturecode", StringComparison.OrdinalIgnoreCase)) {
|
||||
ProcessCultureCode(evaluationContext);
|
||||
}
|
||||
|
||||
if (String.Equals(evaluationContext.FunctionName, "culturelcid", StringComparison.OrdinalIgnoreCase)) {
|
||||
ProcessCultureId(evaluationContext);
|
||||
}
|
||||
|
||||
if (String.Equals(evaluationContext.FunctionName, "cultureisrtl", StringComparison.OrdinalIgnoreCase)) {
|
||||
ProcessCurrentCultureIsRtl(evaluationContext);
|
||||
}
|
||||
|
||||
if (String.Equals(evaluationContext.FunctionName, "culturelang", StringComparison.OrdinalIgnoreCase)) {
|
||||
ProcessLanguageCode(evaluationContext);
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessCurrentCultureIsRtl(dynamic ruleContext) {
|
||||
var currentUserCulture = CultureInfo.GetCultureInfo(_workContext.CurrentCulture);
|
||||
|
||||
@@ -69,5 +93,7 @@ namespace Orchard.Localization.RuleEngine {
|
||||
.Select(CultureInfo.GetCultureInfo)
|
||||
.Any(c => c.Name == currentUserCulture.Name);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user