AnyBar.Localization 0.0.2

dotnet add package AnyBar.Localization --version 0.0.2
                    
NuGet\Install-Package AnyBar.Localization -Version 0.0.2
                    
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="AnyBar.Localization" Version="0.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AnyBar.Localization" Version="0.0.2" />
                    
Directory.Packages.props
<PackageReference Include="AnyBar.Localization" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AnyBar.Localization --version 0.0.2
                    
#r "nuget: AnyBar.Localization, 0.0.2"
                    
#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.
#:package AnyBar.Localization@0.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AnyBar.Localization&version=0.0.2
                    
Install as a Cake Addin
#tool nuget:?package=AnyBar.Localization&version=0.0.2
                    
Install as a Cake Tool

AnyBar Localization Toolkit

Localization toolkit for AnyBar and its plugins, which helps AnyBar plugin developers make the localization process easier.

Getting Started

Install and reference AnyBar.Localization via NuGet.

Build Properties

These are properties you can configure in your .csproj file to customize the localization process. You can set them in the <PropertyGroup> section. For example, to set the AnyBarUseDependencyInjection property to true, add the following lines:

<PropertyGroup>
    <AnyBarUseDependencyInjection>true</AnyBarUseDependencyInjection>
</PropertyGroup>

AnyBarUseDependencyInjection

This flag specifies whether to use dependency injection to obtain an IPublicAPI instance. The default is false.

  • If set to false, the main class (which must implement IPlugin or IAsyncPlugin) must have a PluginInitContext property that is at least internal static.
  • If set to true, you can access the IPublicAPI instance via PublicApi.Instance using dependency injection, and the main class does not need to include a PluginInitContext property.

Usage

Main Class

The main class must implement IPluginI18n.

If AnyBarUseDependencyInjection is false, include a PluginInitContext property, for example:

// Must implement IPluginI18n
public class Main : IPlugin, IPluginI18n
{
    // Must be at least internal static
    internal static PluginInitContext Context { get; private set; } = null!;
}

Localized Strings

You can simplify your code by replacing calls like:

Context.API.GetTranslation("AnyBar_Plugin_Localization_Demo_Plugin_Name")

with:

Localize.AnyBar_Plugin_Localization_Demo_Plugin_Name()

If your localization string uses variables, it becomes even simpler! From this:

string.Format(Context.API.GetTranslation("AnyBar_Plugin_Localization_Demo_Value_With_Keys"), firstName, lastName);

To this:

Localize.AnyBar_Plugin_Localization_Demo_Value_With_Keys(firstName, lastName);

If you would like to add summary for functions of localization strings, you need to comment strings in xaml files like this:


<system:String x:Key="AnyBar_Plugin_Localization_Demo_Plugin_Name">Demo</system:String>

Or if you would like to change the default types or names of variables in localization strings, you need to comment strings in xaml file like this:


<system:String x:Key="AnyBar_Plugin_Localization_Demo_Value_With_Keys">Demo {2:00}, {1,-35:D} and {0}</system:String>

Localized Enums

For enum types (e.g., DemoEnum) that need localization in UI controls such as combo boxes, use the EnumLocalize attribute to enable localization. For each enum field:

  • Use EnumLocalizeKey to provide a custom localization key.
  • Use EnumLocalizeValue to provide a constant localization string.

Example:

[EnumLocalize] // Enable localization support
public enum DemoEnum
{
    // Specific localization key
    [EnumLocalizeKey("localize_key_1")]
    Value1,

    // Specific localization value
    [EnumLocalizeValue("This is my enum value localization")]
    Value2,

    // Key takes precedence if both are present
    [EnumLocalizeKey("localize_key_3")]
    [EnumLocalizeValue("Localization Value")]
    Value3,

    // Using the Localize class. This way, you can't misspell localization keys, and if you rename
    // them in your .xaml file, you won't forget to rename them here as well because the build will fail.
    [EnumLocalizeKey(nameof(Localize.Anybar_Plugin_Localization_Demo_Plugin_Description))]
    Value4,
}

Then, use the generated DemoEnumLocalized class within your view model to bind to a combo box control:

// ComboBox ItemSource
public List<DemoEnumLocalized> AllDemoEnums { get; } = DemoEnumLocalized.GetValues();

// ComboBox SelectedValue
public DemoEnum SelectedDemoEnum { get; set; }

In your XAML, bind as follows:

<ComboBox
    DisplayMemberPath="Display"
    ItemsSource="{Binding AllDemoEnums}"
    SelectedValue="{Binding SelectedDemoEnum}"
    SelectedValuePath="Value" />

To update localization strings when the language changes, you can call:

DemoEnumLocalize.UpdateLabels(AllDemoEnums);
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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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.

This package has no dependencies.

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.0.2 279 10/12/2025
0.0.1 162 10/12/2025