Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add liquid filters for transliteration in ContentLocalization module. #136

Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Microsoft.Extensions.DependencyInjection;
using OrchardCore.Liquid;
using OrchardCoreContrib.ContentLocalization.Liquid;

namespace OrchardCoreContrib.ContentLocalization.Extensions;

public static class LiquidFilterServicesExtensions
{
public static void AddLiquidFilters(this IServiceCollection services)
{
services.AddLiquidFilter<CyrToLatFilter>("cyr_to_lat");
hishamco marked this conversation as resolved.
Show resolved Hide resolved
services.AddLiquidFilter<ArabToLatFilter>("arab_to_lat");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Threading.Tasks;
using Fluid;
using Fluid.Values;
using OrchardCore.Liquid;
using OrchardCoreContrib.ContentLocalization.Services;
using OrchardCoreContrib.ContentLocalization.Transliteration;

namespace OrchardCoreContrib.ContentLocalization.Liquid;

public class ArabToLatFilter(ITransliterationService transliterationService) : ILiquidFilter
{
public ValueTask<FluidValue> ProcessAsync(FluidValue input, FilterArguments arguments, LiquidTemplateContext context)
{
var text = input.ToStringValue();
return new StringValue(transliterationService.Transliterate(TransliterateScript.Arabic, text));
hishamco marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Threading.Tasks;
using Fluid;
using Fluid.Values;
using OrchardCore.Liquid;
using OrchardCoreContrib.ContentLocalization.Services;
using OrchardCoreContrib.ContentLocalization.Transliteration;

namespace OrchardCoreContrib.ContentLocalization.Liquid;

public class CyrToLatFilter(ITransliterationService transliterationService) : ILiquidFilter
{
public ValueTask<FluidValue> ProcessAsync(FluidValue input, FilterArguments arguments, LiquidTemplateContext context)
{
var text = input.ToStringValue();
return new StringValue(transliterationService.Transliterate(TransliterateScript.Cyrillic, text));
hishamco marked this conversation as resolved.
Show resolved Hide resolved
}
}
3 changes: 3 additions & 0 deletions src/OrchardCoreContrib.ContentLocalization/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using OrchardCoreContrib.ContentLocalization.Controllers;
using OrchardCoreContrib.ContentLocalization.Services;
using System;
using OrchardCoreContrib.ContentLocalization.Extensions;
hishamco marked this conversation as resolved.
Show resolved Hide resolved

namespace OrchardCoreContrib.ContentLocalization
{
Expand All @@ -29,6 +30,7 @@ public override void ConfigureServices(IServiceCollection services)
services.AddScoped<INavigationProvider, AdminMenu>();
services.AddScoped<IContentLocalizationManager, DefaultContentLocalizationManager>();
services.AddScoped<ITransliterationService, TransliterationService>();
services.AddLiquidFilters();
}

public override void Configure(IApplicationBuilder builder, IEndpointRouteBuilder routes, IServiceProvider serviceProvider)
Expand All @@ -50,6 +52,7 @@ public override void ConfigureServices(IServiceCollection services)
services.AddTransliteration();

services.AddScoped<ITransliterationService, TransliterationService>();
services.AddLiquidFilters();
}
}
}
Loading