我有一个上下文菜单应用程序,我有一个基础项目SampleContextMenu.Base和一个子项目SampleContextMenu.Menu。
在SampleContextMenu.Menu中,我创建了一个上下文菜单,我为此设置了这样的文本。
sampleItem.Text = "Open In";
现在我想全局化这个字符串。所以我创建了3个名为UiStrings.resx,UiStrings.de-DE.resx和UiStrings.fr-FR.resx的资源文件。
在SampleContextMenu.cs类中,我现在有以下代码,
// Resource path
private string strResourcesPath = Application.StartupPath + "/Resources";
// string to store current culture which is comon in all the forms
private string strCulture = "en-US";
//resourcemanager which retrivesthe strings
//from the resource files
private static ResourceManager rm;
private void GlobalizeApp()
{
SetCulture();
SetResource();
}
private void SetCulture()
{
CultureInfo objCI = new CultureInfo(strCulture);
Thread.CurrentThread.CurrentCulture = objCI;
}
private void SetResource()
{
rm = new ResourceManager("SampleContextMenu.Menu.UiStrings", typeof(SampleContextMenu).Assembly);
}
protected override ContextMenuStrip CreateMenu()
{
// some code to create menu
strCulture = Read("language");
GlobalizeApp();
sampleItem.Text = rm.getString("0000");
}
修改 对我来说,即使语言是de或fr,它仍然显示默认值(即En)