diff --git a/Yavsc.Server/Attributes/Validation/YaRegularExpression.cs b/Yavsc.Server/Attributes/Validation/YaRegularExpression.cs index 3d0a5e4a..eb42373b 100644 --- a/Yavsc.Server/Attributes/Validation/YaRegularExpression.cs +++ b/Yavsc.Server/Attributes/Validation/YaRegularExpression.cs @@ -1,5 +1,4 @@ using System.Resources; -using Yavsc.Resources; namespace Yavsc.Attributes.Validation { @@ -11,7 +10,7 @@ namespace Yavsc.Attributes.Validation public override string FormatErrorMessage(string name) { - return ResourcesHelpers.DefaultResourceManager.GetString(this.ErrorMessageResourceName); + return ResourcesHelpers.GlobalLocalizer[this.ErrorMessageResourceName]; } } } \ No newline at end of file diff --git a/Yavsc.Server/Attributes/Validation/YaRequiredAttribute.cs b/Yavsc.Server/Attributes/Validation/YaRequiredAttribute.cs index 4e7a7503..fffa9a95 100644 --- a/Yavsc.Server/Attributes/Validation/YaRequiredAttribute.cs +++ b/Yavsc.Server/Attributes/Validation/YaRequiredAttribute.cs @@ -16,7 +16,7 @@ namespace Yavsc.Attributes.Validation } public YaRequiredAttribute () { - this.ErrorMessage = ResourcesHelpers.DefaultResourceManager.GetString("RequiredField"); + this.ErrorMessage = ResourcesHelpers.GlobalLocalizer["RequiredField"]; } public override bool IsValid(object value) { diff --git a/Yavsc.Server/Attributes/Validation/YaStringLength.cs b/Yavsc.Server/Attributes/Validation/YaStringLength.cs index d7d94bb9..e7aa65ed 100644 --- a/Yavsc.Server/Attributes/Validation/YaStringLength.cs +++ b/Yavsc.Server/Attributes/Validation/YaStringLength.cs @@ -6,7 +6,7 @@ namespace Yavsc.Attributes.Validation private long maxLen; public YaStringLength(long maxLen) : base( ()=>string.Format( - ResourcesHelpers.DefaultResourceManager.GetString("BadStringLength"), + ResourcesHelpers.GlobalLocalizer["BadStringLength"], maxLen)) { this.maxLen = maxLen; @@ -43,12 +43,12 @@ namespace Yavsc.Attributes.Validation if (MinLen<0) { // DetailledMaxStringLength return string.Format( - ResourcesHelpers.DefaultResourceManager.GetString("DetailledMaxStringLength"), + ResourcesHelpers.GlobalLocalizer["DetailledMaxStringLength"], maxLen, excedent); } else return string.Format( - ResourcesHelpers.DefaultResourceManager.GetString("DetailledMinMaxStringLength"), + ResourcesHelpers.GlobalLocalizer["DetailledMinMaxStringLength"], MinLen, maxLen, manquant, diff --git a/Yavsc.Server/Attributes/Validation/YaValidationAttribute.cs b/Yavsc.Server/Attributes/Validation/YaValidationAttribute.cs index 02e5ba2e..c6af52d5 100644 --- a/Yavsc.Server/Attributes/Validation/YaValidationAttribute.cs +++ b/Yavsc.Server/Attributes/Validation/YaValidationAttribute.cs @@ -4,7 +4,7 @@ namespace Yavsc.Attributes.Validation { public class YaValidationAttribute : System.ComponentModel.DataAnnotations.ValidationAttribute { - public YaValidationAttribute() : base(()=> ResourcesHelpers.DefaultResourceManager.GetString("validationError")) + public YaValidationAttribute() : base(()=> ResourcesHelpers.GlobalLocalizer["validationError"]) { } @@ -16,7 +16,7 @@ namespace Yavsc.Attributes.Validation public override string FormatErrorMessage(string name) { - return ResourcesHelpers.DefaultResourceManager.GetString(name); + return ResourcesHelpers.GlobalLocalizer[name]; } } } \ No newline at end of file diff --git a/Yavsc.Server/Helpers/ResourcesHelpers.cs b/Yavsc.Server/Helpers/ResourcesHelpers.cs index a20a7bc7..cb10c6c6 100644 --- a/Yavsc.Server/Helpers/ResourcesHelpers.cs +++ b/Yavsc.Server/Helpers/ResourcesHelpers.cs @@ -1,14 +1,8 @@ +using System; using System.Resources; -using Yavsc.Resources; +using Microsoft.Extensions.Localization; public static class ResourcesHelpers { - - static ResourceManager _defaultResourceManager - = ResourceManager.CreateFileBasedResourceManager("Yavsc.Localization",".",typeof(YavscLocalisation)); - - public static ResourceManager DefaultResourceManager - { - get { return _defaultResourceManager; } - set { _defaultResourceManager = value; } - } + public static IStringLocalizer GlobalLocalizer = null ; + } \ No newline at end of file diff --git a/Yavsc.Server/Models/HairCut/HairCutQuery.cs b/Yavsc.Server/Models/HairCut/HairCutQuery.cs index d82774d7..839d2477 100644 --- a/Yavsc.Server/Models/HairCut/HairCutQuery.cs +++ b/Yavsc.Server/Models/HairCut/HairCutQuery.cs @@ -22,10 +22,8 @@ namespace Yavsc.Models.Haircut // Bill description public override string GetDescription() { - string type = ResourcesHelpers.DefaultResourceManager - .GetString(this.GetType().Name); - string gender = ResourcesHelpers.DefaultResourceManager - .GetString(this.Prestation.Gender.ToString()); + string type = ResourcesHelpers.GlobalLocalizer[this.GetType().Name]; + string gender = ResourcesHelpers.GlobalLocalizer[this.Prestation.Gender.ToString()]; return $"{type} ({gender})"; } @@ -88,8 +86,7 @@ namespace Yavsc.Models.Haircut Name = "Coupe", Description = $"Coupe "+ - ResourcesHelpers.DefaultResourceManager - .GetString(Prestation.Gender.ToString())+ " "+ + ResourcesHelpers.GlobalLocalizer[Prestation.Gender.ToString()]+ " "+ (Prestation.Gender == HairCutGenders.Women ? Prestation.Length == HairLength.Long ? longhairsuffix : Prestation.Length == HairLength.HalfLong ? halflonghairsuffix : diff --git a/Yavsc.Server/Models/HairCut/HairCutQueryEvent.cs b/Yavsc.Server/Models/HairCut/HairCutQueryEvent.cs index a4de1abb..31dd8a12 100644 --- a/Yavsc.Server/Models/HairCut/HairCutQueryEvent.cs +++ b/Yavsc.Server/Models/HairCut/HairCutQueryEvent.cs @@ -16,8 +16,7 @@ namespace Yavsc.Models.Haircut public string CreateBoby() { - return string.Format(ResourcesHelpers.DefaultResourceManager - .GetString("RdvToPerf"), Client.UserName, + return string.Format(ResourcesHelpers.GlobalLocalizer["RdvToPerf"], Client.UserName, EventDate?.ToString("dddd dd/MM/yyyy à HH:mm"), Location.Address, ActivityCode); diff --git a/Yavsc.Server/Models/Messaging/RdvQueryEvent.cs b/Yavsc.Server/Models/Messaging/RdvQueryEvent.cs index d2f40488..02d59187 100644 --- a/Yavsc.Server/Models/Messaging/RdvQueryEvent.cs +++ b/Yavsc.Server/Models/Messaging/RdvQueryEvent.cs @@ -50,7 +50,7 @@ using Interfaces.Workflow; public string CreateBody() { return string.Format( - ResourcesHelpers.DefaultResourceManager.GetString("RdvToPerf"), + ResourcesHelpers.GlobalLocalizer["RdvToPerf"], Client.UserName, EventDate?.ToString("dddd dd/MM/yyyy à HH:mm"), Location.Address, diff --git a/Yavsc.Server/ViewModels/Account/RegisterViewModel.cs b/Yavsc.Server/ViewModels/Account/RegisterViewModel.cs index aa378c54..a8063b94 100644 --- a/Yavsc.Server/ViewModels/Account/RegisterViewModel.cs +++ b/Yavsc.Server/ViewModels/Account/RegisterViewModel.cs @@ -8,9 +8,9 @@ namespace Yavsc.ViewModels.Account // ErrorMessage = "", - [Display(ResourceType = typeof(Yavsc.Resources.YavscLocalisation), Name = "UserName")] + [Display(ResourceType = typeof(RegisterViewModel), Name = "UserName")] [StringLength(102)] - [YaRegularExpression(@"[a-zA-Z0-9 .'_-]+", ErrorMessageResourceName="InvalidUserName", ErrorMessageResourceType = typeof(Yavsc.Resources.YavscLocalisation))] + [YaRegularExpression(@"[a-zA-Z0-9 .'_-]+", ErrorMessageResourceName="InvalidUserName", ErrorMessageResourceType = typeof(RegisterViewModel))] public string UserName { get; set; } [YaRequired()] @@ -23,12 +23,12 @@ namespace Yavsc.ViewModels.Account // ErrorMessage = "Les mots de passe doivent contenir au moins un caractère spécial, qui ne soit ni une lettre ni un chiffre.")] - [Display(ResourceType = typeof(Yavsc.Resources.YavscLocalisation), Name = "Password")] + [Display(ResourceType = typeof(RegisterViewModel), Name = "Password")] public string Password { get; set; } [DataType(DataType.Password)] - [Display(ResourceType = typeof(Yavsc.Resources.YavscLocalisation), Name = "PasswordConfirm")] - [Compare("Password", ErrorMessageResourceName = "PassAndConfirmDontMach", ErrorMessageResourceType = typeof(Yavsc.Resources.YavscLocalisation) )] + [Display(ResourceType = typeof(RegisterViewModel), Name = "PasswordConfirm")] + [Compare("Password", ErrorMessageResourceName = "PassAndConfirmDontMach", ErrorMessageResourceType = typeof(RegisterViewModel) )] public string ConfirmPassword { get; set; } public string GoogleRegId { get; set; } diff --git a/Yavsc.Server/project.json b/Yavsc.Server/project.json index 378c783f..d736a520 100644 --- a/Yavsc.Server/project.json +++ b/Yavsc.Server/project.json @@ -37,7 +37,7 @@ "contrib" ] }, - "embed": [ + "copyToOutput": [ "Resources/**/*.resx" ] }, @@ -77,4 +77,4 @@ } } } -} +} \ No newline at end of file diff --git a/Yavsc/Helpers/EventHelpers.cs b/Yavsc/Helpers/EventHelpers.cs index 46fd37e1..96f8277c 100644 --- a/Yavsc/Helpers/EventHelpers.cs +++ b/Yavsc/Helpers/EventHelpers.cs @@ -42,7 +42,7 @@ namespace Yavsc.Helpers string strprestation = query.GetDescription(); var yaev = query.CreateEvent("NewHairCutQuery", - string.Format(Startup.GlobalLocalizer["HairCutQueryValidation"],query.Client.UserName), + string.Format(ResourcesHelpers.GlobalLocalizer["HairCutQueryValidation"],query.Client.UserName), $"{query.Client.Id}"); diff --git a/Yavsc.Server/Resources/Yavsc.Controllers.AnnouncesController.resx b/Yavsc/Resources/Yavsc.Controllers.AnnouncesController.resx similarity index 100% rename from Yavsc.Server/Resources/Yavsc.Controllers.AnnouncesController.resx rename to Yavsc/Resources/Yavsc.Controllers.AnnouncesController.resx diff --git a/Yavsc.Server/Resources/Yavsc.Models.Billing.NominativeServiceCommand.resx b/Yavsc/Resources/Yavsc.Models.Billing.NominativeServiceCommand.resx similarity index 100% rename from Yavsc.Server/Resources/Yavsc.Models.Billing.NominativeServiceCommand.resx rename to Yavsc/Resources/Yavsc.Models.Billing.NominativeServiceCommand.resx diff --git a/Yavsc.Server/Resources/Yavsc.Resources.YavscLocalisation.en.resx b/Yavsc/Resources/Yavsc.Resources.YavscLocalisation.en.resx similarity index 100% rename from Yavsc.Server/Resources/Yavsc.Resources.YavscLocalisation.en.resx rename to Yavsc/Resources/Yavsc.Resources.YavscLocalisation.en.resx diff --git a/Yavsc.Server/Resources/Yavsc.Resources.YavscLocalisation.fr.resx b/Yavsc/Resources/Yavsc.Resources.YavscLocalisation.fr.resx similarity index 100% rename from Yavsc.Server/Resources/Yavsc.Resources.YavscLocalisation.fr.resx rename to Yavsc/Resources/Yavsc.Resources.YavscLocalisation.fr.resx diff --git a/Yavsc.Server/Resources/Yavsc.ViewComponents.CommentViewComponent.en.resx b/Yavsc/Resources/Yavsc.ViewComponents.CommentViewComponent.en.resx similarity index 100% rename from Yavsc.Server/Resources/Yavsc.ViewComponents.CommentViewComponent.en.resx rename to Yavsc/Resources/Yavsc.ViewComponents.CommentViewComponent.en.resx diff --git a/Yavsc.Server/Resources/Yavsc.ViewComponents.CommentViewComponent.fr.resx b/Yavsc/Resources/Yavsc.ViewComponents.CommentViewComponent.fr.resx similarity index 100% rename from Yavsc.Server/Resources/Yavsc.ViewComponents.CommentViewComponent.fr.resx rename to Yavsc/Resources/Yavsc.ViewComponents.CommentViewComponent.fr.resx diff --git a/Yavsc.Server/Resources/Yavsc.ViewComponents.CommentViewComponent.resx b/Yavsc/Resources/Yavsc.ViewComponents.CommentViewComponent.resx similarity index 100% rename from Yavsc.Server/Resources/Yavsc.ViewComponents.CommentViewComponent.resx rename to Yavsc/Resources/Yavsc.ViewComponents.CommentViewComponent.resx diff --git a/Yavsc.Server/Resources/Yavsc.ViewComponents.TaggerViewComponent.en.resx b/Yavsc/Resources/Yavsc.ViewComponents.TaggerViewComponent.en.resx similarity index 100% rename from Yavsc.Server/Resources/Yavsc.ViewComponents.TaggerViewComponent.en.resx rename to Yavsc/Resources/Yavsc.ViewComponents.TaggerViewComponent.en.resx diff --git a/Yavsc.Server/Resources/Yavsc.ViewComponents.TaggerViewComponent.fr.resx b/Yavsc/Resources/Yavsc.ViewComponents.TaggerViewComponent.fr.resx similarity index 100% rename from Yavsc.Server/Resources/Yavsc.ViewComponents.TaggerViewComponent.fr.resx rename to Yavsc/Resources/Yavsc.ViewComponents.TaggerViewComponent.fr.resx diff --git a/Yavsc.Server/Resources/Yavsc.ViewComponents.TaggerViewComponent.resx b/Yavsc/Resources/Yavsc.ViewComponents.TaggerViewComponent.resx similarity index 100% rename from Yavsc.Server/Resources/Yavsc.ViewComponents.TaggerViewComponent.resx rename to Yavsc/Resources/Yavsc.ViewComponents.TaggerViewComponent.resx diff --git a/Yavsc.Server/Resources/YavscLocalisation.cs b/Yavsc/Resources/YavscLocalisation.cs similarity index 100% rename from Yavsc.Server/Resources/YavscLocalisation.cs rename to Yavsc/Resources/YavscLocalisation.cs diff --git a/Yavsc/Startup/Startup.cs b/Yavsc/Startup/Startup.cs index b5d4fb35..3e81b4f6 100755 --- a/Yavsc/Startup/Startup.cs +++ b/Yavsc/Startup/Startup.cs @@ -50,6 +50,7 @@ namespace Yavsc public static PayPalSettings PayPalSettings { get; private set; } private static ILogger logger; + public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv) { var devtag = env.IsDevelopment()?"D":""; @@ -256,9 +257,6 @@ namespace Yavsc CheckServices(services); } - - public static IStringLocalizer GlobalLocalizer { get; private set; } - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, IOptions siteSettings, @@ -271,7 +269,7 @@ namespace Yavsc ILoggerFactory loggerFactory) { GoogleSettings = googleSettings.Value; - GlobalLocalizer = localizer; + ResourcesHelpers.GlobalLocalizer = localizer; SiteSetup = siteSettings.Value; Authority = siteSettings.Value.Authority; var blogsDir = siteSettings.Value.UserFiles.Blog;