From fb35d9b772d79c46dd5313c3ece4410dae05762b Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sun, 16 Jun 2019 13:10:14 +0100 Subject: [PATCH] Localize using strongly typed resources: generated Class with strotygen -p -t Yavsc.Models.IT.Fixing.Bug.resx must be modified : * prefix with 'Yavsc.Server.Resources.' the baseName in call to new System.Resources.ResourceManager * remove the internal ctor additionally, the generated class must be or unique or partial --- .../Attributes/Validation/YaStringLength.cs | 1 - .../Models/IT}/Fixing/Bug.cs | 6 +- .../Models/IT}/Fixing/BugStatus.cs | 0 src/Yavsc.Server/Resources/Bug.Designer.cs | 53 +++++++++++++++ .../Yavsc.Models.IT.Fixing.Bug.en.resx | 62 +++++++++++++++++ .../Yavsc.Models.IT.Fixing.Bug.fr.resx | 65 ++++++++++++++++++ .../Resources/Yavsc.Models.IT.Fixing.Bug.resx | 62 +++++++++++++++++ src/Yavsc/Resources/BugResources.Designer.cs | 35 ---------- ...avsc.Models.IT.Fixing.BugResources.fr.resx | 4 +- .../Yavsc.Models.IT.Fixing.BugResources.resx | 3 +- .../{YavscMandatory.cs => BatchTests.cs} | 6 +- src/test/Mandatory/Resources.cs | 23 +++++++ src/test/Resources/Test.TestResources.resx | 66 +++++++++++++++++++ 13 files changed, 342 insertions(+), 44 deletions(-) rename src/{Yavsc/Models => Yavsc.Server/Models/IT}/Fixing/Bug.cs (76%) rename src/{Yavsc/Models => Yavsc.Server/Models/IT}/Fixing/BugStatus.cs (100%) create mode 100644 src/Yavsc.Server/Resources/Bug.Designer.cs create mode 100644 src/Yavsc.Server/Resources/Yavsc.Models.IT.Fixing.Bug.en.resx create mode 100644 src/Yavsc.Server/Resources/Yavsc.Models.IT.Fixing.Bug.fr.resx create mode 100644 src/Yavsc.Server/Resources/Yavsc.Models.IT.Fixing.Bug.resx delete mode 100644 src/Yavsc/Resources/BugResources.Designer.cs rename src/test/Mandatory/{YavscMandatory.cs => BatchTests.cs} (97%) mode change 100755 => 100644 create mode 100644 src/test/Mandatory/Resources.cs create mode 100644 src/test/Resources/Test.TestResources.resx diff --git a/src/Yavsc.Abstract/Attributes/Validation/YaStringLength.cs b/src/Yavsc.Abstract/Attributes/Validation/YaStringLength.cs index c8e5c6c8..2a80c4e1 100644 --- a/src/Yavsc.Abstract/Attributes/Validation/YaStringLength.cs +++ b/src/Yavsc.Abstract/Attributes/Validation/YaStringLength.cs @@ -21,7 +21,6 @@ namespace Yavsc.Attributes.Validation if (value == null) { return false; } - Console.WriteLine("Validating string length for "+value.ToString()); string stringValue = value as string; if (stringValue==null) return false; diff --git a/src/Yavsc/Models/Fixing/Bug.cs b/src/Yavsc.Server/Models/IT/Fixing/Bug.cs similarity index 76% rename from src/Yavsc/Models/Fixing/Bug.cs rename to src/Yavsc.Server/Models/IT/Fixing/Bug.cs index 0dbf573c..94dd4902 100644 --- a/src/Yavsc/Models/Fixing/Bug.cs +++ b/src/Yavsc.Server/Models/IT/Fixing/Bug.cs @@ -5,7 +5,7 @@ using Yavsc.Models.IT.Evolution; namespace Yavsc.Models.IT.Fixing { - public class Bug + public partial class Bug { [Key,DatabaseGenerated(DatabaseGeneratedOption.Identity)] public long Id { get; set; } @@ -15,10 +15,10 @@ namespace Yavsc.Models.IT.Fixing public long? FeatureId { get; set; } - [YaStringLength(240, ErrorMessageResourceType=typeof(BugResources), ErrorMessageResourceName="TitleTooLong")] + [StringLength(240, ErrorMessageResourceType=typeof(Yavsc.Models.IT.Fixing.Bug), ErrorMessageResourceName="TitleTooLong")] public string Title { get; set; } - [YaStringLength(4096)] + [StringLength(4096)] public string Description { get; set; } public BugStatus Status { get; set; } diff --git a/src/Yavsc/Models/Fixing/BugStatus.cs b/src/Yavsc.Server/Models/IT/Fixing/BugStatus.cs similarity index 100% rename from src/Yavsc/Models/Fixing/BugStatus.cs rename to src/Yavsc.Server/Models/IT/Fixing/BugStatus.cs diff --git a/src/Yavsc.Server/Resources/Bug.Designer.cs b/src/Yavsc.Server/Resources/Bug.Designer.cs new file mode 100644 index 00000000..5a2771a8 --- /dev/null +++ b/src/Yavsc.Server/Resources/Bug.Designer.cs @@ -0,0 +1,53 @@ +// ------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Mono Runtime Version: 4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// ------------------------------------------------------------------------------ + +namespace Yavsc.Models.IT.Fixing { + using System; + using System.Reflection; + + + [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [System.Diagnostics.DebuggerNonUserCodeAttribute()] + [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + public partial class Bug { + + private static System.Resources.ResourceManager resourceMan; + + private static System.Globalization.CultureInfo resourceCulture; + + + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + public static System.Resources.ResourceManager ResourceManager { + get { + if (object.Equals(null, resourceMan)) { + System.Resources.ResourceManager temp = new System.Resources.ResourceManager("Yavsc.Server.Resources.Yavsc.Models.IT.Fixing.Bug", typeof(Bug).GetTypeInfo().Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + public static System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + public static string TitleTooLong { + get { + return ResourceManager.GetString("TitleTooLong", resourceCulture); + } + } + } +} diff --git a/src/Yavsc.Server/Resources/Yavsc.Models.IT.Fixing.Bug.en.resx b/src/Yavsc.Server/Resources/Yavsc.Models.IT.Fixing.Bug.en.resx new file mode 100644 index 00000000..e6f65108 --- /dev/null +++ b/src/Yavsc.Server/Resources/Yavsc.Models.IT.Fixing.Bug.en.resx @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + The title is too long + \ No newline at end of file diff --git a/src/Yavsc.Server/Resources/Yavsc.Models.IT.Fixing.Bug.fr.resx b/src/Yavsc.Server/Resources/Yavsc.Models.IT.Fixing.Bug.fr.resx new file mode 100644 index 00000000..3297698d --- /dev/null +++ b/src/Yavsc.Server/Resources/Yavsc.Models.IT.Fixing.Bug.fr.resx @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Le titre est trop long + \ No newline at end of file diff --git a/src/Yavsc.Server/Resources/Yavsc.Models.IT.Fixing.Bug.resx b/src/Yavsc.Server/Resources/Yavsc.Models.IT.Fixing.Bug.resx new file mode 100644 index 00000000..e6f65108 --- /dev/null +++ b/src/Yavsc.Server/Resources/Yavsc.Models.IT.Fixing.Bug.resx @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + The title is too long + \ No newline at end of file diff --git a/src/Yavsc/Resources/BugResources.Designer.cs b/src/Yavsc/Resources/BugResources.Designer.cs deleted file mode 100644 index b4121614..00000000 --- a/src/Yavsc/Resources/BugResources.Designer.cs +++ /dev/null @@ -1,35 +0,0 @@ -// ------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Mono Runtime Version: 4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -// ------------------------------------------------------------------------------ - -namespace Yavsc.Models.IT.Fixing { - using System; - using System.Reflection; - using Microsoft.Extensions.DependencyInjection; - using Microsoft.Extensions.Localization; - - public class BugResources { - private static IStringLocalizer _localizer=null; - static IStringLocalizer Localizer { - get { - if (_localizer != null) return _localizer; - var scope = Startup.Services.GetRequiredService().CreateScope(); - var stringLocFactory = scope.ServiceProvider.GetService(); - _localizer = stringLocFactory.Create(typeof(BugResources)); - return _localizer; - } - } - - public static string TitleTooLong { - get { - return Localizer["TitleTooLong"]; - } - } - } -} diff --git a/src/Yavsc/Resources/Yavsc.Models.IT.Fixing.BugResources.fr.resx b/src/Yavsc/Resources/Yavsc.Models.IT.Fixing.BugResources.fr.resx index b386a5fb..1fce2126 100644 --- a/src/Yavsc/Resources/Yavsc.Models.IT.Fixing.BugResources.fr.resx +++ b/src/Yavsc/Resources/Yavsc.Models.IT.Fixing.BugResources.fr.resx @@ -61,5 +61,7 @@ - Le titre est trop long + Le titre est trop court ou trop long ({MaxLen} au maximum, {ecart} en trop)) + Le titre est trop court ou trop long ({MaxLen} au maximum, {ecart} en trop)) + Le titre est trop court ({MinLen} au minimum, {ecart} manquant) \ No newline at end of file diff --git a/src/Yavsc/Resources/Yavsc.Models.IT.Fixing.BugResources.resx b/src/Yavsc/Resources/Yavsc.Models.IT.Fixing.BugResources.resx index b386a5fb..d9dfd69b 100644 --- a/src/Yavsc/Resources/Yavsc.Models.IT.Fixing.BugResources.resx +++ b/src/Yavsc/Resources/Yavsc.Models.IT.Fixing.BugResources.resx @@ -61,5 +61,6 @@ - Le titre est trop long + Too Long ({MaxLen} at maximum, {ecart} in excess)) + Too Short ({MinLen} at minus, {ecart} missing) \ No newline at end of file diff --git a/src/test/Mandatory/YavscMandatory.cs b/src/test/Mandatory/BatchTests.cs old mode 100755 new mode 100644 similarity index 97% rename from src/test/Mandatory/YavscMandatory.cs rename to src/test/Mandatory/BatchTests.cs index 647a988c..60253bd8 --- a/src/test/Mandatory/YavscMandatory.cs +++ b/src/test/Mandatory/BatchTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder.Internal; using Microsoft.AspNet.Razor; @@ -29,13 +29,13 @@ namespace test [Collection("Yavsc mandatory success story")] [Trait("regres", "no")] - public class YavscMandatory: BaseTestContext, IClassFixture, IDisposable + public class BatchTests: BaseTestContext, IClassFixture, IDisposable { ApplicationDbContext _dbContext; ServerSideFixture _fixture; - public YavscMandatory(ITestOutputHelper output, ServerSideFixture fixture) : base (output, fixture) + public BatchTests(ITestOutputHelper output, ServerSideFixture fixture) : base (output, fixture) { _dbContext = fixture.DbContext; _fixture = fixture; diff --git a/src/test/Mandatory/Resources.cs b/src/test/Mandatory/Resources.cs new file mode 100644 index 00000000..599292d4 --- /dev/null +++ b/src/test/Mandatory/Resources.cs @@ -0,0 +1,23 @@ + +namespace test { + public class ResxResources { + const string resPath = "Resources/Test.TestResources.resx"; + + public void HaveAResxLoader() + { + System.Resources.ResourceReader loader = new System.Resources.ResourceReader(resPath); + // IDictionary + var etor = loader.GetEnumerator(); + while (etor.Current !=null) + { + byte[] data; + string stringdata; + string resName = etor.Key.ToString(); + + loader.GetResourceData(resName, out stringdata, out data); + + } + + } + } +} \ No newline at end of file diff --git a/src/test/Resources/Test.TestResources.resx b/src/test/Resources/Test.TestResources.resx new file mode 100644 index 00000000..a9e4584c --- /dev/null +++ b/src/test/Resources/Test.TestResources.resx @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Too Long ({MaxLen} at maximum, {ecart} in excess)) + Too Short ({MinLen} at minus, {ecart} missing) + \ No newline at end of file