rskibbe.I18n.Winforms
1.0.4
See the version list below for details.
dotnet add package rskibbe.I18n.Winforms --version 1.0.4
NuGet\Install-Package rskibbe.I18n.Winforms -Version 1.0.4
<PackageReference Include="rskibbe.I18n.Winforms" Version="1.0.4" />
paket add rskibbe.I18n.Winforms --version 1.0.4
#r "nuget: rskibbe.I18n.Winforms, 1.0.4"
// Install rskibbe.I18n.Winforms as a Cake Addin #addin nuget:?package=rskibbe.I18n.Winforms&version=1.0.4 // Install rskibbe.I18n.Winforms as a Cake Tool #tool nuget:?package=rskibbe.I18n.Winforms&version=1.0.4
Description
A package with helpers for translating Windows Forms (Winforms) applications - based on rskibbe.I18n.
Getting started
If you followed the steps from the base package, you are ready to provide your custom translations.
A quick translator setup recap
To setup your custom translator just go ahead and use this quick method (if you've installed rskibbe.I18n & like rskibbe.I18n.Json & finally this package rskibbe.I18n.Winforms):
// don't forget the imports
using rskibbe.I18n.Models;
using rskibbe.I18n.Winforms;
// before like the first Form InitializeComponent
Translator.Builder
.WithAutoFormTranslation()
.Build()
.StoreInstance();
This will take the Json (or like Ini if installed instead) package by autodetection and will automatically translate and update corresponding controls like Labels, Buttons and Forms. You don't need to configure much more - isn't this nice 😉.
Remember to do this "bestly" before any UI going on, the Bootstrapping point Program.cs/Program.vb or like the first Form Constructor could be the best place (but make sure it doesn't get called multiple times).
Marking controls as translatable
In the next step you need to tell the translator what controls should actually be translated. This is easily done by just specifying its tag property inside the designer.
Supported Controls
Currently this package supports auto-translation of the following controls:
- Button
- CheckBox
- GroupBox
- Label
- LinkLabel
Full Example
Step 1 - Install packages from NuGet
The base package is always necessary rskibbe.I18n. Depending on the translation style you want to use (InMemory, file-based like Json or Ini, etc.), install the next package like rskibbe.I18n.Json. Now you can install the last helper package for Windows Forms (this one you are in right now..) rskibbe.I18n.Winforms.
Step 2 - Create a "Form"
Go on like your first form - usually Form1 - and put a button on top of it. Name it as you wish but specify the Tag property as i18n:myTranslationKey. The translator will search for the i18n prefix and will know, that it has to tranlate it with the corresponding translation key (the thing after the 😃.
Step 3 - Create the necessary files
Please take a look at the corresponding package like rskibbe.I18n.Json or rskibbe.I18n.Ini for file and content structure. More packages for loading from web APIs and like SQL to come.
public partial class Form1 : Form
{
public Form1()
{
Translator.Builder
.WithAutoFormTranslation()
.Build()
.StoreInstance();
InitializeComponent();
}
private async void Form1_Load(object sender, EventArgs e)
{
await Translator.Instance.LoadLanguagesAsync();
if (Translator.Instance.HasLanguages)
{
var language = Translator.Instance.Languages.SingleOrDefault(x => x.Iso == "en-US");
await Translator.Instance.ChangeLanguageAsync(language);
}
}
private async void btnSetGerman_Click(object sender, EventArgs e)
{
await Translator.Instance.ChangeLanguageAsync("de-DE");
}
private async void btnSetEnglish_Click(object sender, EventArgs e)
{
await Translator.Instance.ChangeLanguageAsync("en-US");
}
}
Take a look at the base package for more information like getting the available languages, changing the language, etc.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0-windows7.0 is compatible. net7.0-windows was computed. net8.0-windows was computed. |
-
net6.0-windows7.0
- rskibbe.I18n (>= 1.0.8)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.