Skip to content

HereticSoftware/Metaphrase

Metaphrase

Build Action Publish Action License .NET 8 .NET 9 Downloads

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.

Packages

Package Stable Pre
Metaphrase Metaphrase Metaphrase
Metaphrase.SmartFormat Metaphrase.SmartFormat Metaphrase.SmartFormat

Usage

Description

  • Metaphrase
    • Contains the abstractions, defaults, primitives, http loader and the service.
  • Metaphrase.SmartFormat
    • Contains the SmartFormatParser.

Installation:

  • Metaphrase in projects that you want to use the service or any of the primitives.
  • Metaphrase.SmartFormat in projects that use the service and you want to replace the default parser.

Getting Started

The section will describe how to get started with Translate in a Blazor Wasm using the HttpLoader storing the language files at wwwroot/i18n.

  1. Add the Metaphrase package.
dotnet add package Metaphrase
  1. 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
  1. 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"!

Contributing

For general contribution information you can read the Raven Tail Contributing document.

Local Development

To develop you need:

  1. dotnet 9.0 SDK
  2. Visual Studio or VS Code with the C# extension.
  3. Configured your IDE for the TUnit library.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors