Split a large resource file into multiple files physically, while the compiler treats it as one

Is it possible to split one large resource file (.resx) into several files physically and still use the same syntex to get the data.

i.e.

GlobalResource.resx

in

GlobalResource1.resx, GlobalResource2.resx, GlobalResource3.resx, ...

and the whole file will be compensated in one and use as

Resources.GlobalResource.errParamNameReq 

using it in Asp.net 3.5. having a problem while working on svn, every time it encounters a conflict during validation, so I decided to split it into many files, while the compiler treats it as one.

+6
source share
4 answers

Each resource file has a code file that is used to declare resource elements as static properties. Also, many automated code generation are used by Visual Studio tools to synchronize between the xml / resource editor data and the code behind the file. It may be possible to split the resource into several files, but the consequences of automatic code generation can cause even more problems than just merging your changes. A possible solution is to create different resource files. Then you have a class that stores a collection of the ResourceManager instance for each resource manager. Something like that:

  public class ResourceWrapper { private ICollection<ResourceManager> resourceManagers; public ResourceWrapper(IEnumerable<ResourceManager> managers) { resourceManagers = new List<ResourceManager>(managers); } public string GetString(string key) { foreach (var resourceManager in resourceManagers) { string res = resourceManager.GetString(key); if (res != null) { return res; } } return null; } public string GetString(string key, CultureInfo culture) { foreach (var resourceManager in resourceManagers) { string res = resourceManager.GetString(key, culture); if (res != null) { return res; } } return null; } } 

You only need to get all the resources and pass them to the constructor. You might want to save a shell instance after creating it to avoid creating a resource manager for each resource file โ€” a static feed will be executed. The only problem with the code above is that there is no guarantee that two or more resource files define the same key. If this happens, the code will return only the first match.

+2
source

So, are you trying to break it in order to avoid conflicts during verification in svn? If so, then you do not decide the root cause, but its consequences.

If it is so large that every time you register, you are likely to run into conflicts, try reorganizing them into smaller files with meaningful names. And then use the @Ivaylo solution. Each resource corresponds to a class, the ASP.Net website model simply hides it from you.

If you create the Resource1.resx file in App_GlobalResources, you get Resource.Resource1 as a class in your code.

0
source

As far as I know, there is no way for a resource file to be split into several files so that you can access records from several resx files through one common accessor, for example Resources.MyAggregatedResources.Resource1 . You probably know that you can put as many resource files in your App_GlobalResources folder as you wish and access them as Resources.ResourceFile1.Resource1 , Resources.ResourceFile2.Resource1 .

All resources added to resx files are automatically mapped to strongly typed properties in files with code named resource.Designer.cs (If you do not see this file, switch the "Show all files" option to Solution Explorer (second button)). "Display" is implemented as code generation in Visual Studio and therefore cannot be changed from your project. You need to implement your own level of abstraction over resources in order to return values โ€‹โ€‹from several resource files and pass the resource name as a string => there is no way to check for spelling errors or missing resources during development and the absence of IntelliSense.

One way to implement the functionality you want is to upgrade your solution to .Net 4.0 and use the dynamic properties that are allowed at runtime. However, you will not get IntelliSense support for the names of your resources, as in the case of static resources ...

0
source

It was found that this thread will look for a way to share large text resources (xml image files), but it did not help me and did not use other search terms such as "split resx multiple filex"

During a further search, I found http://forums.asp.net/t/937583.aspx?Maximum+string+length+in+resx+file for several weeks, because it seems that I could not save my xml files at all resource editor.

The solution was to use the "Add Resource โ†’ Add New Text File" function in the resource editor and name the resource exactly as I would name it in the "name" colum in the resource editor. Then I managed to insert everything into a new text file, which I would usually fill in the column "value".

Now I have one text file for each of these resources, convenient diff, etc. Iโ€™m not sure that it refers to this particular stream, but I still wanted to share it.

0
source

Source: https://habr.com/ru/post/890129/


All Articles