WPF.MultiLanguage 1.1.0

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

// Install WPF.MultiLanguage as a Cake Tool
#tool nuget:?package=WPF.MultiLanguage&version=1.1.0

WPF.MultiLanguage

This library is a tool designed to read JSON files and modify WPF window control properties based on the content of the files. By using this library, you can easily bind data from JSON files to WPF window controls, enabling dynamic updates to the interface. The library provides an asynchronous method, ReadJsonFileAsync, which takes the folder path, file name of the JSON file, and an instance of the window as parameters. It then modifies the specified control properties in the window based on the content of the JSON file.

In the JSON file, you can define different types of controls (such as Label, Button, etc.), specify their names, and the property values that need to be modified. When you call the ReadJsonFileAsync method, the library will parse the JSON file, locate the corresponding controls based on the file content, and then update their property values.

The purpose of this library is to allow WPF applications to dynamically update their interface based on external data, improving flexibility while enhancing code reusability and maintainability. By using this library, you can separate the appearance and content of the interface, making it easier to modify the interface and configure it according to external data sources.

Warn: Now we only support button and label, if you want more, please send an issue on GitHub.

Support .NET 6.0 to .NET 8.0.

Usage

MainWindow.caml.cs

using WPF.MultiLanguage;
using System.Windows;
using System.Windows.Controls;

namespace WpfApp1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private async void Cn_ClickAsync(object sender, RoutedEventArgs e)
        {
            await Translate.ChangeLanguageAsync("language", "zh-cn", this);
        }
    }
}

MainWindow.xaml

<Window x:Class="WpfApp1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp1"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Label x:Name="tlabel" Content="Label" HorizontalAlignment="Left" Margin="43,35,0,0" VerticalAlignment="Top"/>
        <Button x:Name="Cn" Content="cn" HorizontalAlignment="Left" Margin="43,117,0,0" VerticalAlignment="Top" Click="Cn_ClickAsync"/>
        <Button x:Name="En" Content="en" HorizontalAlignment="Left" Margin="128,127,0,0" VerticalAlignment="Top"/>
    </Grid>
</Window>

Cn.json

{
  "Label": {
    "tlabel": "Welcome to My App"
  },
  "Button": {
    "Cn": "zw",
    "En": "yw"
  }
}
Product Compatible and additional computed target framework versions.
.NET net6.0-windows7.0 is compatible.  net7.0-windows was computed.  net7.0-windows7.0 is compatible.  net8.0-windows was computed.  net8.0-windows7.0 is compatible. 
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
1.1.0 106 3/19/2024
1.0.0 89 3/14/2024