I have a problem of understanding with localization, hope you can help.
I create a winform app:
add a button
set the form Localizable property to True
set the form Language to Spanish
change the button's Text to "Vamos" and BackColor to "Green".
set the form Language to English
change the button's Text to "Go" and BackColor to "Yellow".
When I swap between Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("es"); and Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en"); the button Text DOES change from "Vamos" to “Go” but the BackColor is always set to “Yellow”.
My deduction is that Localizable = True tracks [control].Text property changes, and other changes such as [control].Location and [control].Size, but it does NOT track [control].BackColor or many other control property changes in the respective resx files.
Is this a bug? Is there a reference document to understand what IS and ISN'T being tracked? I can understand that BackColor is not something that is typically related to a language change but on that basis, size and location shouldn’t be either...so I am not clear on the rationale applied here...
Because of this limitation I am having to make certain localization changes via resx files and others manually via my on logic, feels a bit messy.
Thanks for your help.
[tested in VS 2012 and 2017 with equal behaviour]
A property is considered as localizable if it's decorated with Localizable(true) attribute. For example BackColor property is not localizable, but Text property is localizable.
When the designer generates code for your form, when you have enabled localization for the form, properties which are decorated with the Localizable(true) will be serialized to the resource file of the form. For the rest of the properties, their values will be serialized in code.
For more information and links to how to create multi-language windows forma application, take a look at:
How to make multi language app in winforms
Related
I'm getting into globalization and localization. I'm aware that I can set the localizable property of my form to true and that I'm able to edit the form for that specific culture. That's great. My question is am I able to, at the designer, load my resx values into their assigned winforms? My goal is to edit the size of my winform assets around the translated languages. This is, obviously, easier if I can see the translations in the designer. Attached is the code that change the text of my buttons at runtime, but my goal is have this take place during the design phase.
buttonTelescopeUp.Text = Resource.TeleUp;
buttonTelescopeDown.Text = Resource.TeleDown;
buttonTelescopeLeft.Text = Resource.TeleLeft;
buttonTelescopeRight.Text = Resource.TeleRight;
Form at runtime
Formin design
As you know LinkLabel control in WinForms supports selection of an area of text (stored in .resx) that will act as link by specifying start and position and length in LinkArea property. But localized text can and will change this exact values as in example below:
"Visit our page now!" [6, 7]
"Посетите нашу страничку сегодня!" [9, 13]
Is there a way to overcome this issue without using special characters and other messy workarounds?
LinkArea property is decorated with Localizable attribute and therefore it's localizable.
So if you set Localizable property of the Form to true, then you can set different value for localizable properties of controls for different languages. This way, property values will store in separate resource files for different cultures.
For more information and links to how to create multi-language windows forma application, take a look at:
How to make multi language app in winforms
I've creted a simple winforms application with only one label. On the default localization language it was set like this
label1.Visible = False
I've changed the language to German (or any other language for that matter) and set label1.Visible = True
After saving and compiling, the label's visibility changed back to False (On the properties form) and I've seen that the German resx file doesn't save the label1.Visible property
I guess that it wasn't saved in the resx file because 'Visible=True' is the default value for labels, but when I run the application on German localization it takes the value 'Visible=False' from the default localization.
It there a way to do this? because it seems like a bug and i can't find a way to overcome it.
I've tried saving this property in the German resx manually but it gets overriden whenever i compile.
A workaround is to hide the label in the default localization by setting AutoSize = False and Size = (0, 0)
I've recently been tasked with localizing a small piece of software that my company created. I've been able to create the resx file for the particular culture, and things are well and good. Thing is, that there are roughly 50 or so labels/buttons/etc, that need to be changed. My question is, do I need to write in the code to set the text, or is there an easier way? For instance,
lblText.text = Resources.labelText
for every single button/label. Or is there a property in the button/label that I'm missing that would set it. Thanks.
You can change the text directly with the form designer of visual studio. Just set the form's property Localizable to true and change the Language property to the one you want to translate. Then, every change you make will only be reflected in the language you selected
If you want more help, you can take a look at this walkthrough
In the Visual Studio Designer, I can change, say, the background of a textbox to blue.
To change it back to its 'default' value, I can right click on that property and click "Default Value".
My question: How do I do that programmatically? I'd like the opportunity to set my controls to and from a custom color back to their windows default (without specifically knowing what they are).
Thanks!
Marc Gravell's answer seems to do what you are looking for:
PropertyDescriptor prop = TypeDescriptor.GetProperties(textBox1)["BackColor"];
if (prop.CanResetValue(textBox1)) {
prop.ResetValue(textBox1);
}
yes you can change any control's property
or also you can see how it build your form via your designer class
check your form1.designer.cs
and read it you can find every control's initialization there.
and if you want to change ur textbox back color here is a code
textBox1.BackColor = System.Drawing.SystemColors.HotTrack;