Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/darklikally/i18next.net
A port of the i18next javascript library for .Net platforms based on .Net Standard 2.0
https://github.com/darklikally/i18next.net
csharp dotnet dotnet-core dotnet-standard i18n i18next internationalization localization translation
Last synced: 3 days ago
JSON representation
A port of the i18next javascript library for .Net platforms based on .Net Standard 2.0
- Host: GitHub
- URL: https://github.com/darklikally/i18next.net
- Owner: DarkLiKally
- License: apache-2.0
- Created: 2018-09-11T14:33:03.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-03-22T22:30:14.000Z (10 months ago)
- Last Synced: 2024-12-06T09:05:27.988Z (about 1 month ago)
- Topics: csharp, dotnet, dotnet-core, dotnet-standard, i18n, i18next, internationalization, localization, translation
- Language: C#
- Homepage:
- Size: 707 KB
- Stars: 54
- Watchers: 5
- Forks: 30
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](https://www.nuget.org/packages/I18Next.Net/) 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.
```csharp
services.AddI18NextLocalization(i18n => i18n.IntegrateToAspNetCore());
```Now you're ready to go using I18Next by simply injecting `IStringLocalizer` into your controllers and services.
```csharp
// ...private readonly IStringLocalizer _localizer;
public HomeController(IStringLocalizer localizer)
{
_localizer = localizer;
}public IActionResult About()
{
ViewData["Message"] = _localizer["about.description"];return View();
}// ...
```If you also want to use [view localization](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-2.1#view-localization)
in your mvc application you should configure I18Next view localization by adding the following to your MVC builder.
```csharp
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.
```csharp
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.
```csharp
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`