asp.net core - Single resource file for DataAnnotations localization -


what should try achieve have single resource (resx) file each supported language in net-core. explain problem bit.

i have dataannotations on each of entities , need localize messages returned in case of errors. seems default convention required net-core have different resx file each of our entities.

this file named accordingly namespace of entity culture indentifier , resx extensions. so, if have entity named customers within namespace data.entities, should add file named data.entities.customers.it.resx , put translations italian language in it. so, if have attribute

stringlength(50, errormessage="the {0} should not longer {1} characters")  public string name {get;set;} 

then add proper translation data.entities.customers.it.resx file.

but, if go on entitity suppliers forced write resource file named data.entities.suppliers.it.resx and, of course have

stringlength(50, errormessage="the {0} should not longer {1} characters")  public string suppliername {get;set;} 

now need write again same translation in proper file suppliers entity. goes on other common attributes [required].

so hope have explained problem , queston is: there way specify single resource file entities validation messages , write single time messages common texts?

from docs, can tell framework use shared resource data annotations localisation:

public void configureservices(iservicecollection services) {     services.addmvc()         .adddataannotationslocalization(options => {             options.dataannotationlocalizerprovider = (type, factory) =>                 factory.create(typeof(sharedresource));         }); } 

in preceeding code, sharedresource class corresponding resx validation messages stored. approach, dataannotations use sharedresource, rather resource each class.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -