Supporting multiple languages in a Winforms application
I know this question have been ask a long time ago but since there was no answer here's what I suggest:
To access a resource file in C# you can use a ResourceManager. First create your resource manager depending on the curent language. You have two options for this. You can use a switch or if statement (if the language is determined by a menu) or use localization to use the current culture of the computer. Finally, with both ways you can then call the GetString() method providing the key which I believe in your case is lblName.
N.B: In the example bellow I use the first method which is retrieving the language from a menu.
string selectedLanguage = comboBoxLang.Text; // Comes from a menu option
string resourceFile = string.Empty;
/***/
Logic to retrieve the proper resourceFile depending on the selectedLanguage.
/***/
ResourceManager rm = new ResourceManager(resourceFile, Assembly.GetExecutingAssembly());
// Set your label text.
lblName.Text = rm.GetString("lblName");
Max
Updated on June 04, 2022Comments
-
Max almost 2 years
I've almost finished my C# application; the only thing left to do is to implement multiple language support.
I've already created resource files which hold strings for a few languages for all the text displayed on screen.
Example of my English Resource file:
Name | Value | Comment ------------------------------------------------------------------------------ lblName | Name: | Name EN
Example of my Dutch Resource file:
Name | Value | Comment ------------------------------------------------------------------------------ lblName | Naam: | Name NL
How can I bind the field
Value
to theText
property of myLabel
(lblName
)?I'm using .NET Framework 3.5.