Skip to content

spib/i18n.core

 
 

Repository files navigation

i18n.Core

  • stable Nuget
  • pre-release: Nuget
  • Dependabot Status
Build server Platforms Build status
Github Actions windows-latest, ubuntu-latest Branch: develop i18n.core
Github Actions windows-latest, ubuntu-latest Branch: master i18n.core

Smart internationalization for ASP.NET Core

Sponsored by Finter Mobility AS. We are hiring! Check out our remote positions over at finterjobs.com.

Platforms supported

  • ASP.NET Core 3.1

Introduction

The i18n library is designed to replace the use of .NET resources in favor of an easier, globally recognized standard for localizing ASP.NET-based web applications.

Project configuration (ASP.NET CORE)

<PackageReference Include="i18n.Core" Version="1.0.10" />
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
    services.AddI18NLocalization(HostEnvironment, options =>
    {
        var supportedCultures = new[]
        {
            new CultureInfo("nb-NO"),
            new CultureInfo("en-US")
        };

        var defaultCulture = supportedCultures.Single(x => x.Name == "en-US");

        options.DefaultRequestCulture = new RequestCulture(defaultCulture);
        options.SupportedCultures = supportedCultures;
        options.SupportedUICultures = supportedCultures;
        options.RequestCultureProviders = new List<IRequestCultureProvider>
        {
            new CookieRequestCultureProvider()
        };
    });
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    app.UseI18NRequestLocalization();
}

Automatically update *.pot file (Portable Object Template)

dotnet tool install pot -g
pot --watch

Custom configuration (Web.config)

NB! This is not required for this to work as you can configure this middleware by resolving IOptions<I18NLocalizationOptions>. It's available for legacy reasons only.

<?xml version="1.0"?>

<configuration>
  <appSettings>
    <add key="i18n.DirectoriesToScan" value=".;"/>
    <add key="i18n.GenerateTemplatePerFile" value="false"/>
  </appSettings>
</configuration>

Demo

A demo project is available in this repository. You can find it here

Special thanks to

This project is mainly built on hard work of the following projects:

About

Smart internationalization for ASP.NET Core

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 93.3%
  • PowerShell 4.1%
  • HTML 1.9%
  • Other 0.7%