using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace LanguageTest { class Program { static void Main(string[] args) { bool stop = false; while(!stop) { Console.WriteLine("请输入系统语种,如 en, cn"); var lang = Console.ReadLine(); SetCulture(lang); Console.WriteLine(Resource.String1); Console.WriteLine("是否退出? y=退出 n=继续"); stop = Console.ReadLine() == "y"; } } public static void SetCulture(string languageId) { //语言转换 if (languageId == "cn") languageId = "zh-cn"; else if (languageId == "jp") languageId = "ja-jp"; else if (languageId == "hant") languageId = "zh-hant"; else languageId = "en-us"; var info = new CultureInfo(languageId); Thread.CurrentThread.CurrentCulture = info; Thread.CurrentThread.CurrentUICulture = info; } } }
注意一点,资源文件必须要有一个默认语言的资源文件,如上面的Resource.resx,不能都写上语言名称,必须留一个不写语言名称的。