Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the Localizable property and support in my own design tool?

Overview

In another question, I asked about deploying localizations for some runtime compiled UserControl's. However, before I can get to deploying the localizations, I need a way of localizing the controls.

Background

The controls are created by our own WinForms-style designer (using .NET's support for design surfaces, etc.) and saved as a binary format that combines the CodeCompileUnit, resource resx, and user source into one file. These files are then compiled into an assembly as appropriate at runtime by another tool.

In order to localize these, we need to tell the designer and serialization that localizable property values are to be stored in the resources. The VisualStudio WinForms designer does this using an extension property called Localizable and an associated property for specifying the default culture. We need this property in our custom designer, if possible.

Constraints

We need our standalone designer tool that is easy to use for non-developer types as well as restricting certain actions so using a free edition of Visual Studio (i.e. C# Express) is not going to work (I've already pitched it and failed); therefore, any solution to how we localize these UserControl's needs to compensate for this.

Question

Can we get the Localizable support into our custom WinForms designer?

  • If yes, how?
  • If no, what alternatives are there to localizing our UserControl's? e.g. post-processing somehow, different file format, etc.
like image 829
Jeff Yates Avatar asked Feb 03 '09 15:02

Jeff Yates


2 Answers

I'm not sure if I understood your question correctly.

Just check for the System.ComponentModel.LocalizableAttribute on all properties to (de-)serialize if your control is Localizable.

// Gets the attributes for the property.
AttributeCollection attributes = 
TypeDescriptor.GetProperties(this)["MyProperty"].Attributes;

// Checks to see if the property needs to be localized.
LocalizableAttribute myAttribute = 
(LocalizableAttribute)attributes[typeof(LocalizableAttribute)];
if(myAttribute.IsLocalizable) {
// Insert code for handling resource files here.
}

Since you decided to write your own designer you have to do this yourself.

like image 108
Stefan Haubold Avatar answered Nov 17 '22 11:11

Stefan Haubold


You need to add a System.ComponentModel.Design.LocalizationExtenderProvider to your design surface.

like image 40
Alex Lyman Avatar answered Nov 17 '22 11:11

Alex Lyman