How to localize App_GlobalResources in ASP.NET?

I have an ASP.NET site with some "global" resources:

\App_GlobalResources ContosoFrobberResource.resx 

This is a complement to the local resources associated with each aspx file:

 \App_LocalResources Materials.aspx.resx Notes.aspx.resx OrderHistory.aspx.resx 

Now I want to localize the site in another language standard (for example, en ). I create a resx file for each "local" resource:

 \App_LocalResources Materials.aspx.en.resx Materials.aspx.en-us.resx Materials.aspx.en-uk.resx Materials.aspx.en-sg.resx Notes.aspx.en.resx Notes.aspx.en-us.resx Notes.aspx.en-uk.resx Notes.aspx.en-sg.resx OrderHistory.aspx.en.resx OrderHistory.aspx.en-us.resx OrderHistory.aspx.en-uk.resx OrderHistory.aspx.en-sg.resx 

And all this works great; The site displays customized English versions for

  • USA (en-US)
  • United Kingdom (en-UK)
  • Singapore (en-SG)

as well as reserve for general

  • Russian (ru)

The problem occurs when I try to localize resources in App_GlobalResources :

 \App_GlobalResources ContosoFrobberResource.resx ContosoFrobberResource.en-us.resx 

Error page failed:

CS0101: The Resource namespace already contains a definition for ContosoFrobberResource

How to localize App_GlobalResources on an ASP.NET website?

Bonus Chat

ContosoFrobberResource.resx

  <?xml version="1.0" encoding="utf-8"?> <root> <data name="ProjectDueDate" xml:space="preserve"> <value>Proposal Due Date</value> </data> </root> 

ContosoFrobberResource.qps.resx

  <?xml version="1.0" encoding="utf-8"?> <root> <data name="ProjectDueDate" xml:space="preserve"> <value>Prȍposẳl Duɇ Dãtē</value> </data> </root> 
+4
source share
1 answer

Found the answer.

ASP.NET does not properly indent the parent language. If he cannot recognize the file as a “backup” locale, then he cannot analyze it and shows an error that is misleading.

eg.

 ContosoGrobber.resx ContosoGrobber.en-us.resx 

works great. But:

 ContosoGrobber.resx ContosoGrobber.en.resx 

fails when the " en " part of the locale string is not recognized. Change it to use the fully qualified locale name and avoid erroneous backup code - this is a fix. eg:.

 ContosoGrobber.qps.resx 

should become:

 ContosoGrobber.qps-ploc.resx 

In other words: if the browser requests the qps-ploc , ideally you can use

 ContosoGrobber.qps.resx 

and local qps-ploc will return to qps . But due to an error in ASP.NET, it is not backing down properly. This means that you cannot allow him to return; you must handle all possible locales:

 ContosoGrobber.qps-ploc.resx ContosoGrobber.qps-plocm.resx ContosoGrobber.qps-ploca.resx 
+4
source

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


All Articles