Localising ASP.NET MVC JQuery Validation on Azure - asp.net-mvc

I am developing a website to support both Arabic and English. Now, when on the development I only need to use DisplayAttribute to localize field names and set the thread to the appropriate culture, and then ASP.NET generates a localized error message using my DispalyAttribute names.
However, when deploying on Azure, and when I switch to Arabic, everything is localized correctly but error messages. In which the names are localized but the error itself is in English.
I could use ErrorMessageResourceType explicitly, but would like to know where is the discrepancy.
Note: I set thread culture at Application_BeginRequest of Global.asax.

I made a little hack to know where the issue is. I created my own ValidationAttribute which basically reports current culture name instead of the error message. It turned out that the culture is properly set, and that it seems Azure version of DataAnnotationResources might not include Arabic.

Related

.NET6 Blazor Server Application Localization

I would like to add language resources to my application based on the browser language preferences.
Blazor server application, .net6, c#
I will be using the syntax such as this on a razor page. #localizer["helloworld"]
I expecting the localizer to know the language set in the browser and then use the appropriate resource file.
I am using ISO language codes for the resource files. The app needs to support english and french, so I have resource.resx and resource.fr.resx
I have spent lots of time trying to get this to work. The documentation seems so easy, yet I have had zero success.
The application will compile and run. The default language of English is always coming up, regardless of the browser language setting. My theory is either the browser language is not being detected, or the naming of the resource file is incorrect preventing the localizer from using it.
The first lesson is that where builder.Services.AddLocalization(); is declared in program.cs is important. It will not function at all if in the wrong location (line)
Does anyone have any experience with this issue using .net6 and Blazor server app?
Thanks,
Marc.
For a full example about localization.
https://github.com/iso8859/AspNetCoreAuthMultiLang
#region Localization
builder.Services.AddLocalization(option => option.ResourcesPath = "Resources");
builder.Services.Configure<RequestLocalizationOptions>(options =>
{
var supportedCultures = new List<CultureInfo>()
{
new CultureInfo("en-US"),
new CultureInfo("fr-FR")
};
options.DefaultRequestCulture = new RequestCulture("en-US");
options.SupportedCultures = supportedCultures;
options.SupportedUICultures = supportedCultures;
});
#endregion
#edit
Because server side blazor app are Single Page App you can't change the cookie. The only way to change a cookie it is to do a page refresh. This is done in the AuthController.cs
For WASM Project you can set cookie using Javascript
the value is for en-US
Set-Cookie: .AspNetCore.Culture=c%3Den-US%7Cuic%3Den-US; path=/
Both the above posts provided the information I needed for my implementation. Some of the MS documentation was a bit cryptic in assuming you knew all the correct parameter settings, but after a bit of tweaking I was successfully able to build the solution I required for my application. Thanks to all for their help.

MVC CultureInfo language-code needed for Hmong

I am working on a MVC project that will have its pages in English, Spanish, and Hmong using CultureInfo. I am unsure what language code I should use for the Hmong translations. I haven't found anything related to it other than other than hmn(ISO 639-2 Code). Should I use this or something else?
You may find Hmong to be a few different culture codes. Our plant workers use a dashboard we wrote and their version of spoken Hmong most closely resembled vi-VN . So that is the culture code we use when our Hmong workers switch their displays to their translated language.

MVC Validation: Same project, different languages: why?

When I start my MVC application and try to sumbit a form with an empty field than validation is fired and the following message appears (german):
Das Feld "Telefon" ist erforderlich.
If i do the same on my bosses computer, the message is
The Telefon field is required.
I checked if out windows settings for region and language are different, but they are the same? What else could be the reason?
EDIT
Solution is to install 'Microsoft .NET Framework 4 Extended DEU Language Pack' (or your perferred language) and to add the culture information in Views/web.config in the <system.web>-Part:
<globalization culture="de-DE" uiCulture="de-DE"/>
On your computer you probably installed the German localized version of the .NET Framework so all error messages are coming from the localized satellite assemblies. Phil Haack blogged about localizing validation messages.
In most browsers you can specify your preferred languages. These can be different from your windows settings.
Check the Accepted-language request header.

Swap English to Spanish in ValidationMessageFor Method Dynamicaly

My Models / data silos are in a different class library which contain data annotation - Required, Max Length and some custom validation. This all works great in English however is there a way to swap the English validation message for the Spanish using a global resource file contained in the web project. The class library is used both on the web site and other components so I cannot be assured that the resource file will be in the same project.
Assuming you are talking about a .Net MVC application, I suggest you have a look at this blog post about internationalization in MVC3:
http://afana.me/post/aspnet-mvc-internationalization.aspx
For a project I am currently working on, we decided to place the resource-files in a separate project, so that we could keep all the resource-strings in one place, and then simply referring to the language-project from any other project that needs multi-lingual support.

Custom Resource Provider

I am using custom resource provider in Asp.Net to get the data from the external resource files, After changing the browser language it does not select the proper translation. i.e. It always returns English version. On the other side, if i use Asp.Net tag
It returns the correct translation. I configured it in web.config
Am i missing something?
Actually i figured out by myself. In my custom resouce provider, i was passing the cultureinfo by myself. I change it to null and it started working. Its wiered but worked for me.

Resources