Morris.AutoLocalize.Fody
1.0.0
Prefix Reserved
See the version list below for details.
dotnet add package Morris.AutoLocalize.Fody --version 1.0.0
NuGet\Install-Package Morris.AutoLocalize.Fody -Version 1.0.0
<PackageReference Include="Morris.AutoLocalize.Fody" Version="1.0.0" />
<PackageVersion Include="Morris.AutoLocalize.Fody" Version="1.0.0" />
<PackageReference Include="Morris.AutoLocalize.Fody" />
paket add Morris.AutoLocalize.Fody --version 1.0.0
#r "nuget: Morris.AutoLocalize.Fody, 1.0.0"
#:package Morris.AutoLocalize.Fody@1.0.0
#addin nuget:?package=Morris.AutoLocalize.Fody&version=1.0.0
#tool nuget:?package=Morris.AutoLocalize.Fody&version=1.0.0
AutoLocalize
AutoLocalize is a Fody weaver that fills in
ErrorMessageResourceType and ErrorMessageResourceName for your
ValidationAttribute-based annotations so you only declare your resource type once
per assembly.
Getting started
- Install Fody (if you do not already use it) and AutoLocalize:
<ItemGroup> <PackageReference Include="Fody" Version="6.*" PrivateAssets="All" /> <PackageReference Include="Morris.AutoLocalize.Fody" Version="1.*" /> </ItemGroup> - Build once. Fody will create a
FodyWeavers.xmlfile in your project if it does not exist. - Add AutoLocalize to
FodyWeavers.xml, then build again so weaving runs.<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> <Morris.AutoLocalize /> </Weavers> - Specify the assembly-level attribute that tells the weaver which resource class
to use. The default
ErrorMessageResourceNamePrefixis"AutoLocalize_"if you do not set it.using Morris.AutoLocalize; using System.ComponentModel.DataAnnotations; [assembly: AutoLocalizeValidationAttributes( typeof(Resources.ValidationMessages), ErrorMessageResourceNamePrefix = "AutoLocalize_")] public class Person { [Required] [StringLength(50, MinimumLength = 2)] public string Name { get; set; } = string.Empty; }
Note: In case you don't know, to get a class for your resx file you need to set its
Custom Tool property to PublicResXFileCodeGenerator.
What the weaver does
- Finds every field/property decorated with an attribute descended from
ValidationAttribute. - Ensures the
ErrorMessageResourceTypeandErrorMessageResourceNameproperties are set on each attribute. - Removes the
[assembly:AutoLocalizeValidationAttributes]attribute from your build output. - Removes the assembly reference to
Morris.AutoLocalizefrom your build output, so your runtime assembly has no extra dependencies.
ValidationAttribute update rules
ErrorMessageResourceResourceTypeis set to the value specified in the[assembly:LocalizeValidationAttributes({value here}})]attribute you added to your project.ErrorMessageResourceNameis set to{Prefix}_{ShortAttributeName}- If either the
ErrorMessageResourceTypeorErrorMessageproperties are set on the attribute then it is assumed you want a specific error message, so AutoLocalize will leave the validation attribute untouched.
Resource automatic naming algorithm
- Prefix =
AutoLocalize_- this can be overridden when declaring your[assembly:LocalizeValidationAttributes(typeof(MyResource))]attribute by setting theErrorMessageResourceNamePrefixproperty. - ShortAttributeMame = The class name of the attribute that descends from
ValidationAttributewithout the wordAttributeat the end.RequiredAttribute⇒RequiredSomeGenericValidationAttribute<int>⇒SomeGenericValidation
Examples
[assembly:AutoLocalizeValidationAttributes(typeof(DataAnnotationsMessages))]
| Attribute | ErrorMessageResourceType | ErrorMessageResourceName |
|---|---|---|
[Required] |
DataAnnotationsMessages | AutoLocalize_Required |
[Range(0, int.MaxValue, ErrorMessageResourceName="CannotBeNegative")] |
DataAnnotationsMessages | <unaltered> |
[EmailAddress(ErrorMessageResourceType=typeof(X), ErrorMessageResourceName="MustBeAValidEmailAddress")]] |
<unaltered> | <unaltered> |
[EmailAddress(ErrorMessage="{0} must be a valid email address")]] |
<unaltered> | <unaltered> |
[assembly:AutoLocalizeValidationAttributes(
typeof(DataAnnotationsMessages),
ErrorMessageResourceNamePrefix = "ValidationError_"
)]
| Attribute | ErrorMessageResourceType | ErrorMessageResourceName |
|---|---|---|
[Required] |
DataAnnotationsMessages | ValidationError_Required |
Manifest of resource keys
During weaving a CSV file named after your project (e.g.
MyProject.Morris.AutoLocalize.csv) is written next to the project file. It
contains all resource keys the weaver added or discovered:
ErrorMessageResourceName
AutoLocalize_Required
AutoLocalize_StringLength
Use this manifest to ensure your resource file contains entries for each key.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.2.1 | 264 | 3/22/2026 |
| 1.2.0-Preview1 | 86 | 3/22/2026 |
| 1.1.0 | 131 | 3/15/2026 |
| 1.0.1 | 121 | 3/10/2026 |
| 1.0.0 | 132 | 3/10/2026 |
| 0.0.11 | 107 | 3/10/2026 |
| 0.0.10 | 109 | 3/9/2026 |
| 0.0.9 | 112 | 3/9/2026 |
| 0.0.8 | 109 | 3/9/2026 |
| 0.0.7 | 115 | 3/9/2026 |
| 0.0.6 | 111 | 3/9/2026 |
| 0.0.5 | 115 | 3/8/2026 |
| 0.0.4 | 116 | 3/8/2026 |
| 0.0.3 | 113 | 3/8/2026 |
| 0.0.2 | 110 | 3/8/2026 |
| 0.0.1 | 108 | 3/8/2026 |