0

I'm struggling with JQuery Validation Unobstrousive, which is already built in with creating an ASP.Net MVC 5 Project.

Locally my whole machine is in a german environment. The validation text of JQuery Validation is coming from my data annotations:

[MaxLength(2000)]
public string Beschreibung { get; set; }

Debugging my project locally show the validation messages in german language. After deploying on the server the validation messages are changed to english language.

I searched on the Internet and found several possible solutions, but no one was working for me:

  • loading german localization file after validation-js-files
  • setting in html-tag: lang="de-de"
  • setting in web.config: globalization culture="de-DE" uiCulture="de-DE"
  • setting in Global.asax.cs:

.

protected void Application_BeginRequest(object sender, EventArgs e)
{
    CultureInfo culture = new CultureInfo("de-DE");
    Thread.CurrentThread.CurrentCulture = culture;
    Thread.CurrentThread.CurrentUICulture = culture;
}

When checking the CultureInfo in the view (

<h2>@System.Threading.Thread.CurrentThread.CurrentCulture</h2>
<h2>@System.Threading.Thread.CurrentThread.CurrentUICulture</h2>

), it's always showing correctly "de-DE", but all validation messages are still english.

Can anybody help me? I want to change the language from english to the existing german language.

Sparky
  • 98,165
  • 25
  • 199
  • 285
sandy
  • 464
  • 1
  • 6
  • 13
  • could you please follow this thread, Are you including your Globalization file in HTML ? https://github.com/aspnet/AspNetCore.Docs/issues/4076 – Samaritan_Learner Jul 12 '19 at 07:37
  • This thread also will help you out to sovle this - https://stackoverflow.com/questions/44924907/mvc-5-validation-german-date-with-unobtrusiv-js-a-simple-approach – Samaritan_Learner Jul 12 '19 at 07:39
  • 1
    `@System.Globalization.CultureInfo.CurrentUICulture` is showing me also correctly "de-DE" while messages are english. – sandy Jul 12 '19 at 07:45
  • The second thread will not help me because the validating it self is working properly. My problem are the auto-generated messages from my data annotations. So the problem is on server-side, not client-side jquery i think. – sandy Jul 12 '19 at 07:50
  • why can't you pass the, messages manually from your end like this - [Required(ErrorMessage = "Text with German Language")] – Samaritan_Learner Jul 12 '19 at 07:53
  • I think you may need to add your own messages in resources and modify the data annotations instead of that you can pass the message in model itself by yourself will make it easier if its only for few places. – Samaritan_Learner Jul 12 '19 at 07:56
  • I could do this, but then I have to define every single ErrorMessage manually though the german messages are there but you can't activate them -.- It's so stupid man.. But your idea would be my last choice if I can't find any other solutions. Thank you – sandy Jul 12 '19 at 07:56
  • You can do it globally by adding the resources, I never tried this practically but just now gone through this for you, Sorry mate I cant help you much. Cheers. - https://learn.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-2.2 – Samaritan_Learner Jul 12 '19 at 08:01

0 Answers0