問題描述
我有很多本地資源文件
- /Controls/App_LocalResources/SomeControl.ascx.resx,
- /Pages/App_LocalResources/SomePage.aspx.resx等
我想添加另一種語言,但我不想瀏覽所有文件夾并添加 SomeControl.ascx.de.resx 文件,例如,然后必須重新編譯整個想法.
I want to add another language and I do not want to go through all folders and add SomeControl.ascx.de.resx files for example and then have to recompile the whole think.
我想使用附屬程序集并將所有文件嵌入到 MyWebPage.de.dll 之類的文件中
I would like to use satellite assemblies and embed all the files into something like MyWebPage.de.dll
這在VS2003版本的全局資源中是可以的,但是我不確定在VS2008版本的本地資源中是否可以這樣做?
This was possible in VS2003 version for global resources, but I'm not sure can I do it in VS2008 version for local resources?
我正在使用以下語法訪問資源:
I am accessing the resource with the syntax:
<asp:label id="lblSomething" runat="server" meta:resourcekey="labelFirstName"/>
推薦答案
您的問題不是很清楚,您是在尋找 VS2008 的功能還是 ASP.NET 框架的功能.所以我會用代碼解決方案.
Your question isn't really too clear on whether you are looking for a feature of VS2008 or a feature of the ASP.NET framework. So I'll go with the code solution.
您使用的隱式綁定語法使用 ASP.NET 的默認(rèn) LocalResourceProvider,它采用資源所在的頁面路徑來計算要加載的資源.如果您的資源存儲在其他地方,并且您仍想在前面的代碼中使用隱式綁定系統(tǒng)稅,您將需要使用您自己的 Provider.聽起來很復(fù)雜,但其實很簡單.
The implicit binding syntax you're using uses ASP.NET's default LocalResourceProvider which takes in the path of page under which the resources live to work out which resources to load. If your resources are stored elsewhere and you still want to use the implicit binding systax in your code in front you'll need to use your own Provider. Sounds complicated but it's fairly straightforward.
要做到這一點(diǎn),您需要首先將 ResourceProviderFactory 子類化
To do this you'll need to first subclass ResourceProviderFactory
并覆蓋兩者
IResourceProvider CreateGlobalResourceProvider(string classKey)
IResourceProvider CreateLocalResourceProvider(string virtualPath)
...然后實現(xiàn)您自己的 IResourceProvider,使用 ResourceManager 從附屬程序集中獲取資源
...then implement your own IResourceProvider that gets your resources from your satellite assemblies using a ResourceManager
public interface IResourceProvider
{
object GetObject(string resourceKey, CultureInfo culture);
IResourceReader ResourceReader { get; }
}
然后您需要將配置添加到您的 web.config 文件,讓 ASP.NET 知道使用您的 SatelliteResourceProviderFactory 并將您的資源移動到您的外部程序集,但這應(yīng)該是您的好去處.
You then need to add configuration to your web.config file to let ASP.NET know to use your SatelliteResourceProviderFactory and move your resources in to your external assemby, but that should be you good to go.
可以在此處找到大量文檔...在構(gòu)建數(shù)據(jù)庫資源提供程序"部分下...
Plenty of documentation can be found here...under the "Building a Database Resource Provider" section...
http://msdn.microsoft.com/en-us/庫/aa905797.aspx#exaspnet20rpm_topic4
這篇關(guān)于我可以在附屬程序集中合并本地資源嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!