How to maintain a resx file in ASP.NET?

How can I serve the corresponding .resx file for the http client locale in ASP.NET?

eg.

 GET /App_LocalResources/MeshModdler.resx 

Background

I have a client-side binary that the web server should ask for the corresponding language resources (i.e. it does not have all the possible translations, it requests the one that it needs).

Currently, the client-side binary prefers to receive an xml file containing all localized resources (strings, etc.). This XML file has a format that looks curious, like the Microsoft resx format (you might think that the format was copied - and they are not mistaken).

Ideally, we can use the capabilities of the ASP.NET web server to search for the corresponding resx file based on the Accept-Language http client, for example.

 GET /App_LocalResources/MeshModdler.resx Accept-Language: az-Cyrl-AZ 

Ideally, the web server will try to return in order of preference:

  • MeshModdler.az-Cyrl-AZ.resx
  • MeshModdler.az-AZ.resx
  • MeshModdler.az.resx
  • MeshModdler.resx

But instead, the server returns:

 HTTP/1.1 404 Not Found 

Bonus Chat

I know this is not possible. So in addition to the answer cannot be done I also agree with the answer, which just does what I want:

  • leverages the power of the ASP.NET web server to perform resource resolution and backup.
  • allows you to delete new resx localization resx in a folder and receive them
  • you don’t need to resort to creating a dummy page that builds what looks like a resx file, but must process each entry with:

     <root> <data name="TesselateMesh.Caption"> <value><%$ Resources:MeshModdler, TesselateMesh.Caption1 %></value> </data> ... </root> 

Additional chatter

Now hacking will rename resx files to xml :

  • MeshModdler.az-Cyrl-AZ.xml
  • MeshModdler.az-AZ.xml
  • MeshModdler.az.xml
  • MeshModdler.xml

And recreate the backup code:

 GET /MeshModdler.az-Cyrl-AZ.xml 404 Not found GET /MeshModdler.az-AZ.xml 404 Not found GET /MeshModdler.az.xml 200 Ok 

But it would be nice to work with ASP.NET, and not against it.

+4
source share
1 answer

You can create an ASHX file that takes the resource name file and looks at the correct .ResX file on the server. (moving the current fallback logic to /GetResource.ashx?Name=MeshModeler )

+5
source

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


All Articles