locked
Best practices for building localizable custom controls in xaml RRS feed

  • Question

  • Hello, I created a custom control for xaml that I distribute using a .vsix file. My component includes a .resw file that contains en-us string resources but I want to make sure the component can be localized by the app consuming it. What is the best practice?

    Note: my component loads string resources both via code:

    new ResourceLoader(componentName).GetString("Resources/SomeString");

    and via xaml:

    <TextBlock x:Uid="TextId"/>
    Both techniques above work great for the default en-us resources, but I haven't found a way to allow consumers of the control to ship custom resources for other languages with their app. Any tips here?

    Thanks,

    Tim

    Thursday, September 27, 2012 11:31 PM

Answers

  • Thanks Sara. While this would work for programmatically retrieved strings, I don't think either approach works with x:Uid attributes in my custom control's xaml.

    I don´t believe that exist any way to use x:Uid for that you want. And in my opinion the solution that i say is very simple and good for implement. Because if you do that you can use the same code for other platforms like WP.

    Sara Silva
    My Windows 8 Store Apps Samples
    Follow me in Twitter @saramgsilva

    • Marked as answer by Tim Greenfield Monday, October 22, 2012 12:47 AM
    Saturday, October 20, 2012 8:34 PM

All replies

  • In this sample:

    Application resources and localization sample

    you can see in Scenario6 how you can use resources string from another library. I think you can do this, only need is to add a string property for the path and if is set you use that reference for get resources. But you need to expose all keys they need to translate.

    Another way is:

    In your control add a property like

    IResourceManager ResourceManager {get;set}

    Then you will define the IResourceManager interface and the ResourceManager class.

    • ResourceManager implements the IResourceManager.
    • The IResourceManager has properties that represent all keys/localization strings you need
    • The ResourceManager implements the interface and each property is virtual

    your customer needs:

    • create a class that inherit from ResourceManager and override each property that they needs.
    • Implement a class that implements the interface IResourceManager and set it to the property in control.

    Telerik has something interesting about it. is similar that i say and i like it.

    See this example:

    String Loaders



    Sara Silva

    • Proposed as answer by saramgsilva Wednesday, October 3, 2012 6:09 PM
    • Marked as answer by Min ZhuMember Monday, October 8, 2012 5:29 AM
    • Unmarked as answer by Tim Greenfield Monday, October 8, 2012 2:58 PM
    Wednesday, October 3, 2012 6:00 PM
  • Thanks Sara. While this would work for programmatically retrieved strings, I don't think either approach works with x:Uid attributes in my custom control's xaml.
    Monday, October 8, 2012 2:58 PM
  • you saw the sample? And the ResourceManager class?






    Sara Silva

    Monday, October 8, 2012 3:35 PM
  • Thanks Sara. While this would work for programmatically retrieved strings, I don't think either approach works with x:Uid attributes in my custom control's xaml.

    I don´t believe that exist any way to use x:Uid for that you want. And in my opinion the solution that i say is very simple and good for implement. Because if you do that you can use the same code for other platforms like WP.

    Sara Silva
    My Windows 8 Store Apps Samples
    Follow me in Twitter @saramgsilva

    • Marked as answer by Tim Greenfield Monday, October 22, 2012 12:47 AM
    Saturday, October 20, 2012 8:34 PM
  • This is the conclusion I've reached as well... That x:uid should not be used in a custom control if you want to allow developers to be able to localize it. Oh well.
    Monday, October 22, 2012 12:47 AM