开发者

Cannot localize (translate) a custom control in .NETCF 2.0

I am translating a compact framework 2.0 windows form in Visual Studio 2005. To do that, I change the language of the form to German (the target language) and edit/resize the controls on the form. This creates a resources.de.resx file containing the translated strings as expected.

However, there is a custom control on the form, which has a property called GroupText, which must also be translated. However, the Form Designer refuses to use the resource files for this property. Whenever I change the property in the property editor, it gets changed for all languages. I checked the resx files - they do not contain the GroupText property, and the Designer generated code also does not use the resx file for this property.

Is there a way to enable resx-based, Visual Studio supported localization for custom controls as well?

Edit:

As an addition to the accepted ans开发者_StackOverflow中文版wer, here's what you have to do to get resx files for custom controls to work.

Each property that should go into a resx file must have the Localizable attribute set to true. Now, the CF does not support this attribute via the usual bracket syntax. You cannot just write [Localizable=true] in the cs source file. You have to create a separate file called DesignTimeAttributes.xmta in the project and add the following:

<?xml version="1.0" encoding="utf-16"?>
<Classes xmlns="http://schemas.microsoft.com/VisualStudio/2004/03/SmartDevices/XMTA.xsd">
<Class Name="MyControl">
  <Property Name="MyProperty">
    <Localizable>true</Localizable>
  </Property>
</Class>

Once you rebuild the assembly containing the control, Visual Studio will put the property values into resx files.


Custom controls for I think quite obvious reasons are not localizable by default, the author of such control has to take care of that. Some custom controls have boolean Localizable property, which controls whether the control writes its messages to resource file but I assume this is not the case here.

If the text you want to translate is accessible via property or constructor, you can create your own *.resx file and assign this text during creation. If it is not, I am afraid you're out of luck.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜