3
A
回答
4
在project.json你需要這種依賴性
"Microsoft.Extensions.Localization": "1.0.0-rc2-final",
在Startup.cs在ConfigureServices你需要這樣的代碼:
services.AddLocalization(options => options.ResourcesPath = "GlobalResources");
services.Configure<RequestLocalizationOptions>(options =>
{
var supportedCultures = new[]
{
new CultureInfo("en-US"),
new CultureInfo("en"),
new CultureInfo("fr-FR"),
new CultureInfo("fr"),
};
// State what the default culture for your application is. This will be used if no specific culture
// can be determined for a given request.
options.DefaultRequestCulture = new RequestCulture(culture: "en-US", uiCulture: "en-US");
// You must explicitly state which cultures your application supports.
// These are the cultures the app supports for formatting numbers, dates, etc.
options.SupportedCultures = supportedCultures;
// These are the cultures the app supports for UI strings, i.e. we have localized resources for.
options.SupportedUICultures = supportedCultures;
// You can change which providers are configured to determine the culture for requests, or even add a custom
// provider with your own logic. The providers will be asked in order to provide a culture for each request,
// and the first to provide a non-null result that is in the configured supported cultures list will be used.
// By default, the following built-in providers are configured:
// - QueryStringRequestCultureProvider, sets culture via "culture" and "ui-culture" query string values, useful for testing
// - CookieRequestCultureProvider, sets culture via "ASPNET_CULTURE" cookie
// - AcceptLanguageHeaderRequestCultureProvider, sets culture via the "Accept-Language" request header
//options.RequestCultureProviders.Insert(0, new CustomRequestCultureProvider(async context =>
//{
// // My custom request culture logic
// return new ProviderCultureResult("en");
//}));
});
in配置你需要的代碼是這樣的:
var locOptions = app.ApplicationServices.GetService<IOptions<RequestLocalizationOptions>>();
app.UseRequestLocalization(locOptions.Value);
我有一些working demo code here,如果你需要更多的
相關問題
- 1. 如何更改默認文件夾
- 2. uiswitch默認文本更改
- 3. 更改默認化背景色
- 4. 如何更改Symfony2 Behat Bundle默認功能上下文文件(FeatureContext.php默認)
- 5. 如何更改下拉列表中的默認空白默認值(更改後)
- 6. 更改默認pythonpath
- 7. 更改默認SKScene
- 8. 更改默認庫
- 9. 如何更改Android默認瀏覽器默認主頁URL
- 10. 如何更改NgbCollapse的默認值false?
- 11. 如何更改groovysh.profile的默認位置?
- 12. PhantomJS C#如何更改默認語言
- 13. 如何更改Android Studio默認佈局
- 14. 如何更改默認佈局目錄?
- 15. 如何更改ServiceStack中的默認ContentType?
- 16. JPA - EclipseLink - 如何更改默認架構
- 17. 如何更改Crawler4j中的默認crawlStorageFolder?
- 18. mvc如何更改默認路由
- 19. 如何更改javacard默認鍵?
- 20. 如何更改phpldapadmin默認端口?
- 21. 如何更改Spree默認主頁?
- 22. 如何更改QDialogBox中的默認QPushButton
- 23. Highstocks - 如何更改默認縮放
- 24. 如何更改默認版權模板
- 25. 如何更改默認的python版本?
- 26. 如何更改DatePicker默認的「級別」?
- 27. 如何更改UIWebView默認字體
- 28. 如何更改爲Drupal默認管理
- 29. 如何更改默認的URL地址
- 30. 如何更改默認主頁圖標
你能校驗編碼的意見(* .cshml)文件使用的是什麼?他們是UTF-8還是一些ISO-8859-x編碼? – Tseng
你可以通過選擇文件並轉到文件>另存爲...>保存編碼...並選擇「Unicode(帶簽名的UTF-8)」 – Tseng
完美,它的工作! –