Mtf.Windows.Forms.LanguageService 3.0.37

dotnet add package Mtf.Windows.Forms.LanguageService --version 3.0.37
                    
NuGet\Install-Package Mtf.Windows.Forms.LanguageService -Version 3.0.37
                    
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="Mtf.Windows.Forms.LanguageService" Version="3.0.37" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Mtf.Windows.Forms.LanguageService" Version="3.0.37" />
                    
Directory.Packages.props
<PackageReference Include="Mtf.Windows.Forms.LanguageService" />
                    
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 Mtf.Windows.Forms.LanguageService --version 3.0.37
                    
#r "nuget: Mtf.Windows.Forms.LanguageService, 3.0.37"
                    
#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.
#addin nuget:?package=Mtf.Windows.Forms.LanguageService&version=3.0.37
                    
Install Mtf.Windows.Forms.LanguageService as a Cake Addin
#tool nuget:?package=Mtf.Windows.Forms.LanguageService&version=3.0.37
                    
Install Mtf.Windows.Forms.LanguageService as a Cake Tool

Translator Class Documentation

The Translator class provides functionality to translate Windows Forms controls, forms, and their children recursively. It integrates with the Lng class to provide multilingual support by updating the Text property of controls and related UI elements.


Namespace

Mtf.LanguageService.Windows.Forms

Methods

Translate(Form form)

Translates a Form and all its child controls.

  • Parameters:
    • form (Form): The Form to be translated.
  • Exceptions:
    • ArgumentNullException: Thrown if form is null.

Translate(UserControl userControl)

Translates a UserControl and all its child controls.

  • Parameters:
    • userControl (UserControl): The UserControl to be translated.
  • Exceptions:
    • ArgumentNullException: Thrown if userControl is null.

Translate(Control.ControlCollection controls)

Recursively translates a collection of controls.

  • Parameters:
    • controls (Control.ControlCollection): The collection of controls to be translated.
  • Exceptions:
    • ArgumentNullException: Thrown if controls is null.

Translate(DataGridView dataGridView)

Translates the headers of a DataGridView.

  • Parameters:
    • dataGridView (DataGridView): The DataGridView to be translated.

Translate(TreeNode node)

Recursively translates a TreeNode and its child nodes.

  • Parameters:
    • node (TreeNode): The TreeNode to be translated.

Translate(ComboBox comboBox, ComboBox.ObjectCollection items)

Translates the items in a ComboBox.

  • Parameters:
    • comboBox (ComboBox): The ComboBox whose items will be translated.
    • items (ComboBox.ObjectCollection): The collection of items to be translated.

Translate(ToolStripItemCollection toolStripItems)

Translates a collection of ToolStripItem objects.

  • Parameters:
    • toolStripItems (ToolStripItemCollection): The collection of tool strip items to be translated.
  • Exceptions:
    • ArgumentNullException: Thrown if toolStripItems is null.

Translate(Menu.MenuItemCollection items) (Only for .NET Framework 4.8.1 and below)

Translates a collection of MenuItem objects.

  • Parameters:
    • items (Menu.MenuItemCollection): The collection of menu items to be translated.

Features

  1. Control Types Supported:

    • Label, Button, TextBox, ListView, TreeView, MenuStrip, StatusStrip, ComboBox, ContextMenuStrip, DataGridView, and more.
  2. Recursive Translation:

    • Child elements of controls like TreeView.Nodes or MenuStrip.Items are translated recursively.
  3. Integration with Lng Class:

    • Uses Lng.Elem for translating strings based on the application's current language.
  4. Framework Compatibility:

    • Contains conditional compilation directives for compatibility with .NET Framework 4.8.1 (#if NET481).

Usage Example

using System.Windows.Forms;
using Mtf.LanguageService.Windows.Forms;

class Program
{
    static void Main()
    {
        // Example Form
        var form = new Form
        {
            Text = "Main Form"
        };

        // Example Controls
        var button = new Button
        {
            Text = "Click Me",
            Location = new System.Drawing.Point(10, 10)
        };

        var label = new Label
        {
            Text = "Hello World",
            Location = new System.Drawing.Point(10, 50)
        };

        form.Controls.Add(button);
        form.Controls.Add(label);

        // Translate the Form and all its controls
        Translator.Translate(form);

        Application.Run(form);
    }
}
using Mtf.LanguageService;
using Mtf.LanguageService.Windows.Forms;

public partial class MainForm : Form
{
	public MainForm()
	{
		InitializeComponent();
		
		lv.ItemsSource = new[] { Lng.Elem("Users"), Lng.Elem("Groups") };
		rtb.Document.Blocks.Add(new Paragraph(new Run(Lng.Elem("File name"))));
		
		Translator.Translate(this);
	}
}

If you need to translate to Hungarian, just use this code snippet.

Lng.DefaultLanguage = Mtf.LanguageService.Language.Hungarian;
Translator.Translate(this);

You can translate from any language to any other language like this.

Lng.Translate(Language.Hungarian, "Ismétlődés", Language.English);

Notes

  1. Error Handling:

    • Ensures null checks for all inputs to avoid runtime errors.
  2. Non-Translatable Elements:

    • Elements like WebBrowser are explicitly skipped during translation.
  3. Customization:

    • Extend or modify translation behavior by overriding the Lng.Elem method.
  4. Conditional Compilation:

    • MenuItemCollection translation is only available for .NET Framework.

Links

GitHub URL Developer's URL Facebook Page

Product Compatible and additional computed target framework versions.
.NET net8.0-windows7.0 is compatible.  net9.0-windows was computed.  net9.0-windows7.0 is compatible. 
.NET Framework net452 is compatible.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 is compatible.  net481 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
3.0.37 87 3/27/2025
3.0.35 89 1/29/2025
3.0.34 76 1/29/2025
3.0.33 74 1/13/2025
3.0.32 72 1/13/2025
3.0.31 82 1/13/2025
3.0.30 69 1/10/2025
2.0.29 85 1/9/2025
2.0.26 99 12/21/2024
2.0.25 87 12/21/2024
2.0.24 96 12/21/2024
2.0.23 98 12/6/2024
2.0.21 96 11/30/2024
2.0.20 94 11/30/2024
2.0.19 93 11/29/2024
2.0.18 78 11/27/2024
2.0.17 96 11/26/2024
2.0.16 94 11/25/2024
1.0.10 104 11/14/2024
1.0.9 116 10/4/2024
1.0.8 105 10/4/2024
1.0.6 374 12/3/2022
1.0.5 540 11/14/2020
1.0.4 555 8/7/2020
1.0.3 461 8/7/2020
1.0.2 530 7/19/2020
1.0.1 691 5/13/2020 1.0.1 is deprecated because it has critical bugs.

Rename to Mtf.LanguageService.