Skip to content

Cricle/Ao.Lang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

81 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

An can bind two way config

Structing your app like Asp.Net Core startup

About

Cross platform i18n framework

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages