Skip to content

tifish/Jeek.Avalonia.Localization

Repository files navigation

Jeek.Avalonia.Localization

Avalonia string localization support.

  • Switch language at runtime.
  • Customizable language file format and location.
  • Simple interface, simple implementation.

Usage

  • Json language file Languages\en.json:
{
    "Welcome": "Welcome to Avalonia!"
}
  • Load language files:
Localizer.SetLocalizer(new JsonLocalizer());
  • Use localized string in .axaml:
<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        
        xmlns:l="using:Jeek.Avalonia.Localization"

        mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
        x:Class="Jeek.Avalonia.Localization.Example.MainWindow"
        Title="Jeek.Avalonia.Localization.Example">
    <StackPanel>
        
        <!-- Get the string with key Welcome -->
        <Label Content="{l:Localize Welcome}" />
        
    </StackPanel>
</Window>
  • Switch language:
Localizer.Language = "en";
  • Get localized string in code:
Localizer.Get("Welcome");

Origin

About

Avalonia localization support.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages