locked
Are "?" in resource keys supported?

    Question

  • I have two keys in my resjson file

    "key" and "key?". When I try to get the value for "key?" WinRT always returns the value for "key". Does it not support "?" in keynames?

    Thursday, April 23, 2015 2:46 PM

Answers

  • Thanks Franklin for confirming this behaviour. I wonder if that is intentional, by design, or just a bug. Maybe someone from the product team can shed some light on that?

    Hi pkursawe,

    This is by design, here are the steps how I locate the key point:

    Go to the Definition of WinJS.Resources.getString -> Go to the Definition of WinJS.Resources._getStringWinRT

    _getStringWinRT: function (resourceId) {
                if (!resourceMap) {
                    var mainResourceMap = Windows.ApplicationModel.Resources.Core.ResourceManager.current.mainResourceMap;
                    try {
                        resourceMap = mainResourceMap.getSubtree('Resources');
                    }
                    catch (e) {
                    }
                    if (!resourceMap) {
                        resourceMap = mainResourceMap;
                    }
                }
    
                var stringValue;
                var langValue;
                var resCandidate;
                try {
                    var resContext = WinJS.Resources._getResourceContext();
                    if (resContext) {
                        resCandidate = resourceMap.getValue(resourceId, resContext);
                    } else {
                        resCandidate = resourceMap.getValue(resourceId);
                    }
    ......

    Modeled on the above method, we can create a Windows Store app using C#:

    var mainResourceMap = Windows.ApplicationModel.Resources.Core.ResourceManager.Current.MainResourceMap;
    mainResourceMap.GetValue("Key?");

    Go to the Definition of Windows.ApplicationModel.Resources.Core.ResourceMap.GetValue, you will see the following information, this will tell us the truth:

    //Parameters:
    //   resource:
    //     A resource specified as a name or reference.The resource identifier is treated
    //     as a Uniform Resource Identifier (URI) fragment, subject to Uniform Resource
    //     Identifier (URI) semantics. For example, getValue(Caption%20) is treated
    //     as getValue(Caption ). Do not use ? or # in resource identifiers, as they
    //     terminate the named resource path. For example, Foo?3 is treated as Foo.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, April 27, 2015 6:20 AM
    Moderator
  • That is not the limitation from Microsoft. Instead, the reason is the questionmark is a key word for URI.

    As Franklin mentioned, the key is part of URI. According to the standards of URI, questionmark is followed by parameters. I will suggest you read the standards of URI schema in this Wiki artical. And we can also find the official definition in RFC 3986

    Feel free to share your concerns.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    Alan Yao
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.



    Tuesday, April 28, 2015 6:16 AM
  • well actually, that does not explain why it is treated as an URI. I assume they do internally something like concatenating the key to the apps schema like this: `ms-appx:///resources/key` ?

    Hi pkursawe,

    We can not provide more internal details about this in public forum, but your direction is right


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by pkursawe Monday, May 4, 2015 6:54 PM
    Monday, May 4, 2015 9:53 AM
    Moderator

All replies

  • Hi pkursawe,

    I think the answer is no.

    Based on my test, the question mark is not supported for the name of a string resource, although I used the HTML Number(&#63;), the result is the same as yours: the question mark would be ignored


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, April 24, 2015 9:23 AM
    Moderator
  • Thanks Franklin for confirming this behaviour. I wonder if that is intentional, by design, or just a bug. Maybe someone from the product team can shed some light on that?
    Friday, April 24, 2015 9:36 AM
  • Thanks Franklin for confirming this behaviour. I wonder if that is intentional, by design, or just a bug. Maybe someone from the product team can shed some light on that?

    Hi pkursawe,

    I will ask our experts through internal way and come back if have any updates.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Sunday, April 26, 2015 6:10 AM
    Moderator
  • Thanks Franklin for confirming this behaviour. I wonder if that is intentional, by design, or just a bug. Maybe someone from the product team can shed some light on that?

    Hi pkursawe,

    This is by design, here are the steps how I locate the key point:

    Go to the Definition of WinJS.Resources.getString -> Go to the Definition of WinJS.Resources._getStringWinRT

    _getStringWinRT: function (resourceId) {
                if (!resourceMap) {
                    var mainResourceMap = Windows.ApplicationModel.Resources.Core.ResourceManager.current.mainResourceMap;
                    try {
                        resourceMap = mainResourceMap.getSubtree('Resources');
                    }
                    catch (e) {
                    }
                    if (!resourceMap) {
                        resourceMap = mainResourceMap;
                    }
                }
    
                var stringValue;
                var langValue;
                var resCandidate;
                try {
                    var resContext = WinJS.Resources._getResourceContext();
                    if (resContext) {
                        resCandidate = resourceMap.getValue(resourceId, resContext);
                    } else {
                        resCandidate = resourceMap.getValue(resourceId);
                    }
    ......

    Modeled on the above method, we can create a Windows Store app using C#:

    var mainResourceMap = Windows.ApplicationModel.Resources.Core.ResourceManager.Current.MainResourceMap;
    mainResourceMap.GetValue("Key?");

    Go to the Definition of Windows.ApplicationModel.Resources.Core.ResourceMap.GetValue, you will see the following information, this will tell us the truth:

    //Parameters:
    //   resource:
    //     A resource specified as a name or reference.The resource identifier is treated
    //     as a Uniform Resource Identifier (URI) fragment, subject to Uniform Resource
    //     Identifier (URI) semantics. For example, getValue(Caption%20) is treated
    //     as getValue(Caption ). Do not use ? or # in resource identifiers, as they
    //     terminate the named resource path. For example, Foo?3 is treated as Foo.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, April 27, 2015 6:20 AM
    Moderator
  • Ok, thanks for digging this up. I still wonder why ? and # are not permitted in keys. Any word about that (imho stupid) limitation from the team?
    Monday, April 27, 2015 3:54 PM
  • That is not the limitation from Microsoft. Instead, the reason is the questionmark is a key word for URI.

    As Franklin mentioned, the key is part of URI. According to the standards of URI, questionmark is followed by parameters. I will suggest you read the standards of URI schema in this Wiki artical. And we can also find the official definition in RFC 3986

    Feel free to share your concerns.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    Alan Yao
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.



    Tuesday, April 28, 2015 6:16 AM
  • well actually, that does not explain why it is treated as an URI. I assume they do internally something like concatenating the key to the apps schema like this: `ms-appx:///resources/key` ?
    Saturday, May 2, 2015 8:10 AM
  • well actually, that does not explain why it is treated as an URI. I assume they do internally something like concatenating the key to the apps schema like this: `ms-appx:///resources/key` ?

    Hi pkursawe,

    We can not provide more internal details about this in public forum, but your direction is right


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by pkursawe Monday, May 4, 2015 6:54 PM
    Monday, May 4, 2015 9:53 AM
    Moderator