如何在 ASP.NET 中提供 resx 文件?
如何向 ASP.NET 中的 http 客户端提供适合区域设置的 .resx
文件?
例如
GET /App_LocalResources/MeshModdler.resx
背景
我有一个客户端二进制文件,需要向网络服务器询问适当的语言资源(即它没有所有可能的翻译;它要求它需要的翻译)。
现在,客户端二进制文件更喜欢提供一个包含所有本地化资源(字符串等)的 xml 文件。该 XML 文件的格式与 Microsoft 的 resx
格式非常相似(人们可能会认为该格式是复制的 - 他们不会错)。
理想情况下,我们可以使用 ASP.NET Web 服务器的功能,根据 http 客户端的 Accept-Language
来定位适当的 resx 文件,例如,
GET /App_LocalResources/MeshModdler.resx
Accept-Language: az-Cyrl-AZ
理想情况下,Web 服务器会尝试按以下顺序返回:首选项:
MeshModdler.az-Cyrl-AZ.resx
MeshModdler.az-AZ.resx
MeshModdler.az.resx
MeshModdler.resx
但服务器返回:
HTTP/1.1 404 Not Found
Bonus Chatter
我知道这是不可能的。因此,除了无法完成
答案之外,我还接受一个只做我想要的答案:
- 利用 ASP.NET Web 服务器的力量来执行资源解析和后备
- 允许新的本地化将
resx
文件拖放到文件夹中并拾取它们 不需要创建一个虚拟页面来构建看起来类似于
resx< /code> 文件,但必须对每个条目进行 thunk 操作:
<前><代码><根>; <数据名称=“TesselateMesh.Caption”> <值><%$ 资源:MeshModdler、TesselateMesh.Caption1 %> ...
以下命令
对每个条目进行 thunk:目前的破解方法是将 resx
文件重命名为 xml
:
MeshModdler.az-Cyrl-AZ.xml
MeshModdler.az-AZ.xml
MeshModdler.az.xml
MeshModdler.xml
并重新发明后备代码:
GET /MeshModdler.az-Cyrl-AZ.xml
404 Not found
GET /MeshModdler.az-AZ.xml
404 Not found
GET /MeshModdler.az.xml
200 Ok
但是最好与 ASP.NET 一起工作,而不是与之对抗。
How can i serve a locale appropriate .resx
file to a http client in ASP.NET?
e.g.
GET /App_LocalResources/MeshModdler.resx
Background
i have a client-side binary that needs to ask a web-server for the appropriate language resources (i.e. it does not have all possible translations; it asks for the one it needs).
Right now the client-side binary prefers to be given an xml file containing all the localized resources (strings, etc). This XML file has a format that looks curiously like Microsoft's resx
format (one might think the format was copied - and they would not be wrong).
Ideally we can use the power of an ASP.NET web-server to locate the appropriate resx file based on the http client's Accept-Language
, e.g.
GET /App_LocalResources/MeshModdler.resx
Accept-Language: az-Cyrl-AZ
Ideally the web-server would 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 Chatter
i know this is not possible. So in addition to a cannot be done
answer, i would also accept an answer that just does what i want:
- harnesses the power of an ASP.NET web-server to perform resource resolution and fallback
- allows new localization
resx
files to be dropped into a folder and have them picked up will not require resorting to creating a dummy page that builds what looks like a
resx
file, but has to thunk every entry with:<root> <data name="TesselateMesh.Caption"> <value><%$ Resources:MeshModdler, TesselateMesh.Caption1 %></value> </data> ... </root>
Additional Chatter
The hack for now will be to rename the resx
files to xml
:
MeshModdler.az-Cyrl-AZ.xml
MeshModdler.az-AZ.xml
MeshModdler.az.xml
MeshModdler.xml
And re-invent the fallback 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, not against it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建一个 ASHX 文件,该文件采用资源名称文件并在服务器上查找正确的
.ResX
文件。 (将当前的后备逻辑移至/GetResource.ashx?Name=MeshModeler
)You can create an ASHX file that takes a resource name file and looks up the correct
.ResX
file on the server. (moving your current fallback logic to/GetResource.ashx?Name=MeshModeler
)