Mtf.Windows.Forms.LanguageService
2.0.20
See the version list below for details.
dotnet add package Mtf.Windows.Forms.LanguageService --version 2.0.20
NuGet\Install-Package Mtf.Windows.Forms.LanguageService -Version 2.0.20
<PackageReference Include="Mtf.Windows.Forms.LanguageService" Version="2.0.20" />
paket add Mtf.Windows.Forms.LanguageService --version 2.0.20
#r "nuget: Mtf.Windows.Forms.LanguageService, 2.0.20"
// Install Mtf.Windows.Forms.LanguageService as a Cake Addin #addin nuget:?package=Mtf.Windows.Forms.LanguageService&version=2.0.20 // Install Mtf.Windows.Forms.LanguageService as a Cake Tool #tool nuget:?package=Mtf.Windows.Forms.LanguageService&version=2.0.20
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
): TheForm
to be translated.
- Exceptions:
ArgumentNullException
: Thrown ifform
isnull
.
Translate(UserControl userControl)
Translates a UserControl
and all its child controls.
- Parameters:
userControl
(UserControl
): TheUserControl
to be translated.
- Exceptions:
ArgumentNullException
: Thrown ifuserControl
isnull
.
Translate(Control.ControlCollection controls)
Recursively translates a collection of controls.
- Parameters:
controls
(Control.ControlCollection
): The collection of controls to be translated.
- Exceptions:
ArgumentNullException
: Thrown ifcontrols
isnull
.
Translate(DataGridView dataGridView)
Translates the headers of a DataGridView
.
- Parameters:
dataGridView
(DataGridView
): TheDataGridView
to be translated.
Translate(TreeNode node)
Recursively translates a TreeNode
and its child nodes.
- Parameters:
node
(TreeNode
): TheTreeNode
to be translated.
Translate(ComboBox comboBox, ComboBox.ObjectCollection items)
Translates the items in a ComboBox
.
- Parameters:
comboBox
(ComboBox
): TheComboBox
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 iftoolStripItems
isnull
.
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.Nodes
orMenuStrip.Items
are translated recursively.
- Child elements of controls like
Integration with
Lng
Class:- Uses
Lng.Elem
for 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
WebBrowser
are explicitly skipped during translation.
- Elements like
Customization:
- Extend or modify translation behavior by overriding the
Lng.Elem
method.
- Extend or modify translation behavior by overriding the
Conditional Compilation:
MenuItemCollection
translation 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-windows7.0 is compatible. |
.NET Framework | net481 is compatible. |
-
.NETFramework 4.8.1
- System.IO.Compression (>= 4.3.0)
-
net8.0-windows7.0
- System.IO.Compression (>= 4.3.0)
-
net9.0-windows7.0
- System.IO.Compression (>= 4.3.0)
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 | |
---|---|---|---|
2.0.23 | 80 | 12/6/2024 | |
2.0.21 | 83 | 11/30/2024 | |
2.0.20 | 82 | 11/30/2024 | |
2.0.19 | 81 | 11/29/2024 | |
2.0.18 | 69 | 11/27/2024 | |
2.0.17 | 82 | 11/26/2024 | |
2.0.16 | 86 | 11/25/2024 | |
1.0.10 | 96 | 11/14/2024 | |
1.0.9 | 111 | 10/4/2024 | |
1.0.8 | 98 | 10/4/2024 | |
1.0.6 | 360 | 12/3/2022 | |
1.0.5 | 519 | 11/14/2020 | |
1.0.4 | 531 | 8/7/2020 | |
1.0.3 | 440 | 8/7/2020 | |
1.0.2 | 509 | 7/19/2020 | |
1.0.1 | 651 | 5/13/2020 |
Rename to Mtf.LanguageService.