Tpig.Components.Localization 1.2.3

dotnet add package Tpig.Components.Localization --version 1.2.3                
NuGet\Install-Package Tpig.Components.Localization -Version 1.2.3                
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="Tpig.Components.Localization" Version="1.2.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Tpig.Components.Localization --version 1.2.3                
#r "nuget: Tpig.Components.Localization, 1.2.3"                
#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 Tpig.Components.Localization as a Cake Addin
#addin nuget:?package=Tpig.Components.Localization&version=1.2.3

// Install Tpig.Components.Localization as a Cake Tool
#tool nuget:?package=Tpig.Components.Localization&version=1.2.3                

Tpig.Components.Localization, .NET Version

A .NET WPF library to switch languages. Here is sample:

public MainWindow() {
    InitializeComponent();
    // initialize current locale to "en"
    LocaleManager.Instance.Current = "en";
    // load "en" language file/resource
    Localize.Load(this);
}

After that, switching language is just:

LocaleManager.Instance.Current = "th";

or:

LocaleManager.Instance.Current = "en";

Create String Files

First, you have to create string resource file. This file should have to folder "Locales" (it can be change) and this file must have prefix "Lang" (still, it can be change). Here is an example file "Locales\Lang.xaml":

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:sys="clr-namespace:System;assembly=System.Runtime">
    <sys:String x:Key="Text1">Localization</sys:String>
</ResourceDictionary>

When you want to use "Lang.xaml" in UI, first, include this in xaml, like this:

<Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/Locales/Lang.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Window.Resources>

and use DynamicResource, such as:

<TextBlock Text="{DynamicResource Text1}"/>

Create Localize Files

After you created "Lang.xaml". You have to create localization file. Example that you want to create Thai localization. It can be done by create file "Lang.th-TH.xaml" or "Lang.th_TH.xaml" or just "Lang.th.xaml".

Code in "Lang.th.xaml" may look like this:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:sys="clr-namespace:System;assembly=System.Runtime">
    <sys:String x:Key="Text1">แปลเป็นภาษาไทย</sys:String>
</ResourceDictionary>

Now, load file in construction UI, like this:

public SomeWindow() {
    InitializeComponent();
    Localize.Load(this);
}

Finally, when you want to change language, here:

LocaleManager.Instance.Current = "th";

Demo

These sample programs show how to use various features.

  • Tpig.Demonstrates.Basic: provide enough basic functional
  • Tpig.Demonstrates.TestNotify: show how to use interface NotifyChangeLanguage
  • Tpig.Demonstrates.TestDll: show how to use DLL

Requirements

  • .NET version 6.0

NuGet

You can retrieve package at https://www.nuget.org/packages/Tpig.Components.Localization.

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.
  • net6.0-windows7.0

    • No dependencies.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Tpig.Components.Localization:

Package Downloads
Tpig.Boosters

Package Description

Tpig.Components.CustomUi

.NET WPF custom-made UI components.

Tpig.Components.TogetherUi

Together UI codes for .NET version.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.3 90 7/10/2024
1.2.2 110 7/9/2024
1.2.1 106 6/15/2024
1.2.0 342 12/16/2021
1.1.0 1,106 11/29/2020
1.0.5 792 11/25/2020
1.0.4 836 2/19/2020
1.0.3 756 2/13/2020
1.0.2 592 1/22/2020
1.0.1 496 1/10/2020
1.0.0 556 1/8/2020