| sly 的个人资料Silverlight and Internat...照片日志列表 | 帮助 |
|
2008/9/7 Silverlight Localization Methods: User Controls Vs. ApplicationIn this article I'm going to review usercontrol and two types of localization methods around them
1. User Control Overview "UserControls are the basic unit of reusable Xaml and the code that goes with it." User Controls are sometimes called custom controls. Most Silverlight applications will use and create many usercontrols in an application to simplify the application design in a more object orientated structure. A usercontrol can be used for UI elements (eg: dropdownlist, styled buttons, image viewer etc..) or computational (eg: prime number control etc...) or data retrieval (eg: load xml etc...). Once you have created something worth re-using, you can instantiated directly in XAML as a custom type user control. eg: <CoolButtonUCNamespace:coolButton x:Name="button1" ButtonText="Click Here" />. Some samples of user controls but note most controls wont have many UI strings to localize eg:
2. Localization per custom controls On the Silverlight forums people occasionally ask how to do localization on a per control basis? eg: coolButton.xaml with coolButtonResource.de.resx where each control has its own set of resource files. This will mean you need to manage, localize & build many seperate files. To me this method gives some advantages and disadvantages Advantages:
Disadvantages:
Unless your a usercontrol vendor, this method would not be my first choice. 3. Localization on application only The excellent Jordan Hammond created a novel way and wrote sample application by registering custom dependency properties and having all controls in generic.xaml. But if you to have seperate controls, downloadable on demand, but I'll try to explain the logic and basics. First review the good example of creating a reusable user control http://community.devexpress.com/blogs/theonewith/archive/2008/08/06/custom-silverlight-controls-creating-a-reusable-messagebox-dialog-part-i.aspx Note a custom type user control can register custom dependency properties where you can set all localisable resources in its declaration and bind xaml at runtime eg: <CoolButtonUCNamespace:coolButton x:Name="button1" ButtonText="Click Here" /> as <CoolButtonUCNamespace:coolButton x:Name="button1" ButtonText="{Binding LocButtonText, Source={StaticResource LocStrings}}" /> using the resx xaml binding as shown in the previous article. Using this method you can expose all UI string properties in each of your user controls. This allows you to override the default strings and use a single application resx file per application rather than a rex per control. Advantages:
Disadvantages:
4. Conclusion Thanks Jordan to pointing me to this method. I believe the localization per application is better due to the cleaner content and code separation which makes life far easier for the translator. Please share your thoughts below. Updated: See bluetext control on http://wpf-e.spaces.live.com/blog/cns!2B248D261D0E0035!407.entry for code sample
|
|
|