GithubHelp home page GithubHelp logo

jsakamoto / toolbelt.blazor.localizeddataannotationsvalidator Goto Github PK

View Code? Open in Web Editor NEW
16.0 5.0 3.0 444 KB

The Data Annotations Validator Component for Blazor to localize validation error messages, based on "Microsoft.Extensions.Localization".

Home Page: https://demo-blazor-localized-data-annotations-validator.azurewebsites.net/

License: Apache License 2.0

C# 78.11% HTML 14.47% CSS 7.43%
blazor localization i18n dataannotations validator

toolbelt.blazor.localizeddataannotationsvalidator's Introduction

Localized Data Annotations Validator Component for Blazor NuGet Package

Summary

This is the Data Annotations Validator Component for Blazor to localize the validation error messages, based on Microsoft.Extensions.Localization.

Live Demo - https://demo-blazor-localized-data-annotations-validator.azurewebsites.net/

fig1

[NOTICE]

This component will works fine on "Server-side Blazor", not "Client-side Blazor" at this time.

The supporting of Microsoft.Extensions.Localization based localization on Client-side Blazor is weak, therefore it will need some hacks. (see also: https://dev.to/5argon/comment/gdch)

Another way, "Blazor I18n Text" service will work fine on both Server-side Blazor and Client-side Blazor. However, it is not integrated Microsoft.Extensions.Localization based localization at this time.

How to use?

Step 1. Setup "IStringLocalizer" infrastructure on your Blazor app

See also:

Of course, you should create resource files (.resx) for data annotation validation error messages, too.

fig.2

Step 2. Install this package

Like this:

> dotnet add package Toolbelt.Blazor.LocalizedDataAnnotationsValidator

Step3. Replace the data annotations validator component

Rewrite the implementation of the validation on your app.

At first, open the "Toolbelt.Blazor.Forms" namespace, in the _Imports.razor.

...
@using Toolbelt.Blazor.Forms

Next, replace the DataAnnotationsValidator to LocalizedDataAnnotationsValidator.

For example, in your .razor file, rewrite it from:

<EditForm Model="..." ...>
  <DataAnnotationsValidator />
  ...

to:

<EditForm Model="..." ...>
  <!-- �« Replace this component! -->
  <LocalizedDataAnnotationsValidator />
  ...

That's all!

Sample Source Code

You can get the source code of Live Demo site from this repository.

Release Note

  • v.1.0.1
    • Fix: concurrent access problem
    • Change license from MPL-2.0 to Apache-2.0
  • v.1.0.0. - Initial release.

License

Apache License Version 2.0

toolbelt.blazor.localizeddataannotationsvalidator's People

Contributors

jsakamoto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

toolbelt.blazor.localizeddataannotationsvalidator's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.