Mtf.Windows.Forms.LanguageService
3.1.16
dotnet add package Mtf.Windows.Forms.LanguageService --version 3.1.16
NuGet\Install-Package Mtf.Windows.Forms.LanguageService -Version 3.1.16
<PackageReference Include="Mtf.Windows.Forms.LanguageService" Version="3.1.16" />
<PackageVersion Include="Mtf.Windows.Forms.LanguageService" Version="3.1.16" />
<PackageReference Include="Mtf.Windows.Forms.LanguageService" />
paket add Mtf.Windows.Forms.LanguageService --version 3.1.16
#r "nuget: Mtf.Windows.Forms.LanguageService, 3.1.16"
#:package Mtf.Windows.Forms.LanguageService@3.1.16
#addin nuget:?package=Mtf.Windows.Forms.LanguageService&version=3.1.16
#tool nuget:?package=Mtf.Windows.Forms.LanguageService&version=3.1.16
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): TheFormto be translated.
- Exceptions:
ArgumentNullException: Thrown ifformisnull.
Translate(UserControl userControl)
Translates a UserControl and all its child controls.
- Parameters:
userControl(UserControl): TheUserControlto be translated.
- Exceptions:
ArgumentNullException: Thrown ifuserControlisnull.
Translate(Control.ControlCollection controls)
Recursively translates a collection of controls.
- Parameters:
controls(Control.ControlCollection): The collection of controls to be translated.
- Exceptions:
ArgumentNullException: Thrown ifcontrolsisnull.
Translate(DataGridView dataGridView)
Translates the headers of a DataGridView.
- Parameters:
dataGridView(DataGridView): TheDataGridViewto be translated.
Translate(TreeNode node)
Recursively translates a TreeNode and its child nodes.
- Parameters:
node(TreeNode): TheTreeNodeto be translated.
Translate(ComboBox comboBox, ComboBox.ObjectCollection items)
Translates the items in a ComboBox.
- Parameters:
comboBox(ComboBox): TheComboBoxwhose 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 iftoolStripItemsisnull.
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
Control Types Supported:
Label,Button,TextBox,ListView,TreeView,MenuStrip,StatusStrip,ComboBox,ContextMenuStrip,DataGridView, and more.
Recursive Translation:
- Child elements of controls like
TreeView.NodesorMenuStrip.Itemsare translated recursively.
- Child elements of controls like
Integration with
LngClass:- Uses
Lng.Elemfor translating strings based on the application's current language.
- Uses
Framework Compatibility:
- Contains conditional compilation directives for compatibility with .NET Framework 4.8.1 (
#if NET481).
- Contains conditional compilation directives for compatibility with .NET Framework 4.8.1 (
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
Error Handling:
- Ensures null checks for all inputs to avoid runtime errors.
Non-Translatable Elements:
- Elements like
WebBrowserare explicitly skipped during translation.
- Elements like
Customization:
- Extend or modify translation behavior by overriding the
Lng.Elemmethod.
- Extend or modify translation behavior by overriding the
Conditional Compilation:
MenuItemCollectiontranslation is only available for .NET Framework.
Links
| Product | Versions 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. net10.0-windows was computed. |
| .NET Framework | net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 is compatible. |
-
.NETFramework 4.6.2
- Mtf.Extensions (>= 1.0.16)
-
.NETFramework 4.8.1
- Mtf.Extensions (>= 1.0.16)
-
net8.0-windows7.0
- Mtf.Extensions (>= 1.0.16)
-
net9.0-windows7.0
- Mtf.Extensions (>= 1.0.16)
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.1.16 | 256 | 6/13/2025 | |
| 3.0.96 | 160 | 6/6/2025 | |
| 3.0.84 | 192 | 5/26/2025 | |
| 3.0.64 | 203 | 5/22/2025 | |
| 3.0.49 | 196 | 5/20/2025 | |
| 3.0.46 | 203 | 5/20/2025 | |
| 3.0.45 | 192 | 5/20/2025 | |
| 3.0.44 | 179 | 5/20/2025 | |
| 3.0.39 | 161 | 4/6/2025 | |
| 3.0.37 | 174 | 3/27/2025 | |
| 3.0.35 | 163 | 1/29/2025 | |
| 3.0.34 | 120 | 1/29/2025 | |
| 3.0.33 | 133 | 1/13/2025 | |
| 3.0.32 | 123 | 1/13/2025 | |
| 3.0.31 | 148 | 1/13/2025 | |
| 3.0.30 | 143 | 1/10/2025 | |
| 2.0.29 | 151 | 1/9/2025 | |
| 2.0.26 | 162 | 12/21/2024 | |
| 2.0.25 | 163 | 12/21/2024 | |
| 2.0.24 | 156 | 12/21/2024 | |
| 2.0.23 | 144 | 12/6/2024 | |
| 2.0.21 | 164 | 11/30/2024 | |
| 2.0.20 | 167 | 11/30/2024 | |
| 2.0.19 | 162 | 11/29/2024 | |
| 2.0.18 | 137 | 11/27/2024 | |
| 2.0.17 | 158 | 11/26/2024 | |
| 2.0.16 | 155 | 11/25/2024 | |
| 1.0.10 | 165 | 11/14/2024 | |
| 1.0.9 | 173 | 10/4/2024 | |
| 1.0.8 | 158 | 10/4/2024 | |
| 1.0.6 | 455 | 12/3/2022 | |
| 1.0.5 | 665 | 11/14/2020 | |
| 1.0.4 | 689 | 8/7/2020 | |
| 1.0.3 | 569 | 8/7/2020 | |
| 1.0.2 | 662 | 7/19/2020 | |
| 1.0.1 | 885 | 5/13/2020 |