locked
Issue with WinJS.Resources.getString and resources beginning with "_"

    Question

  • Hello,

    I've noticed that when using WinJS.Resources.getString you can not retrieve resource keys that begin with an underscore. ie WinJS.Resources.getString("_stringMessage").  I receive an error "JavaScript runtime error: NamedResource Not Found" even though the resource is present in the resources.resjson file.   This seems to be intentional since the localization sample uses the underscores to indicate comments and those should not be accessable.

    My issue is that I have data that unfortunately starts with underscores that I use as keys for localization.  Being unable to modify the data, what should I do code-wise to get around this?  Maybe there is a configuration of some kind allows underscores?

    I'm thinking that I could overwrite the function to perform a string replacement of the underscore or prepend something but that doesn't feel like the cleanest solution.

    Thanks


    -Jeff

    Monday, April 9, 2012 8:36 PM

Answers

  • Hi Jeff,

    More detailed information for you:

    .resjson files don’t support underscores as resource identifiers, but they are treated as metadata. This is simply a construct of the .resjson indexer and how it interprets JSON objects. One option would be to use .resw files instead (typically used in C# projects) and make sure the BuildAction is set to Resource.

    -Jeff


    Jeff Sanders (MSFT)


    Wednesday, April 11, 2012 2:07 PM
    Moderator