LazZiya.ExpressLocalization 3.1.3

Express localization settings package for dotnet core web appliations.
Localize (Views, DataAnnotations, ModelBinding, IdentityErrors, Client side validation errors and scripts) and add RouteValueRequestCultureProivder with one clean step.

There is a newer version of this package available.
See the version list below for details.
Install-Package LazZiya.ExpressLocalization -Version 3.1.3
dotnet add package LazZiya.ExpressLocalization --version 3.1.3
<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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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

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

Release Notes

- Support for DotNet Core 3.1

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
5.0.0-beta2 378 6/1/2020
5.0.0-beta1 160 5/17/2020
4.0.4 353 9/29/2020
4.0.3 204 9/24/2020
4.0.2 1,485 8/11/2020
4.0.1 1,509 5/19/2020
4.0.0 1,928 3/27/2020
4.0.0-preview1 340 2/20/2020
3.2.0 688 1/16/2020
3.1.3 825 12/18/2019
3.1.3-preview1 160 11/11/2019
3.1.2 678 10/8/2019
3.1.1 388 9/27/2019
3.0.0 409 9/25/2019
3.0.0-preview2 169 9/22/2019
3.0.0-preview1 166 9/2/2019
2.0.1 1,047 6/22/2019
2.0.0 273 6/16/2019
1.1.2 206 6/13/2019
1.1.1 254 6/3/2019
1.1.0 214 5/26/2019
1.0.0 205 5/19/2019
Show less