Crysta.Locale 0.1.3

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

// Install Crysta.Locale as a Cake Tool
#tool nuget:?package=Crysta.Locale&version=0.1.3

Crysta

Introduction

The "Crysta.Locale" provides the mechanism of the localization (switching displayed texts) for the WPF Application.

How to use

At first, declares some reference to the namespace as below.

using Crysta;
using Crysta.Locale;

In the initializer of the view-model class, you initialize the Crysta.Locale.LanguageSource class as below. <br/>And then publishs it as a public property to binding in the Xaml.

namespace SampleProject 
{

	/// <summary>
	/// A bindable object (View-model in the MVVM design pattern or Presenter in the MVP design pattern) for the MainWindow.DataContext property.
	/// </summary>
	internal class MainPresenter : Presenter<MainWindow>
	{
		
		public MainPresenter() {
	
		    // Instantizes a new instance.
		    _LangSrc = new();
		    
	#if UsingJson
		    
		    // Makes a full-path specifies a language table file. (In this example, Specifies the path relatied application root directry.)
		    // You have to reference the resource file with "Build Action" property is "Content" and "Copy to Output Dictionary" property is "Copy always".
		    string en = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources\LanguageResource.en.json");
		    string ja = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources\LanguageResource.ja.json");
		    
		    // Registers it to the <see cref="LanguageSource"/> object.
		    _LangSrc.RegisterFromJSONFile(new System.Globalization.CultureInfo("en-US", false), en);
		    _LangSrc.RegisterFromJSONFile(new System.Globalization.CultureInfo("ja-JP", false), ja);
		    
	#else
		    
		    // Registers your <see cref="IDictionary{string, string}"/> (key:string, value:string) object with a <see cref="CultureInfo"/> key the corresponding to it.
		    
		    IDictionary<string, string>; enDic = new Dictionary<string, string>();
		    IDictionary<string, string>; jaDic = new Dictionary<string, string>();
		    
		    /* Adds your interpret definitions */
		    
		    _LangSrc.Register(new System.Globalization.CultureInfo("en-US", false), enDic);
		    _LangSrc.Register(new System.Globalization.CultureInfo("ja-JP", false), jaDic);
		    
	#endif
		}
	
	
		LanguageSource _LangSrc;
	
		// Publish as a binding property.
		LanguageSource Texts => _LangSrc;
	}

}

<br/> How to make the language table file (.json)

{
  "MyKey1": "Key1Value"
  "MyKey2": "Key2Value"
  ...
}

You make any number of the file corresponding to each languages.

<br/>

How to bind to the text content in the view (.xaml):

<Label Content="{Binding Lang.Current[MyKey1]}"/>
<TextBox Text="{Binding Lang.Current[MyKey2]}"/>

<br/> How to switch displayed language texts (.cs):


private void MyMethod() {
	// Set a new desired culture into the application UI's culture property.
	CultureInfo.CurrentUICulture = new("en-US");

	// Refreshs all of the binded texts in the UI.
	_LangSrc.UpdateCulture();
}

Product Compatible and additional computed target framework versions.
.NET net5.0-windows7.0 is compatible.  net6.0-windows was computed.  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.
  • net5.0-windows7.0

    • 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.1.3 109 2/13/2024
0.1.1 76 1/16/2024
0.1.0 77 1/15/2024