如何为RESX文件中的ASP.NET? [英] How to serve resx file in ASP.NET?

查看:241
本文介绍了如何为RESX文件中的ASP.NET?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能起到相应的语言环境的.resx 文件在ASP.NET一个HTTP客户端?

How can i serve a locale appropriate .resx file to a http client in ASP.NET?

例如。

GET /App_LocalResources/MeshModdler.resx

背景

我有一个客户端的二进制文件需要问一个Web服务器的相应语言资源(即它不具有的所有可能的翻译;它要求它需要一个)

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).

现在客户端的二进制prefers一个 XML 包含文件中的所有本地化资源(字符串等)。这个XML文件有一个看起来像好奇微软的 RESX 格式的格式(人们可能认为的格式被复制 - 他们不会是错误的)。

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).

在理想情况下,我们可以使用ASP.NET Web服务器的能力来定位基于HTTP客户端的接受语言,例如适当的RESX文件

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

理想情况下,Web服务器将尝试返回,在preference的顺序为:

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

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

但不是服务器返回:

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:


  • 驾的ASP.NET Web服务器的能力来执行资源的分辨率和后备

  • 允许新的定位 RESX 文件被丢弃到一个文件夹,并让他们拿起

  • 不需要诉诸创建构建一个虚拟页面什么的看起来的像 RESX 文件,但有咚每个条目搭配:

  • 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>


对于现在的黑客会在 RESX 文件重命名为 XML

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

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

和重新发明后备code:

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

不过,这将是很好的工作的的ASP.NET,而不是反对它。

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

推荐答案

您可以创建一个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)

这篇关于如何为RESX文件中的ASP.NET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆