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
This commit is contained in:
Paul Schneider 2019-06-16 13:10:14 +01:00
commit 9501ee1f16
13 changed files with 342 additions and 44 deletions

View file

@ -1,27 +0,0 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Yavsc.Attributes.Validation;
using Yavsc.Models.IT.Evolution;
namespace Yavsc.Models.IT.Fixing
{
public class Bug
{
[Key,DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long Id { get; set; }
[ForeignKey("FeatureId")]
public virtual Feature False { get; set; }
public long? FeatureId { get; set; }
[YaStringLength(240, ErrorMessageResourceType=typeof(BugResources), ErrorMessageResourceName="TitleTooLong")]
public string Title { get; set; }
[YaStringLength(4096)]
public string Description { get; set; }
public BugStatus Status { get; set; }
}
}

View file

@ -1,17 +0,0 @@
namespace Yavsc.Models.IT.Fixing
{
/// <summary>
/// Bug status:
/// * Inserted -> Confirmed|FeatureRequest|Feature|Rejected
/// * Confirmed -> Fixed
/// * FeatureRequest -> Implemented
/// </summary>
public enum BugStatus : int
{
Inserted,
Confirmed,
Rejected,
Feature,
Fixed
}
}

View file

@ -1,35 +0,0 @@
// ------------------------------------------------------------------------------
// <autogenerated>
// 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.
// </autogenerated>
// ------------------------------------------------------------------------------
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<IServiceScopeFactory>().CreateScope();
var stringLocFactory = scope.ServiceProvider.GetService<IStringLocalizerFactory>();
_localizer = stringLocFactory.Create(typeof(BugResources));
return _localizer;
}
}
public static string TitleTooLong {
get {
return Localizer["TitleTooLong"];
}
}
}
}

View file

@ -61,5 +61,7 @@
<!--
route name for the api controller used to tag the 'BlogPost' entity
-->
<data name="TitleTooLong"><value>Le titre est trop long</value></data>
<data name="TitleTooLong"><value>Le titre est trop court ou trop long ({MaxLen} au maximum, {ecart} en trop))</value></data>
<data name="TooLong"><value>Le titre est trop court ou trop long ({MaxLen} au maximum, {ecart} en trop))</value></data>
<data name="TooShort"><value>Le titre est trop court ({MinLen} au minimum, {ecart} manquant)</value></data>
</root>

View file

@ -61,5 +61,6 @@
<!--
route name for the api controller used to tag the 'BlogPost' entity
-->
<data name="TitleTooLong"><value>Le titre est trop long</value></data>
<data name="TooLong"><value>Too Long ({MaxLen} at maximum, {ecart} in excess))</value></data>
<data name="TitleTooLong"><value>Too Short ({MinLen} at minus, {ecart} missing)</value></data>
</root>