Ao.Lang.AspNetCore

This is cross platform i18n library. It not only can provider static string, and it can hot reload/hot switch culture, use in wpf xaml etc... This package is base on Microsoft.Extensions.Configuration. If you want some other support files, you can intall package Microsoft.Extensions.Configuration.* or install Ao.Lang.Sources. If you want us it in wpf, you can install Ao.Lang.Wpf. Already implement *.resx and *.resources(or stream) reader. If you wan use embed resources, you can use extensions methods. If you want auto add lang files, you can named file *.zh-cn.json/*.zh-cn.resx to Raise. If you want auto add lang resources, you can named compile rex file *.zh_cn.*.resouces and index your lang identity. In 4.3.x, support argument binding! And it support wpf, uwp, avaloniaui, uno, asp.net core


Keywords
ao, lang, i18n, localization, uwp, wpf, avaloniaui, uno, asp
License
MIT
Install
Install-Package Ao.Lang.AspNetCore -Version 4.3.0

Documentation

What is this .NET codecov

It is i18n libraries. It given many solutions make your app support i18n.

And it support *.resources or *.resx file or stream load.

Why develop it

Because in many framework, has many different way to support i18n, but it can't be standard, so using Microsoft.Extensions.Configuration Key-Value mode can easy to manage i18n string block. And this library is support manay platforms.

I imagine when you want development an International application, install packages, write language files, add less code to locate files √.

I hope that international application does not spend a lot of time on designing multilingual framework, but on how to make users understand these words.

How can it do that

It is base on Microsoft.Extensions.Configuration, because i18n is Key-Value mode.

So it support hot reload, any different types of files(json/xml/ini etc...)

How to use

  1. Install package Ao.Lang, install your target platform package like Ao.Lang.Wpf, Ao.Lang.Uno
  2. Chose your like string provider file type
    • You can only install Microsoft.Extensions.Configuration.* libraries
    • You can install Ao.Lang.Sources(It will support *.json, *.xml, *.ini, *.yaml, *.resx, *.resources files)
    • You can development what you want.
  3. Create LanguageService or use default LanguageService.Default
  4. Load your strings
    • You can determine files target cultures
    • You can use automatic load, invoke LanguageMetadataExtensions.EnableAll to enable all know file types, and invoke ILangLookup.RaiseDirectory to load directory all files, it according to *.culture.ext to intercept culture block to determine culture, ext block to determine source.
    • You can use assembly load, invoke LanguageMetadataExtensions.RaiseAssemblyResources to load assembly embedded resources.
  5. In normal enviroment, you can do this to use string
var langSer = new LanguageService();
//....
var zhRoot = langSer.GetRoot("zh-cn");
var enRoot = langSer.GetRoot("en-us");

var zhTitle=zhRoot["title"];
var enTitle=enRoot["title"];

//...
  1. If you want it automatic load when resource changed, you can set Microsoft.Extensions.Configuration source property ReloadOnChanged = true
  2. If you want it support in wpf, you can install package Ao.Lang.Wpf, using Lang markupextensions to bind string resource
<Window xmlns:l="clr-namespace:System.Windows.Data;assembly=Ao.Lang.Wpf">
    <TextBlock Text="{l:Lang Title}"/>
</Window>

If you want to change language provider, you can change property LanguageManager.LangService If you want to change culture, you can change property LanguageManager.CultureInfo If you want to fixed the language string text, you can

<Window xmlns:l="clr-namespace:System.Windows.Data;assembly=Ao.Lang.Wpf">
    <TextBlock Text="{l:Lang Title,FixedCulture=zh-cn}"/>
</Window>

If you want to provider default value, you can

<Window xmlns:l="clr-namespace:System.Windows.Data;assembly=Ao.Lang.Wpf">
    <TextBlock Text="{l:Lang Title,DefaultValue=title}"/>
</Window>

If you want to non-automatic update culture string, you can

<Window xmlns:l="clr-namespace:System.Windows.Data;assembly=Ao.Lang.Wpf">
    <TextBlock Text="{l:Lang Title,NoUpdate=true}"/>
</Window>

If you want to background binding, you can

var textblock = new TextBlock();
textblock.BindLang(TextBlock.TextProperty, "Title");

Or

textblock = new TextBlock();
textblock.BindText("Title");

If you want to bind to object

LangBindExtensions.BindTo<TObj>(langMgr,obj,x=>x.prop);

If you want dynamic generator lang

Please Use package Ao.Lang.Generator, is implement json and resource compile.

After

  • Add more unit test
  • [√] Make it support MAUI, Blazor, AvaloniaUI, Uno platform...

Samples

Simple use

var langSer = new LanguageService();
langSer.EnsureGetLangNode("zh-cn")
    .AddJsonFile("lang.zh-cn.json");
langSer.EnsureGetLangNode("en-us")
    .AddJsonFile("lang.en-us.json");

var root = langSer.GetRoot(CultureInfo.CurrentCulture);

var title=root["titl"];
//.....

Use in wpf

Has file

Strings
    en_us
        lang.resx
    zh_cn
        lang.resx
var ser = LanguageManager.Instance.LangService;
ser.RaiseAssemblyResources<App>(2);
//Because resx file will compile to namespace.folders.fileName.resources
//So 2 is get from last select file block en_us/zh_cn(symbol `_` will replace to `-`)

You can watch samples\Ao.Lang.Sample or samples\Ao.Lang.Wpf.Sample

Follow #2 it can preview in design time.

Project schedule

Version Status
1.x.x In Nuget
3.0.0 In Nuget, Is was a break change for 1.x.x
4.x.x In Nuget(It was a break change for 3.0.0)

Support platform(or framework)

WPF, UWP, UNO, AvaloniaUI, Asp.NET Core...

Project extensions

Ao.SavableConfig

An can bind two way config

Structing

Structing your app like Asp.Net Core startup