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,18 @@
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,18 @@
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
}
}
2 changes: 1 addition & 1 deletion src/OrchardCoreContrib.ContentLocalization/Manifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
Description = "Provides a type of conversion of a text from one script to another that involves swapping letters.",
Dependencies = new[] { "OrchardCoreContrib.ContentLocalization" },
Category = "Internationalization"
)]
)]
5 changes: 5 additions & 0 deletions src/OrchardCoreContrib.ContentLocalization/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ This module has no dependencies.
4. Enable the `Transliteration` feature.
5. Now you can inject the `ITransliterationService`, then use `Transliterate()` method to transliterate from one script to another.

### Transliteration Liquid
4. Enable the `Liquid` feature.
5. Now you can use the transliteration liquid filters: `cyr_to_lat` and `arab_to_lat`.
6. Usage: `{{ "Иванович" | cyr_to_lat }}`

## Video

[![Watch the video](https://img.youtube.com/vi/14X8fmmnOL8/maxresdefault.jpg)](https://youtu.be/14X8fmmnOL8)
Expand Down
13 changes: 12 additions & 1 deletion src/OrchardCoreContrib.ContentLocalization/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using OrchardCore.Admin;
using OrchardCore.Liquid;
using OrchardCore.Modules;
using OrchardCore.Mvc.Core.Utilities;
using OrchardCore.Navigation;
using OrchardCoreContrib.ContentLocalization.Controllers;
using OrchardCoreContrib.ContentLocalization.Liquid;
using OrchardCoreContrib.ContentLocalization.Services;
using System;

namespace OrchardCoreContrib.ContentLocalization
{
Expand Down Expand Up @@ -52,4 +53,14 @@ public override void ConfigureServices(IServiceCollection services)
services.AddScoped<ITransliterationService, TransliterationService>();
}
}

[Feature("OrchardCoreContrib.ContentLocalization.TransliterationLiquid")]
public class TransliterationLiquidStartup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddLiquidFilter<CyrToLatFilter>("cyr_to_lat");
services.AddLiquidFilter<ArabToLatFilter>("arab_to_lat");
}
}
}
Loading