english language for app-captcha
This commit is contained in:
@@ -1,37 +0,0 @@
|
||||
namespace zero.Localization;
|
||||
|
||||
public class FluentValidationGermanLanguage
|
||||
{
|
||||
public static readonly Dictionary<string, string> Translations = new()
|
||||
{
|
||||
{ "EmailValidator", "Keine gültige E-Mail-Adresse" },
|
||||
{ "GreaterThanOrEqualValidator", "Der Wert muss grösser oder gleich '{ComparisonValue}' sein." },
|
||||
{ "GreaterThanValidator", "Der Wert muss grösser sein als '{ComparisonValue}'." },
|
||||
{ "LengthValidator", "Die Länge muss zwischen {MinLength} und {MaxLength} Zeichen liegen. Es wurden {TotalLength} Zeichen eingetragen." },
|
||||
{ "MinimumLengthValidator", "Die Länge muss größer oder gleich {MinLength} sein. Sie haben {TotalLength} Zeichen eingegeben." },
|
||||
{ "MaximumLengthValidator", "Die Länge muss kleiner oder gleich {MaxLength} sein. Sie haben {TotalLength} Zeichen eingegeben." },
|
||||
{ "LessThanOrEqualValidator", "Der Wert muss kleiner oder gleich '{ComparisonValue}' sein." },
|
||||
{ "LessThanValidator", "Der Wert muss kleiner sein als '{ComparisonValue}'." },
|
||||
{ "NotEmptyValidator", "Dieses Feld darf nicht leer sein." },
|
||||
{ "NotEqualValidator", "Dieser Wert darf nicht '{ComparisonValue}' sein." },
|
||||
{ "NotNullValidator", "Dieses Feld darf nicht leer sein." },
|
||||
{ "PredicateValidator", "Der Wert entspricht nicht der festgelegten Bedingung." },
|
||||
{ "AsyncPredicateValidator", "Der Wert entspricht nicht der festgelegten Bedingung." },
|
||||
{ "RegularExpressionValidator", "Dieses Feld weist ein ungültiges Format auf." },
|
||||
{ "EqualValidator", "Der Wert muss gleich '{ComparisonValue}' sein." },
|
||||
{ "ExactLengthValidator", "Dieses Feld muss genau {MaxLength} lang sein. Es wurden {TotalLength} eingegeben." },
|
||||
{ "ExclusiveBetweenValidator", "Der Wert muss zwischen {From} und {To} sein (exklusiv). Es wurde {PropertyValue} eingegeben." },
|
||||
{ "InclusiveBetweenValidator", "Der Wert muss zwischen {From} and {To} sein. Es wurde {PropertyValue} eingegeben." },
|
||||
{ "CreditCardValidator", "Keine gültige Kreditkartennummer." },
|
||||
{ "ScalePrecisionValidator", "Das Feld darf insgesamt nicht mehr als {ExpectedPrecision} Ziffern enthalten, mit Berücksichtigung von {ExpectedScale} Dezimalstellen. Es wurden {Digits} Ziffern und {ActualScale} Dezimalstellen gefunden." },
|
||||
{ "EmptyValidator", "Dieses Feld sollte leer sein." },
|
||||
{ "NullValidator", "Dieses Feld sollte leer sein." },
|
||||
{ "EnumValidator", "Dieses Feld hat einen Wertebereich, der '{PropertyValue}' nicht enthält." },
|
||||
// Additional fallback messages used by clientside validation integration.
|
||||
{ "Length_Simple", "Die Länge muss zwischen {MinLength} und {MaxLength} Zeichen liegen." },
|
||||
{ "MinimumLength_Simple", "Die Länge muss größer oder gleich {MinLength} sein." },
|
||||
{ "MaximumLength_Simple", "Die Länge muss kleiner oder gleich {MaxLength} sein." },
|
||||
{ "ExactLength_Simple", "Dieses Feld muss genau {MaxLength} lang sein." },
|
||||
{ "InclusiveBetween_Simple", "Der Wert muss zwischen {From} and {To} sein." }
|
||||
};
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
using FluentValidation.Resources;
|
||||
|
||||
namespace zero.Localization;
|
||||
|
||||
public static class LanguageManagerExtensions
|
||||
{
|
||||
public static ILanguageManager AddGermanOverrides(this ILanguageManager manager)
|
||||
{
|
||||
if (manager is LanguageManager languageManager)
|
||||
{
|
||||
foreach (var kvp in FluentValidationGermanLanguage.Translations)
|
||||
{
|
||||
languageManager.AddTranslation("de", kvp.Key, kvp.Value);
|
||||
}
|
||||
}
|
||||
return manager;
|
||||
}
|
||||
}
|
||||
@@ -12,9 +12,6 @@ internal class ZeroLocalizationModule : ZeroModule
|
||||
public override void ConfigureServices(IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
// hint: think about using https://github.com/nuages-io/nuages-localization
|
||||
|
||||
ValidatorOptions.Global.LanguageManager.AddGermanOverrides();
|
||||
|
||||
services.AddScoped<ICultureResolver, CultureResolver>();
|
||||
services.AddScoped<ICultureService, CultureService>();
|
||||
services.AddScoped<ILocalizer, ConfigurationLocalizer>();
|
||||
|
||||
@@ -8,7 +8,7 @@ using zero.Security;
|
||||
|
||||
namespace zero.TagHelpers;
|
||||
|
||||
[HtmlTargetElement("app-captcha", Attributes = "for", TagStructure = TagStructure.NormalOrSelfClosing)]
|
||||
[HtmlTargetElement("app-captcha", Attributes = "for,lang", TagStructure = TagStructure.NormalOrSelfClosing)]
|
||||
public class CaptchaTagHelper(IOptionsMonitor<CaptchaOptions> options) : TagHelper
|
||||
{
|
||||
[HtmlAttributeNotBound]
|
||||
@@ -18,6 +18,9 @@ public class CaptchaTagHelper(IOptionsMonitor<CaptchaOptions> options) : TagHelp
|
||||
[HtmlAttributeName("for")]
|
||||
public ModelExpression For { get; set; }
|
||||
|
||||
[HtmlAttributeName("lang")]
|
||||
public string Lang { get; set; }
|
||||
|
||||
private readonly CaptchaOptions _options = options.CurrentValue;
|
||||
|
||||
|
||||
@@ -41,7 +44,14 @@ public class CaptchaTagHelper(IOptionsMonitor<CaptchaOptions> options) : TagHelp
|
||||
output.PreElement.AppendHtml($"<script>window.CAP_CUSTOM_WASM_URL = '{wasmFilePath}';</script>");
|
||||
output.PreElement.AppendHtml($"<script type='module' src='{widgetFilePath}'></script>");
|
||||
|
||||
foreach ((string key, string value) in _options.Localization)
|
||||
CaptchaLocalizationOptions texts = _options.Localization;
|
||||
|
||||
if (Lang == "en")
|
||||
{
|
||||
texts = CaptchaLocalizationOptions.English;
|
||||
}
|
||||
|
||||
foreach ((string key, string value) in texts)
|
||||
{
|
||||
output.Attributes.SetAttribute($"data-cap-i18n-{key}", value);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace zero.Validation;
|
||||
|
||||
public class FluentValidationEnglishLanguage
|
||||
{
|
||||
public static Dictionary<string, string> Translations = new()
|
||||
{
|
||||
{ "EmailValidator", "Invalid email address" },
|
||||
{ "UrlValidator", "Not a well-formed URL" },
|
||||
{ "HexValidator", "Invalid HEX value" },
|
||||
{ "CaptchaValidator", "The captcha was not solved" }
|
||||
};
|
||||
}
|
||||
@@ -7,8 +7,9 @@ namespace zero.Validation;
|
||||
|
||||
public static class ServiceCollectionExtensions
|
||||
{
|
||||
public static void AddGermanValidation(this IServiceCollection services)
|
||||
public static void AddValidationLanguageExtensions(this IServiceCollection services)
|
||||
{
|
||||
ValidatorOptions.Global.LanguageManager.AddEnglishOverrides();
|
||||
ValidatorOptions.Global.LanguageManager.AddGermanOverrides();
|
||||
services.Replace<IdentityErrorDescriber, GermanIdentityErrorDescriber>(ServiceLifetime.Scoped);
|
||||
}
|
||||
@@ -27,4 +28,18 @@ public static class ServiceCollectionExtensions
|
||||
}
|
||||
return manager;
|
||||
}
|
||||
|
||||
static ILanguageManager AddEnglishOverrides(this ILanguageManager manager)
|
||||
{
|
||||
if (manager is LanguageManager)
|
||||
{
|
||||
var lmanager = manager as LanguageManager;
|
||||
|
||||
foreach (var kvp in FluentValidationEnglishLanguage.Translations)
|
||||
{
|
||||
lmanager.AddTranslation("en", kvp.Key, kvp.Value);
|
||||
}
|
||||
}
|
||||
return manager;
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ internal class ZeroValidationModule : ZeroModule
|
||||
{
|
||||
public override void ConfigureServices(IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
services.AddValidationLanguageExtensions();
|
||||
services.AddScoped(typeof(IZeroMergedValidator<>), typeof(ZeroMergedValidator<>));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user