8
votes

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.
2

2 Answers

3
votes

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.