C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,059 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I created a user control with a description attribute for these properties.
When I test the user control, these descriptions appear correctly in the property grid.
The description attribute is in French.
I would like to be able to change it dynamically depending on a language choice, for example in English.
How can we change this?
The string to be displayed are changed by referring to CultureInfo.CurrentUICulture.Name.
using System.ComponentModel;
using System.Globalization;
class SRDescriptionAttribute : DescriptionAttribute
{
public string EnString { get; }
public string JpString { get; }
public SRDescriptionAttribute(string enString, string jpString) {
EnString = enString;
JpString = jpString;
}
public override string Description {
get {
switch (CultureInfo.CurrentUICulture.Name) {
case "en-US":
return EnString;
case "ja-JP":
return JpString;
}
return EnString;
}
}
}
It is used like this.
class TestUserControl : UserControl
{
[SRDescription("English", "日本語")]
public int Prop1 { get; set; }
}
Many thanks to KOZ6.0 for his answer.
This solved my problem.