3 回答

TA貢獻1851條經驗 獲得超5個贊
在某些情況下,使用資源文件可能會更容易。
將新的資源文件添加到Visual Studio中的項目。例如。
en.resx
對于英語,fr.resx
對于法語。打開資源文件,在字符串中,命名您的字符串,然后在值單元格中放置其他翻譯。例如:
next station
的在值en.resx
就是next station
但fr.resx
可以Prochaine station
。在代碼中,用于
public static ResourceManager rm = new ResourceManager("WindowsFormsApp1.en_local", Assembly.GetExecutingAssembly());
選擇語言資源。當您需要向應用程序輸出任何字符串時,請使用function
GetString()
,例如label1.Text = rm.GetString("welcome");

TA貢獻1836條經驗 獲得超13個贊
wwjih123的答案中缺少一些內容。
在VS2017中
首先,首先在項目根文件夾(不在Resources文件夾中)中創建資源。命名為lang_en,lang_tr,lang_fr等...
2-然后對象屬性窗口將“生成”操作保留為“嵌入式資源”
在lang_tr.resx文件的3邊添加土耳其語的新字符串lbl_error和值“ Hata”(無論您喜歡什么)
4-在類內部定義變量為:
ResourceManager res_man; // declare Resource manager to access to specific cultureinfo
在InitializeComponent()之后進行5 in類初始化;
Console.WriteLine("You are speaking {0}",
System.Globalization.CultureInfo.CurrentUICulture.TwoLetterISOLanguageName);
res_man = new ResourceManager("MyApp.lang_"+ System.Globalization.CultureInfo.CurrentUICulture.TwoLetterISOLanguageName, Assembly.GetExecutingAssembly());
lblError.Text = res_man.GetString("lbl_error");
如果您的ui語言是土耳其語,它將自動加載lang_tr.resx,如果是英語,則將加載lang_en.resx文件,依此類推...
祝好運
- 3 回答
- 0 關注
- 607 瀏覽
添加回答
舉報