我開發了一個簡單的應用程序,它使用便攜式對象將單詞從英語翻譯成挪威語。no.po(便攜物品)msgid "Hello world!"msgstr "Hei Verden!"msgid "Date Of Birth"msgstr "F?dselsdato"啟動.cspublic void ConfigureServices(IServiceCollection services){ services.Configure<CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1) .AddViewLocalization(); services.AddPortableObjectLocalization(); services.Configure<RequestLocalizationOptions>( opts => { var supportedCultures = new List<CultureInfo> { new CultureInfo("en-US"), new CultureInfo("en"), new CultureInfo("fr-FR"), new CultureInfo("fr"), new CultureInfo("no"), new CultureInfo("nb-NO"), }; opts.DefaultRequestCulture = new RequestCulture("en-US"); opts.SupportedCultures = supportedCultures; opts.SupportedUICultures = supportedCultures; });}// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.public void Configure(IApplicationBuilder app, IHostingEnvironment env){ if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseCookiePolicy(); app.UseRequestLocalization(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); });}實際輸出如上圖所示,F dselsdato 未正確編碼。我不知道這背后的原因是什么。如果我錯過了代碼中的任何內容,請建議我實現我的期望。預期輸出應為F?dselsdato謝謝。
1 回答

UYOU
TA貢獻1878條經驗 獲得超4個贊
我找到了解決問題的方法。為了運行顯示國際語言字符,我們需要檢查我們的文件是否為UTF-8格式。默認情況下,它將采用ANSI格式。我們需要使用任何文本編輯器將其從ANSI轉換為UTF-8。我將展示我是如何修復它的。
在Notepad++ 中打開包含本地化文本的可移植對象 (po) 文件,然后轉到“編碼”選項卡并檢查格式。如果它不是UTF-8格式,則將其轉換為UTF-8,如下所示。
保存文件并運行應用程序,您會看到所有字符在瀏覽器中完美顯示。
- 1 回答
- 0 關注
- 212 瀏覽
添加回答
舉報
0/150
提交
取消