Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/nepitwin/i18n.avalonia

Avalonia Internationalizing for ReactiveUi and Prism
https://github.com/nepitwin/i18n.avalonia

avalonia avaloniaui i18n linux macos prism reactive windows

Last synced: 2 months ago
JSON representation

Avalonia Internationalizing for ReactiveUi and Prism

Awesome Lists containing this project

README

        

# Avalonia Internationalizing

[license]: https://img.shields.io/github/license/Nepitwin/I18N.Avalonia?style=flat-square

[LinuxBuild]: https://github.com/Nepitwin/I18N.Avalonia/actions/workflows/linux.yml/badge.svg
[MacOSBuild]: https://github.com/Nepitwin/I18N.Avalonia/actions/workflows/macos.yml/badge.svg
[WindowsBuild]: https://github.com/Nepitwin/I18N.Avalonia/actions/workflows/windows.yml/badge.svg

[NetCore]: https://img.shields.io/badge/NetCore-blue
[3]: https://img.shields.io/badge/3-Support-blue
[5]: https://img.shields.io/badge/5-Support-blue
[6]: https://img.shields.io/badge/6-Support-blue
[7]: https://img.shields.io/badge/7-Support-blue

[Ava-0X]: https://img.shields.io/badge/0.21-Support-green
[Ava-11]: https://img.shields.io/badge/11-Support-green

[Nuget-Core]: https://buildstats.info/nuget/I18N.Avalonia?dWidth=70
[Nuget-Prism]: https://buildstats.info/nuget/I18N.Avalonia.Prism?dWidth=70
[Nuget-Reactive]: https://buildstats.info/nuget/I18N.Avalonia.ReactiveUi?dWidth=70

[Prism-Example]: https://raw.githubusercontent.com/Nepitwin/I18N.Avalonia/main/assets/Prism.gif
[Reactive-Example]: https://raw.githubusercontent.com/Nepitwin/I18N.Avalonia/main/assets/ReactiveUi.gif

| | |
|----------------|---------------------------------------------------|
| License | ![][license] |
| Builds | ![][LinuxBuild] ![][MacOSBuild] ![][WindowsBuild] |
| .NET Core | ![][3] ![][5] ![][6] ![][7] |
| Avalonia | ![][Ava-0X] ![][Ava-11] |
| Core | [![NuGet][Nuget-Core]](https://www.nuget.org/packages/I18N.Avalonia) |
| Prism | [![NuGet][Nuget-Prism]](https://www.nuget.org/packages/I18N.Avalonia.Prism) |
| Reactive | [![NuGet][Nuget-Reactive]](https://www.nuget.org/packages/I18N.Avalonia.ReactiveUi) |

| Prism | ReactiveUi |
|----------------------------------------------|---------------------------------------------------|
| ![][Prism-Example] | ![][Reactive-Example] |

# How to use it

## Ressource manager files (.resx)

* Recommended tool to manage resx files is ResXResourceManager
* https://github.com/dotnet/ResXResourceManager

### Prism registration

```dotnet
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterInstance(new Localizer(Properties.Resource.ResourceManager));
}
```

Include prism internationalizing module by .axaml

```
xmlns:i18N="clr-namespace:I18N.Avalonia.Prism;assembly=I18N.Avalonia.Prism"
```

### Usage in .axaml

```

```

### ReactiveUi registration (Splat)

```dotnet
public override void RegisterServices()
{
base.RegisterServices();
Locator.CurrentMutable.RegisterLazySingleton(() => new Localizer(Properties.Resource.ResourceManager), typeof(ILocalizer));
}
```

Include reactive internatinalizing module by .axaml

```
xmlns:i18N="clr-namespace:I18N.Avalonia.ReactiveUi;assembly=I18N.Avalonia.ReactiveUi"
```

### Usage in .axaml

```

```

### Usage in model view

```
public LanguageViewModel(ILocalizer i18N)
{
i18N.LanguageChangedNotification += OnLanguageChangedNotification;
}

private void OnLanguageChangedNotification()
{
Console.WriteLine(@"Change language to" + _localizer.Language.TwoLetterISOLanguageName);
// Your binding can be changed here or notify property changed can be called to refresh
}
```

### Language change

* After language is set all binding properties will be automatic refreshed and LanguageChangedNotification is called to refresh bindings.

```
public LanguageViewModel(ILocalizer i18N)
{
i18N.Language = new CultureInfo("de");
}
```

# Acknowledgment

Thanks to Sakya which has written this nice blog to understand this behavior and to build a nuget package with some changes.

-