Files
mixtape/zero.Core/Localization/TranslationStore.cs
T

31 lines
734 B
C#
Raw Normal View History

2021-11-24 13:56:08 +01:00
using FluentValidation;
namespace zero.Localization;
2021-11-26 12:31:33 +01:00
public class TranslationStore : EntityStore<Translation>, ITranslationStore
2021-11-24 13:56:08 +01:00
{
2021-11-26 12:31:33 +01:00
public TranslationStore(IStoreContext context) : base(context) { }
2021-11-24 13:56:08 +01:00
/// <inheritdoc />
public async Task<string> LoadString(string id)
{
return (await Load(id))?.Value;
}
protected override void ValidationRules(ZeroValidator<Translation> validator)
{
2021-12-01 14:26:54 +01:00
validator.RuleFor(x => x.Key).NotEmpty().Length(2, 300).Unique(Context.Store);
2021-11-24 13:56:08 +01:00
validator.RuleFor(x => x.Value).MaximumLength(10 * 1000);
}
}
2021-11-26 12:31:33 +01:00
public interface ITranslationStore : IEntityStore<Translation>
2021-11-24 13:56:08 +01:00
{
/// <summary>
/// Get a translated string by id
/// </summary>
Task<string> LoadString(string id);
}