locked
how to add string resources in data-win-options ?

    Question

  • Hi,

    I see that it is possible to add string resources in a DOM element like :

    <span class="win-type-x-large pagesubtitle" data-win-res="{textContent: 'subTitleCollection'}"></span>

    But I don't know how I can add a string resources in a WinJs control :

    <div id="headerFlyout" data-win-control="WinJS.UI.Menu">
                <button data-win-control="WinJS.UI.MenuCommand" data-win-options="{id:'subTitleCollection', label: 'a_string_resource'}"></button>
                <button data-win-control="WinJS.UI.MenuCommand" data-win-options="{id:'subTitleDisk', label: 'a_string_resource'}"></button>
            </div>

     

    I want that label in data-win-options use internationalization.

    Is it possible or I have to set the label programmaticaly with :

    WinJS.Resources.getString('my_resources_key') ?

    Thanks

    Tuesday, April 10, 2012 3:52 PM

Answers

  • You want to use the data-win-res attribute. See this documentation:

    http://msdn.microsoft.com/en-us/library/windows/apps/br211864.aspx

    See this sample for a full example:

    Application resources and localization sample

    Update: I talked with someone further about this.  Label is a special case:

    Data-win-res works on standard elements like <button> <p> <div>, but this question is about how to localize a WinJS control, which defines the labels inside a data-win-options attribute that has more than just the label. The data-win-options is a structured object.

    Here is how you can handle this:

             <div id="headerFlyout" data-win-control="WinJS.UI.Menu">

                         <button data-win-control="WinJS.UI.MenuCommand" data-win-res=”{winControl: {label: ‘a_string_resource’}}” data-win-options="{id:'subTitleCollection' }"></button>

                         <button data-win-control="WinJS.UI.MenuCommand" data-win-res=”{winControl: {label: ‘a_string_resource’}}” data-win-options="{id:'subTitleDisk' }"></button>

            </div>

    The only problem is that the you have to ensure you call WinJS.UI.processAll() and then call WinJS.Resources.processAll().

    -Jeff


    Jeff Sanders (MSFT)


    Wednesday, April 11, 2012 1:54 PM
    Moderator

All replies

  • You want to use the data-win-res attribute. See this documentation:

    http://msdn.microsoft.com/en-us/library/windows/apps/br211864.aspx

    See this sample for a full example:

    Application resources and localization sample

    Update: I talked with someone further about this.  Label is a special case:

    Data-win-res works on standard elements like <button> <p> <div>, but this question is about how to localize a WinJS control, which defines the labels inside a data-win-options attribute that has more than just the label. The data-win-options is a structured object.

    Here is how you can handle this:

             <div id="headerFlyout" data-win-control="WinJS.UI.Menu">

                         <button data-win-control="WinJS.UI.MenuCommand" data-win-res=”{winControl: {label: ‘a_string_resource’}}” data-win-options="{id:'subTitleCollection' }"></button>

                         <button data-win-control="WinJS.UI.MenuCommand" data-win-res=”{winControl: {label: ‘a_string_resource’}}” data-win-options="{id:'subTitleDisk' }"></button>

            </div>

    The only problem is that the you have to ensure you call WinJS.UI.processAll() and then call WinJS.Resources.processAll().

    -Jeff


    Jeff Sanders (MSFT)


    Wednesday, April 11, 2012 1:54 PM
    Moderator
  • That worked, thanks.  

    It's definitely the right answer, so 'emorvil' how about you mark is as the answer and give jpsanders some credit?

    Saturday, April 21, 2012 12:18 AM