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

https://github.com/kulikov-dev/avalonia.localizer

Easy-to-use localization provider for the AvaloniaUI
https://github.com/kulikov-dev/avalonia.localizer

avalonia avaloniaui example-project l10n localization localization-tool xunit

Last synced: 9 months ago
JSON representation

Easy-to-use localization provider for the AvaloniaUI

Awesome Lists containing this project

README

          

## Avalonia localizer
The sample project comes with a ready-to-use localization provider, allowing for dynamic runtime localization using the [AvaloniaUI](https://github.com/AvaloniaUI/Avalonia) framework. The idea is to create JSON files as assets. Each file contains a key and translation according to the locale:
``` JSON
{
"EnumSample": "Primer pretvornika enum",
"car": "Avto",
"plane": "Letalo",
"bicycle": "Kolo",
"SampleTranslate": "To je primer besedila, uporabljenega za lokalizacijo."
}
```
Than you can use the localizer in XAML, code or with enums:
``` C#
\\ XAML
xmlns:localization="clr-namespace:Avalonia.Localizer.Core.Localization"

\\ XAML for Enum



\\ Code
var localized = ProgramCore.Localizer["plane"];

\\ In Enum, where in the Description attribute we use the localization key
public enum SampleEnum
{
[Description("car")]
Car,
}

EnumDescriptionConverter.GetEnumDescription(SampleEnum.Car);
```
Thanks to bindings, we can change the locale in the runtime with just one line of code:
``` C#
ProgramCore.Localizer.SwitchLanguage("en-US");
```

Credits to [sakya](https://github.com/sakya/) for the idea.