Dude Pascalou
Dude Pascalou

Reputation: 3171

Change default culture for client side validation on ASP.NET Core MVC application

I have an ASP.NET 5.0 MVC web application with client side validation enabled. I want to set the culture to french for the client side validation messages (culture = "fr", because there is no "fr-FR" culture in cldr-json).

I took every piece of information I could from this tutorial to try to set the culture: jQuery culture validation in ASP.NET Core 2.0 (I did not took it "as is", because this is ASP.NET Core 2.0 and there is some differences with ASP.NET 5.0. Like: there is no bower any more, I used libman instead.). My _ValidationScriptsPartial.cshtml is the following:

<script src="~/lib/jquery-validation/dist/jquery.validate.js"></script>
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"></script>

<!-- cldr scripts (needed for globalize) -->
<script src="~/lib/cldrjs/dist/cldr.js"></script>
<script src="~/lib/cldrjs/dist/cldr/event.js"></script>
<script src="~/lib/cldrjs/dist/cldr/supplemental.js"></script>

<!-- globalize scripts -->
<script src="~/lib/globalize/globalize.js"></script>
<script src="~/lib/globalize/globalize/number.js"></script>
<script src="~/lib/globalize/globalize/date.js"></script>

<script src="~/lib/jquery-validation-globalize/jquery.validate.globalize.js"></script>

<script type="text/javascript">
    $.when(
        $.get("/lib/cldr-json/cldr-core/supplemental/likelySubtags.json"),
        $.get("/lib/cldr-json/cldr-numbers-full/main/fr/numbers.json"),
        $.get("/lib/cldr-json/cldr-core/supplemental/numberingSystems.json"),
        $.get("/lib/cldr-json/cldr-dates-full/main/fr/ca-gregorian.json"),
        $.get("/lib/cldr-json/cldr-dates-full/main/fr/timeZoneNames.json"),
        $.get("/lib/cldr-json/cldr-core/supplemental/timeData.json"),
        $.get("/lib/cldr-json/cldr-core/supplemental/weekData.json")
    ).then(function () {
        // Normalize $.get results, we only need the JSON, not the request statuses.
        return [].slice.apply(arguments, [0]).map(function (result) {
            return result[0];
        });
    }).then(Globalize.load).then(function () {
        Globalize.locale("fr");
    });
</script>

When I launch the web application, I have no javascript error in the Console, no Network error.

The client side application works, but it is still in english, not in french:

Client side validation messages in english

Does anyone have already managed to change the culture for the client side validation in an ASP.NET 5.0 MVC application ? Can you give me some pointers to check or share me some links to read ?

Upvotes: 1

Views: 390

Answers (0)

Related Questions