.NET ResourceManager.GetResourceSet: "en-GB" does not work on English resource

Is there a way in .NET to make the following calls:

ResourceManager.GetResourceSet(new CultureInfo("en-GB"), true, false)
 ResourceManager.GetResourceSet(new CultureInfo("en-US"), true, false)

      

works also for unshaven ("en" only) resources like:

Resources.en.resx

      

Without the file "en-GB.resx / en-US.resx" above, it will always return null. I would like them to revert to the default en.resx if no more specific file is found (like en-GB.resx or en-US.resx).

NOTE. Setting the third parameter GetResourceSet (tryParaments) to true will return a file with the Resources.resx tag that is not flagged by default, even though en is set in the parent CultureInfos property.

+3


source to share


1 answer


You have to get all the keys to the invariant culture and then you can find the whole translation. Thus, the reserve is working.



var keys = Resources.ResourceManager
    .GetResourceSet(CultureInfo.InvariantCulture, true, true)
    .Cast<DictionaryEntry>()
    .Select(entry => entry.Key)
    .Cast<string>();

var enUsResources = keys.ToDictionary(
    key => key, 
    key => Resources.ResourceManager.GetString(key, CultureInfo.GetCultureInfo("en-US")));

      

0


source







All Articles