asp.net-core-localization

How to localize standard error messages of validation attributes in ASP.NET Core

廉价感情. 提交于 2019-12-25 01:47:25
问题 How to localize standard error messages of validation attributes in ASP.NET Core (v2.2)? For Example, [Required] attribute has this error message " The xxx field is required. "; [EmailAddress] has " The xxx field is not a valid e-mail address. "; [Compare] has " 'xxx' and 'yyy' do not match. " and so on. In our project we use not English language and I want to find a way how to translate standard error messages without writing them directly in every attribute of every data-model class 回答1:

ASPNET Core and localization with resx files

一曲冷凌霜 提交于 2019-12-24 06:40:42
问题 I cant get my resource files loaded, or some thing else is keeping my app to load correct values. This is from my Startup.cs: services.AddLocalization(opts => { opts.ResourcesPath = "Resources"; }); services.AddMvc() .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix, opts => { opts.ResourcesPath = "Resources"; }) .AddDataAnnotationsLocalization(); services.Configure<RequestLocalizationOptions>(options => { var supportedCultures = new[] { new CultureInfo("da-DK") }; options

ASP.NET Core 1.1 Localization Generic Service

牧云@^-^@ 提交于 2019-12-23 10:42:34
问题 I'm making a ASP.NET Core 1.1 app and trying to setup localization. When I make on my ValuesController the implementation of IStringLocalizer it works fine and localize my resource file. public ValuesController(IStringLocalizer<ValuesController> localizer, IService<BaseEntity> service) { _localizer = localizer; _service = service; } The code above locate my resources at "Resources/Controllers/ValuesController.en-US.resx". But, when I try to inject the IStringLocalizer with a generic service

The Language does not change in the ASP.NET Core Web application

一个人想着一个人 提交于 2019-12-23 03:40:28
问题 I follow the Globalization and localization and Building simple multilingual ASP.NET Core website tutorials to add a language switch for my application. So, I created a partial view @using Microsoft.AspNetCore.Builder @using Microsoft.AspNetCore.Http.Features @using Microsoft.AspNetCore.Localization @using Microsoft.AspNetCore.Mvc.Localization @using Microsoft.Extensions.Options @inject IViewLocalizer Localizer @inject IOptions<RequestLocalizationOptions> LocOptions @{ var requestCulture =

ASP.NET Core DisplayAttribute Localization

被刻印的时光 ゝ 提交于 2019-12-19 16:28:26
问题 According to the documentation: The runtime doesn’t look up localized strings for non-validation attributes. In the code above, “Email” (from [Display(Name = "Email")]) will not be localized. I'm looking for a way to localize text in DisplayAttribute. Any suggestions to do it in a proper way(s)? 回答1: You can set the ResourceType on the DisplayAttribute which can be used to localize your text. Add a resource .resx file to your project e.g. MyResources.resx , and add a resource for your field:

CustomRequestCultureProvider: context.User.Identity.IsAuthenticated is always false

谁说我不能喝 提交于 2019-12-13 00:37:30
问题 I'm trying to implement a CustomRequestCultureProvider in my localization pipeline, to retrieve the user culture from the database. To identify the user, I need the ClaimsPrincipal , but for some reason, even though the user is authenticated, context.User.Identity.IsAuthenticated is always false. Here's the relevant code (truncated to highlight my issue: authentication is already working; localization code is based on the localization tutorial). public class Startup { public void

ASP.NET Core Localization with help of SharedResources

老子叫甜甜 提交于 2019-12-12 07:08:37
问题 Hi I have a question about the SharedResources file. It is glanced over in the tutorial here: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization, and I'm not sure if I get it correctly. I am supposed to create a SharedResources.cs class, but where should i put it and should it be empty or do I need to fill it with some data? Same goes for the resource file, should I create a SharedResources.da.resx file and put all my shared strings there? Where should it go? And when I

ASP.NET Core Model Binding Error Messages Localization in ASP.NET CORE 2.0

前提是你 提交于 2019-12-10 19:29:32
问题 In ASP.NET CORE 1.1 it was possible to localize model binding error messages using a resource file and configure its options to set message accessors for ModelBindingMessageProvider in the Startup.cs like services.AddMvc(options => { var F = services.BuildServiceProvider().GetService<IStringLocalizerFactory>(); var L = F.Create("ModelBindingMessages", null); options.ModelBindingMessageProvider.ValueIsInvalidAccessor = (x) => L["The value '{0}' is invalid."]; as shown here: ASP.NET Core Model

Localization in separate project Asp.net Core MVC

孤人 提交于 2019-12-10 12:55:51
问题 I just upgraded to Rc2 and what used to work no longer does. I have a couple of resx files in a separate project and I use a custom class to access the data. Now I get the following error when running it: MissingManifestResourceException: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "GarageWeb.Core.CoreResources.resources" was correctly embedded or linked into assembly "GarageWeb.Core" at compile time, or that all the satellite

aspnet.core localization cannot make it work

▼魔方 西西 提交于 2019-12-08 13:41:30
问题 It must be obvious only I cannot see the problem. I am banging my head against the wall for 6 hours now. I am trying to use localization in an aspnet.core 2.0.6 webapp. The packages I have: Microsoft.AspNetCore.All 2.0.6 Microsoft.Extensions.Localization 2.0.3 I initialized it properly using: services.AddLocalization(options => options.ResourcesPath = "Resources"); in Startup.ConfigureServices (first line) app.UseRequestLocalization(options => ...) in Startup.Configure (first line) I have a