c# - Localization of data annotations in separate class library -


we trying implement localization our domain models existing in separate class library project within our solution. however, not able working our models data annotation attributes doesn't translated @ all.

project structure

  • solution
    • web project
      • resource folder (contains .resx files. ex. app.en.resx) works fine
    • class library
      • domain models
      • resource folder (contains .resx files. ex. app.en.resx) doesn't work

startup.cs

services.addmvc()      .addviewlocalization(languageviewlocationexpanderformat.suffix)      .adddataannotationslocalization(); 

note

localization works within web project, e.g translates views, controllers. however, doesn't work when try translate models exists in separate project.

// regards

there no support translate data annotations, views, controller etc exists in separate project without implementing yourself.

the solution write own custom implementation using istringlocalizer, istringlocalizerfactory , register in startup.cs. see how stringlocalizer/factory works.

fyi: aspnet team working on localizer aware of , working on solution support in future. see aspnet/localization


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -