radj307.Localization.WPF 0.3.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package radj307.Localization.WPF --version 0.3.2                
NuGet\Install-Package radj307.Localization.WPF -Version 0.3.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="radj307.Localization.WPF" Version="0.3.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add radj307.Localization.WPF --version 0.3.2                
#r "nuget: radj307.Localization.WPF, 0.3.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.
// Install radj307.Localization.WPF as a Cake Addin
#addin nuget:?package=radj307.Localization.WPF&version=0.3.2

// Install radj307.Localization.WPF as a Cake Tool
#tool nuget:?package=radj307.Localization.WPF&version=0.3.2                

radj307.Localization

Easy to use localization libraries for C# & WPF.
Loosely based on CodingSeb.Localization, but is capable of both reading and writing translation config files.

Nuget Version
radj307.Localization NuGet Status
radj307.Localization.WPF NuGet Status
radj307.Localization.Json NuGet Status
radj307.Localization.Yaml NuGet Status
radj307.Localization.Xml NuGet Status

Packages

The library's functionality is divided between packages, allowing you to only install what you need.

  • radj307.Localization
    Contains the core library, the Loc class, and the translation functionality.
  • radj307.Localization.WPF
    Contains the Tr markup extension and some binding converters.
    The provided markup extension allows you to swap languages at runtime without any additional code.
  • radj307.Localization.Json
    Contains the default serializer/deserializer for JSON translation config files.
  • radj307.Localization.Yaml
    Contains the default serializer/deserializer for YAML translation config files.
  • radj307.Localization.Xml
    Contains the default serializer/deserializer for XML translation config files.

Basic Usage

C#

using Localization;

Loc.Instance.CurrentLanguageName = "English";
Loc.Instance.Translate("MainWindow.Text"); //< "Hello World!"

Loc.Instance.CurrentLanguageName = "French";
Loc.Instance.Translate("MainWindow.Text"); //< "Salut tout le monde!"

// Loc.Tr is equivalent to Loc.Instance.Translate
Loc.Tr("This.Key.Does.Not.Exist", defaultText: "Default Text!"); //< "Default Text!"

XAML

No xmlns declaration is required, the Tr markup extension is available globally.


<TextBlock Text="{Tr 'MainWindow.Text'}" />
<TextBlock Text="{Tr 'MainWindow.Text', DefaultText='(Translation Not Provided)'}" />
<TextBlock Text="{Tr {Binding MyProperty},
                     FormatString='[1]: {0} {2}',
                     FormatArgs={MakeArray {Binding Header},
                                           '\\'}}" />

Translation Config Files

Translation configs store the translated strings for your application. You can use any file format or syntax you wish by writing an ITranslationLoader implementation for it. Default loader implementations are provided for JSON & YAML documents.

While it is recommended to keep languages separate for maintainability, there is nothing stopping you from saving multiple languages in the same file.

JSON

Syntax used by the JsonTranslationLoader class:

{
  "MainWindow": {
    "Text": {
      "English": "Hello World!",
      "French": "Salut tout le monde!"
    }
  }
}

Alternative syntax used by the JsonSingleTranslationLoader class:

{
  "$LanguageName": "English",

  "MainWindow": {
    "Text": "Hello World!"
  }
}

JsonSingleTranslationLoader only supports 1 language per file, but the syntax is much easier to write.

YAML

Syntax used by the YamlTranslationLoader class:

MainWindow:
  Text:
    English: "Hello World!"
    French: "Salut tout le monde!"
Product Compatible and additional computed target framework versions.
.NET net6.0-windows7.0 is compatible.  net7.0-windows was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on radj307.Localization.WPF:

Package Downloads
VolumeControl.SDK

Official Addon SDK for the Volume Control application.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.3.3 324 11/22/2023
0.3.2 136 11/17/2023
0.3.1 136 11/17/2023
0.3.0 131 11/16/2023
0.2.0 124 11/15/2023
0.1.0 126 11/13/2023
0.0.0 136 11/13/2023