TekDeq.Localization.Avalonia 0.1.0.13

dotnet add package TekDeq.Localization.Avalonia --version 0.1.0.13                
NuGet\Install-Package TekDeq.Localization.Avalonia -Version 0.1.0.13                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TekDeq.Localization.Avalonia" Version="0.1.0.13" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TekDeq.Localization.Avalonia --version 0.1.0.13                
#r "nuget: TekDeq.Localization.Avalonia, 0.1.0.13"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TekDeq.Localization.Avalonia as a Cake Addin
#addin nuget:?package=TekDeq.Localization.Avalonia&version=0.1.0.13

// Install TekDeq.Localization.Avalonia as a Cake Tool
#tool nuget:?package=TekDeq.Localization.Avalonia&version=0.1.0.13                

TekDeq.Localization Create and Publish Packages

Yet another localization library with its own abstractions gives the possibility to create localization infrastructure with examples. It contains basic Json Localization Provider implementation (other types will be added in the future).

Library

Installation

Before using the library, install following Nuget packages:

Name Description Version
TekDeq.Localization.Core Core library Nuget
TekDeq.Localization.DependencyInjection Microsoft DI extensions Nuget
TekDeq.Localization.Avalonia Avalonia Localization and Extensions Nuget

Using the library

To create additional Localization Providers, please look at ILocalizationProvider and LocalizationProviderBase abstractions. As an example of usage please look at JsonLocalizationProvider and AvaloniaJsonLocalizationProvider implementation. If you are using dependency injection in your project, an example of the usage could be found in App.axaml.cs of the demo project.

    public override void OnFrameworkInitializationCompleted()
    {
        var host = Host.CreateDefaultBuilder()
            .ConfigureServices((context, services) =>
            {
                services.UseMicrosoftDependencyResolver();
                // Initialize Splat
                var resolver = Locator.CurrentMutable;
                resolver.InitializeSplat();
                resolver.InitializeReactiveUI();

                // Register Views and ViewModels
                services.AddTransient<MainWindow>();
                services.AddTransient<MainWindowViewModel>();

                // Register Localization
                services.AddLocalization<AvaloniaJsonLocalizationProvider>(() =>
                {
                    var options = new AvaloniaLocalizationOptions(
                        // cultures support localization
                        new List<CultureInfo>
                        {
                            new("en-US"),
                            new("uk-UA")
                        },
                        // defaultCulture, it uses for setting if currentCulture is not in cultures list
                        // and as fallback culture mor missing localization entries.
                        new CultureInfo("en-US"),
                        // currentCulture sets when infrastructure loads,
                        // could be received from app settings or so.
                        Thread.CurrentThread.CurrentCulture,
                        // path to assets with json files of localization.
                        $"{typeof(App).Namespace}/Assets/i18n");
                    return options;
                });
            }).Build();


        if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
        {
            desktop.MainWindow = new MainWindow
            {
                DataContext = host.Services.GetRequiredService<MainWindowViewModel>()
            };
        }

        base.OnFrameworkInitializationCompleted();
    }

For start using the markup localization in Avalonia by Localize markup extension, it needs the namespace to be added to the markup.

<Window xmlns="https://github.com/avaloniaui"
...
        xmlns:i18n="clr-namespace:TekDeq.Localization.Avalonia.Extensions;assembly=TekDeq.Localization.Avalonia"
...
>

After this it could be used for localization of UI

    <StackPanel
...
        <TextBlock Text="{i18n:Localize Greeting}" />
...
    </StackPanel>

AvaloniaUI demo project

The DEMO project included to the repository, just open and run it in Visual Studio.

License

This project is licensed under the terms of the MIT license.

Contribute

Contributions are welcome. Just open an Issue or submit a new PR.

Contact

You can reach me via my email.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.0.13 265 3/9/2023
0.1.0.11 213 3/9/2023