A C# port of the ngx-translate. The port is not one to one and also aims to be more C# friendly where possible.
The library provides you with a TranslateService which combined with a TranslateLoader (HttpLoader built in) enables you to load, compile and display your translations. You format the strings keys. For a much stronger formatting a package that uses the awesome SmartFormat project is provided.
| Package | Stable | Pre |
|---|---|---|
| Metaphrase | ||
| Metaphrase.SmartFormat |
Description
- Metaphrase
- Contains the
abstractions,defaults,primitives,http loaderand theservice.
- Contains the
- Metaphrase.SmartFormat
- Contains the
SmartFormatParser.
- Contains the
Installation:
Metaphrasein projects that you want to use the service or any of the primitives.Metaphrase.SmartFormatin projects that use the service and you want to replace the default parser.
The section will describe how to get started with Translate in a Blazor Wasm using the HttpLoader storing the language files at wwwroot/i18n.
- Add the
Metaphrasepackage.
dotnet add package Metaphrase- Add the appropriate services to the service provider.
services.AddScoped(sp => new HttpClient() { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
services.AddScoped<TranslateLoader, TranslateHttpLoader>(); // This will use the default options
services.AddScoped<TranslateService>(); // This will use the default parser- Use the service
TranslateService also supports a "pipe" syntax to get your translation values.
For the tanslation key: hello and value: Hello you can do:
translate.Instant("hello") // prints "Hello"
translate | "hello" // prints "Hello"For the translation key: welcome, value: Welcome {user}! and param: user.
translate.Instant("hello", new { user = "panos" }) // prints "Welcome panos"!
translate | "hello" | new { user = "panos" } // prints "Welcome panos"!For general contribution information you can read the Raven Tail Contributing document.
To develop you need:
- dotnet 9.0 SDK
- Visual Studio or VS Code with the C# extension.
- Configured your IDE for the TUnit library.