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: 8 months ago
JSON representation
Avalonia Internationalizing for ReactiveUi and Prism
- Host: GitHub
- URL: https://github.com/nepitwin/i18n.avalonia
- Owner: Nepitwin
- License: apache-2.0
- Created: 2023-07-13T15:33:12.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2025-06-02T09:53:30.000Z (about 1 year ago)
- Last Synced: 2025-10-06T17:49:43.443Z (9 months ago)
- Topics: avalonia, avaloniaui, i18n, linux, macos, prism, reactive, windows
- Language: C#
- Homepage:
- Size: 435 KB
- Stars: 10
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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?branch=main
[MacOSBuild]: https://github.com/Nepitwin/I18N.Avalonia/actions/workflows/macos.yml/badge.svg?branch=main
[WindowsBuild]: https://github.com/Nepitwin/I18N.Avalonia/actions/workflows/windows.yml/badge.svg?branch=main
[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
[8]: https://img.shields.io/badge/8-Support-blue
[9]: https://img.shields.io/badge/9-Support-blue
[Ava-0X]: https://img.shields.io/badge/0.21-Support-green
[Ava-11]: https://img.shields.io/badge/11-Support-green
[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] ![][8] ![][9] |
| Avalonia | ![][Ava-0X] ![][Ava-11] |
| Core | [](https://www.nuget.org/packages/I18N.Avalonia) |
| Prism | [](https://www.nuget.org/packages/I18N.Avalonia.Prism) |
| 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.
-