AppText for ASP.NET Core applications
This page continues where Installation finished: a working AppText installation in an ASP.NET Core host application.
In this example, the host application itself is going to be localized with AppText.
#
ASP.NET Core localizationASP.NET Core has built-in components for localization of user interfaces, IStringLocalizer
and IViewLocalizer
. Please check the official documentation about .NET Core globalization and localization if you're not familiar with these components.
AppText has a NuGet package that enables standard .NET Core localization while using AppText to manage localized content.
#
AppText.Localization packageAdd the AppText.Localization package if you want to use AppText to manage localized content for your ASP.NET Core application:
Then, enable ASP.NET Core localization with the AppText integration in Startup.cs (note the .AddAppTextLocalization(options => ...)
call):
With the above configuration, all localized content that is displayed with IStringLocalizer or IViewLocalizer comes from AppText and you manage it on the fly with the AppText Admin interface.
#
Request localizationIn ASP.NET Core, request localization (which language is used for a specific request) is configured in Startup.cs in the Configure() method:
Normally you'd configure this with some options that specify the available cultures and the default culture, but you can also hook this up with AppText, so that the available languages and default language defined in the AppText App will become the available cultures and default culture for request localization:
You can easily check request localization by adding ?culture={apptext_supported_language}
as query string where {apptext_supported_languange} is one of the available languages in the AppText App.
#
Example applicationYou can find a working example of an ASP.NET Core MVC application that uses AppText for localization at https://github.com/martijnboland/apptext/tree/main/examples/AspNetCoreMvcExample.