Lenon
Lenon
CC#
Created by Lenon on 5/20/2024 in #help
.resx does not properly generate Design-File
Looking at AspNetCore Identity (or the whole aspnetcore logic), we can see, that their ErrorDescribers access the resource like:
<data name="UserNotInRole" xml:space="preserve">
<value>User is not in role '{0}'.</value>
<comment>Error when a user is not in the role</comment>
</data>
<data name="UserNotInRole" xml:space="preserve">
<value>User is not in role '{0}'.</value>
<comment>Error when a user is not in the role</comment>
</data>
This will result in a generated method with the following:
/// <summary>User is not in role '{0}'.</summary>
internal static string @UserNotInRole => GetResourceString("UserNotInRole");
/// <summary>User is not in role '{0}'.</summary>
internal static string FormatUserNotInRole(object p0)
=> string.Format(Culture, GetResourceString("UserNotInRole"), p0);
/// <summary>User is not in role '{0}'.</summary>
internal static string @UserNotInRole => GetResourceString("UserNotInRole");
/// <summary>User is not in role '{0}'.</summary>
internal static string FormatUserNotInRole(object p0)
=> string.Format(Culture, GetResourceString("UserNotInRole"), p0);
And allows to call it like a method with a parameter:
/// <summary>
/// Returns an <see cref="IdentityError"/> indicating a user is not in the specified <paramref name="role"/>.
/// </summary>
/// <param name="role">The duplicate role.</param>
/// <returns>An <see cref="IdentityError"/> indicating a user is not in the specified <paramref name="role"/>.</returns>
public virtual IdentityError UserNotInRole(string role)
{
return new IdentityError
{
Code = nameof(UserNotInRole),
Description = Resources.FormatUserNotInRole(role)
};
}
/// <summary>
/// Returns an <see cref="IdentityError"/> indicating a user is not in the specified <paramref name="role"/>.
/// </summary>
/// <param name="role">The duplicate role.</param>
/// <returns>An <see cref="IdentityError"/> indicating a user is not in the specified <paramref name="role"/>.</returns>
public virtual IdentityError UserNotInRole(string role)
{
return new IdentityError
{
Code = nameof(UserNotInRole),
Description = Resources.FormatUserNotInRole(role)
};
}
When i edit this file with more params like User is not in role '{0}' ABC: {1} the generated method will update properly to be generated like internal static string FormatUserNotInRole(object p0, object p1) . So now i want to achieve this within my own project. But somehow i couldn´t manage the localization to generate those damn parameters and i have absolutely no clue why. I´ve already set the generator as well as the file.
2 replies