我知道這裏有很多類似的問題,但我的問題並不完全相同,建議的解決方案不適用於我。因此,我創建了名爲「MyApp 1.0」的C#.NET桌面應用程序,但後來將默認命名空間更改爲MyApp
。現在,我希望我的應用能夠以各種語言本地化,因此我添加了新的資源文件以保留每種語言的UI字符串,如MyAppUIText.en.resx
,MyAppUIText.gu.resx
等。我還創建了一個使用public static
方法的類來從應用程序中任何位置的這些資源中訪問字符串,其代碼如下所示。找不到適合指定文化的任何資源......在本地化的C#.Net桌面應用程序
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Resources;
namespace MyApp
{
namespace Utility
{
class UIText
{
private static ResourceManager rm = new ResourceManager("MyApp.MyAppUIText", typeof(FormMyAppMain).Assembly);
public static string GetString(string key)
{
return rm.GetString(key, System.Globalization.CultureInfo.CurrentUICulture);
}
}
}
}
當我運行我的應用程序,我得到以下運行時錯誤
找不到適合指定區域性或中性文化的任何資源。確保在編譯時「MyApp.MyAppUIText.resources」已正確嵌入或鏈接到程序集「MyApp 1.0」中,或者確保所有需要的附屬程序集均可加載並完全簽名。
但是,字符串正確加載到UI中,但是,窗體設計器顯示與標題To prevent possible data loss before loading the designer, the following errors must be resolved:
相同的錯誤。
我在這裏做錯了什麼?
P.S. 我是C#的新手,但我對Java非常熟悉,並且之前曾使用它的properties
文件。
不適合我.... – Kushal