我有一个包含我们网站控件的组件项目 - 现在必须可以本地化。为站点的其余部分设置本地化不是问题(我们将.resx
文件放入App_GlobalResources
目录中;一切都是笨拙的),但我很难找到有关如何在组件项目中本地访问资源的信息。
App_Local[/Global]Resources
文件夹不想工作 - 我不能像从主项目中那样“添加 ASP.NET 文件夹” 。- 当我自己生成它并将 .resx 文件放入其中时,我不知道如何像在站点中那样访问它们。
一些缩写的控制代码,完全包含ThisWidget.cs
在组件项目中:
namespace site.shop {
[ToolboxData("<{0}:ThisWidget runat=server></{0}:ThisWidget>")]
public class ThisWidget : WebControl {
protected override void CreateChildControls() {
if (ChildControlsCreated) { return; }
this.Controls.Clear();
Label head = new Label();
head.CssClass = "header";
// fails: ThisWidget does not exist in namespace
head.Text = System.Resources.ThisWidget.Label_head;
// fails: can't find GetLocalResourceObject
head.Text = new System.Web.UI.TemplateControl.GetLocalResourceObject("Label_head");
// fails: can't find linked or embedded resources
System.Resources.ResourceManager rm = new ResourceManager();
head.Text = Convert.ToString(rm.GetObject("Label_head"));
this.Controls.Add(head);
}
}
}
new
以及带有/out ,等的几种变体System.Web.UI.TemplateControl
...
我宁愿不必将其编译为附属程序集,然后将其拉回(这似乎是另一种选择),因为组件项目 (a) 具有许多相关控件,并且 (b)是排序的已经依赖卫星了,对吧?我希望我可以将.resx
文件放入,编译.DLL
,然后项目的其余部分可以工作。
[编辑] 我觉得我越来越接近答案了,但我还没有完全到那里......
有任何想法吗?我错过了什么?
谢谢!