Reputation: 1352
I am working on Universal app(with Prism). Here is my scenario.
I have a string resource file in following projects:
1) Windows - Resources.resw - This file has windows specific string resources.
2) WindowsPhone - Resources.resw - This file has phone specific string resources
3) Shared - SharedResources.resw - This file has string resources which are common between windows and phone.
Now, How can I make ResourceLoader to search resources in "SharedResources.resw" and "Resources.resw" both the files?
Any suggestions?
Thanks in advance.
Upvotes: 1
Views: 611
Reputation: 1352
I have extended the ResourceLoader class as following:
public class ResourceLoaderEx : IResourceLoaderEx
{
//This method is used when the PCL contains .resx file instead of .resw.
public string GetString(string resource, string baseName, Assembly assembly) {
ResourceManager resourceManager = new ResourceManager(baseName, assembly);
return resourceManager.GetString(resource);
}
public string GetString(string resource)
{
ResourceLoader resourceLoader;
if (resource.Contains("\\"))
{
resourceLoader = ResourceLoader.GetForCurrentView(resource.Substring(0, resource.LastIndexOf("\\")));
resource = resource.Substring(resource.LastIndexOf("\\") + 1);
}
else
{
resourceLoader = ResourceLoader.GetForCurrentView();
}
return resourceLoader.GetString(resource);
}
}
This class covers following scenarios(below code is under my UILoic class):
var windowsSpecificResource = resourceLoader.GetString(@"windows"); // This will fetch the resource from Resources.resw file
var sharedResource = resourceLoader.GetString(@"SharedResources\testforshared"); // This will fetch the resource from the SharedResources.resw file
var pclResource = resourceLoader.GetString("SaveErrorMessage", "Contoso.UILogic.Strings.Resources", typeof(Strings.Resources).GetTypeInfo().Assembly); // This will fetch the resource from Resources.resx file which is in my UILogic project.
Any comments?
Upvotes: 0