Giter Site home page Giter Site logo

dominikheeb / i18next.net Goto Github PK

View Code? Open in Web Editor NEW

This project forked from darklikally/i18next.net

0.0 1.0 0.0 653 KB

A port of the i18next javascript library for .Net platforms based on .Net Standard 2.0

License: Apache License 2.0

C# 100.00%

i18next.net's Introduction

I18Next.Net

I18Next.Net is a port of I18Next for JavaScript. It implements most of the features provided by the original library and enhances this by some more .Net specific features.

Installation

Nuget:

Install-Package I18Next.Net

.NET Cli:

dotnet add package I18Next.Net

See Nuget for more information.

If you want to integrate with IServiceCollection also install I18Next.Net.Extensions

Install-Package I18Next.Net.Extensions

For further integration with AspNetCore you are also required to add the I18Next.Net.AspNetCore package.

Install-Package I18Next.Net.AspNetCore

See the usage information below for further help.

Basic Usage

Just for now, a quick description on how to use the library in an AspNetCore MVC application.

First you have to register the required services in your application startup. If you call the IntegrateToAspNetCore method you can use the default configuration for AspNetCore applications which includes an HTML-escaping interpolator and the language detection based on the requests Accept-Language header (internally it is based on the current thread language). I'll explain further below how to make the language detection work.

services.AddI18NextLocalization(i18n => i18n.IntegrateToAspNetCore());

Now you're ready to go using I18Next by simply injecting IStringLocalizer into your controllers and services.

// ...

private readonly IStringLocalizer<HomeController> _localizer;

public HomeController(IStringLocalizer<HomeController> localizer)
{
    _localizer = localizer;
}

public IActionResult About()
{
    ViewData["Message"] = _localizer["about.description"];

    return View();
}

// ...

If you also want to use view localization in your mvc application you should configure I18Next view localization by adding the following to your MVC builder.

services.AddMvc()
    .AddI18NextViewLocalization();

In order to make the language detection work let the app use request localization. Don't forget to specify the supported languages.

app.UseRequestLocalization(options => options.AddSupportedCultures("de", "en"));

You can always take a look at the Example.WebApp in the examples directory until there is a proper documentation about all the provided functionality.

To customize the locale file locations or use other backends just take a look at the i18next builder possibilities provided by the service registration.

services.AddI18NextLocalization(i18n => i18n
    .IntegrateToAspNetCore()
    .AddBackend(new JsonFileBackend("wwwroot/locales"))
    .UseDefaultLanguage("es"));

There are lots of more configuration options. More documentation will follow in the future.

Todo

  • Auto build pipeline
  • Further documentation
  • More tests
  • More examples
  • Configurable auto namespace/scope selection for IStringLocalizer<T>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.