LazZiya.ExpressLocalization 3.1.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package LazZiya.ExpressLocalization --version 3.1.3
NuGet\Install-Package LazZiya.ExpressLocalization -Version 3.1.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LazZiya.ExpressLocalization" Version="3.1.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LazZiya.ExpressLocalization --version 3.1.3
#r "nuget: LazZiya.ExpressLocalization, 3.1.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install LazZiya.ExpressLocalization as a Cake Addin
#addin nuget:?package=LazZiya.ExpressLocalization&version=3.1.3

// Install LazZiya.ExpressLocalization as a Cake Tool
#tool nuget:?package=LazZiya.ExpressLocalization&version=3.1.3

What is ExpressLocalization?

A nuget package to simplify the localization of any Asp.Net Core web app to one step only. All below localization settings in one clean step:

  • Global route template: Add {culture} paramter to all routes, so urls will be like http://www.example.com/en-US/
  • RouteValueRequestCultureProvider : Register route value request culture provider, so culture selection will be based on route value
  • ViewLocalization : Use LocalizeTagHelper for localizing all razor pages depending on a shared resource. In order to use LocalizetagHelper LazZiya.TagHelpers.Localization must be installed separately.
  • DataAnnotations Localization : All data annotations validation messages and display names attributes localization
  • ModelBinding Localization : localize model binding error messages
  • IdentityErrors Localization : localize identity describer error messages
  • Client Side Validation : include all client side libraries for validating localized input fields like decimal numbers. This option requires LazZiya.TagHelpers package that will be installed automatically.

Installation

Install from nuget :

Install-Package LazZiya.ExpressLocalization

How to use

  • Install from nuget as mention above
  • Relevant localization resource files are available in LazZiya.ExpressLocalizationSample repo. Download the resources and add them to your main web project, or just create you own resource files with the relevant key names as in ExpressLocalizationResource.tr.resx file.
  • In your main project' startup.cs file, define supported cultures list then add express localization setup in one step or customized steps as mentioned below

One step setup:

This step will add all localization settings :

//add reference to :
using LazZiya.ExpressLocalization;

//setup express localization under ConfigureServices method:
public void ConfigureServices(IServiceCollection services)
{
    //other configuration settings....
    
    var cultures = new CultureInfo[]
    {
        new CultureInfo("en"),
        new CultureInfo("tr"),
        new CultureInfo("ar")
    };

    services.AddRazorPages()
        //ExpressLocalizationResource and ViewLocalizationResource are available in :
        // https://github.com/LazZiya/ExpressLocalizationSample
        .AddExpressLocalization<ExpressLocalizationResource, ViewLocalizationResource>(
            exOps =>
            {
                exOps.ResourcesPath = "LocalizationResources";
                exOps.RequestLocalizationOptions = ops =>
                {
                    ops.SupportedCultures = cultures;
                    ops.SupportedUICultures = cultures;
                    ops.DefaultRequestCulture = new RequestCulture("en");
                };
            });
}

Then configure the app to use RequestLocalizationMiddleware :

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    //other codes...
    
    //add localization middleware to the app
    app.UseRequestLocalization();

    app.UseEndpoints(endpoints =>
    {
        endpoints.MapRazorPages();
    });
}

if you are using Mvc just add the culture parameter to the route as below:

app.UseMvc(routes =>
{
    routes.MapRoute(
    name: "default",
    template: "{culture=en}/{controller=Home}/{action=Index}/{id?}",
    );
});

Also it is possible to add culture parameter to the route attributes as well:

[Route("{culture}/Home")]
public class HomeController : Controller {
     // ...
 }

For more details visit the repository GitHub page : https://github.com/LazZiya/ExpressLocalization

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 is compatible.  netcoreapp2.1 is compatible.  netcoreapp2.2 is compatible.  netcoreapp3.0 is compatible.  netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on LazZiya.ExpressLocalization:

Repository Stars
CervantesSec/cervantes
Cervantes is an open-source, collaborative platform designed specifically for pentesters and red teams. It serves as a comprehensive management tool, streamlining the organization of projects, clients, vulnerabilities, and reports in a single, centralized location.
teduinternational/eShopSolution
eShopSolution is a tutorial solution for everyone using .NET Core 3.1
Version Downloads Last updated
5.0.0-beta2 1,721 6/1/2020
5.0.0-beta1 399 5/17/2020
4.0.4 15,808 9/29/2020
4.0.3 1,444 9/24/2020
4.0.2 7,718 8/11/2020
4.0.1 5,301 5/19/2020
4.0.0 5,690 3/27/2020
4.0.0-preview1 1,545 2/20/2020
3.2.0 2,679 1/16/2020
3.1.3 3,114 12/18/2019
3.1.3-preview1 1,265 11/11/2019
3.1.2 1,929 10/8/2019
3.1.1 1,609 9/27/2019
3.0.0 1,677 9/25/2019
3.0.0-preview2 1,255 9/22/2019
3.0.0-preview1 1,232 9/2/2019
2.0.1 2,891 6/22/2019
2.0.0 1,520 6/16/2019
1.1.2 1,488 6/13/2019
1.1.1 1,565 6/3/2019
1.1.0 1,448 5/26/2019
1.0.0 1,461 5/19/2019

- Support for DotNet Core 3.1