OrchardCMS / OrchardCore

Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
https://orchardcore.net
BSD 3-Clause "New" or "Revised" License
7.37k stars 2.38k forks source link

Ability to extract the localization strings from DataAnnotations attributes #5702

Open hishamco opened 4 years ago

hishamco commented 4 years ago

As #4675 supports data annotations for PO, it would be nice if we let the PoExtractor extract the localization strings from ErrorMessage property, coz now we are limited to ensure that all the error messages are located in {culture}.po

I can work on this in the PoExtractor repository if sound looks good to you guys

/cc @agriffard @jtkech @Skrypt @sebastienros

agriffard commented 4 years ago

It would be a really weird enhancement in the PoExtractor. As you explain here: https://github.com/OrchardCMS/OrchardCore/pull/4675#issuecomment-597786219 You are expecting this kind of string to localize: #. msgid "The UserName field is required." So you will be looking for the class properties that have a Required attribute and generate the corresponding string.

Another example in the Account viewModels has a property named 'CurrentPassword', so you would generate: #. msgid "The CurrentPassword field is required." which is not correct in English.

I prefer to localize all validation messages by implementing IValidatableObject as I did in #5692

agriffard commented 4 years ago

May be a compromise would be to specify the ErrorMessage parameter when you use the Required attribute and generate .po strings only for those ones. https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.dataannotations.requiredattribute

hishamco commented 4 years ago

. msgid "The UserName field is required."

This will be generated if the ErrorMessage contains "The UserName field is required.", otherwise will use the default error message unless you override it in a PO file

So nothing weird here, it will use the same extract mechanism that we 're used, all other translations will be done via Crowdin