Add AlterAsync for a named part, Transliteration Feature - This week in Orchard (14/04/2023)

Gábor Domonkos's avatar
Localization, Documentation, This week in Orchard, Content part

Add AlterAsync for a named part, updating documentation to use Program.cs instead of Startup.cs, and a demo about the Transliteration Feature! Check out our post for the details!

Orchard Core updates

Updating documentation to use Program.cs instead of Startup.cs

Within .NET 6, Startup.cs has been sunsetted. In the new world, it is still possible to use a Startup.cs, however, it is not a mandatory class anymore. This means when upgrading, you do not need to do anything if you wish so. However, if you want your code to use some of the latest framework features, you will need to perform some refactoring by munging the two files together.

And now, the documentation for Orchard Core has been updated with new code samples to show you how to register Orchard CMS service in your Program.cs file when creating a new ASP.NET Core Web Application using Visual Studio.

Using Program.cs instead of Startup.cs

Add AlterAsync for a named part

There is an Alter extension method in Orchard Core that you can use to modify a new or existing content element by name. But the awaitable AlterAsync was missing from ContentExtensions. Now you will find an AlterAsync extension method that supports named parts like Alter.

Add AlterAsync extension method

Demos

Transliteration Feature

Transliteration helps us to pronounce words in another language whereas translation gives us the meaning of words. Transliteration changes the words from one language or alphabet into another corresponding, with similar-sounding letters with different characters.

So, for this demo, we will clone the following GitHub repository, which contains a set of modules for Orchard Core CMS that is driven by community members who love Orchard Core. This will encourage all the passionate developers to build modules that aren't included in Orchard Core. Such modules may be necessary for the community or essential for any sort of CMS.

The module that enables transliteration using the default implementation of the ITransliterationService service is called the Transliteration feature. If you run this solution and enter the admin site using the admin username and admin@OCC123 password, you can navigate to Configuration -> Features. Search for the "transliteration" word to enable the Transliteration feature. Now you can inject the ITransliterationService, then use Transliterate() method to transliterate from one script to another.

Utilizing the TransliterationService

Here you can see we injected the ITransliterationService and passed the script and the text itself which we wanted to transliterate. There is a DefaultTransliterateRuleProvider that supports converting Cyrillic and Arabic letters to Latin.

The default implementation of the ITransliterateRuleProvider

Meaning that in our example, we wanted to convert a Cyrillic text to Latin. Let's run the solution and check out the content of this page! And as you can see, we wrote "Welcome to Orchard Core" and "Feel free to browse the menu and discover all its possibilities" two times here. For the first time, we used Latin letters, and for the second time, we used Cyrillic letters. And by using the TransliterationService, the Cyrillic letters were converted to Latin.

Printing the transliterated text

And as always, if you would like to learn more about this module, don't forget to check out this recording on YouTube!

News from the community

Orchard Dojo Newsletter

Lombiq's Orchard Dojo Newsletter has 435 subscribers! We have started this newsletter to inform the community around Orchard of the latest news about the platform. By subscribing to this newsletter, you will get an e-mail whenever a new post is published to Orchard Dojo, including This week in Orchard of course.

Do you know of other Orchard enthusiasts who would like to read our weekly articles? Tell them to subscribe here!

If you are interested in more news about Orchard and the details of the topics above, don't forget to check out the recording of this Orchard meeting!

No Comments

Add a Comment