NejCommon.NET/Models/LocalizedString.cs
2025-12-03 11:57:50 +01:00

28 lines
847 B
C#

using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace NejCommon.Models;
[Owned]
public class LocalizedString
{
[Column(TypeName = "jsonb")]
public Dictionary<Langauge, string> Values { get; set; } = new();
public string this[Langauge locale]
{
get => Values.TryGetValue(locale, out var v) ? v : "";
set => Values[locale] = value;
}
public static implicit operator LocalizedString(string value)
=> new() { Values = new() { [Langauge.EN] = value } };
public static implicit operator LocalizedString(Dictionary<Langauge, string> value)
=> new() { Values = value };
public static implicit operator Dictionary<Langauge, string>(LocalizedString value)
=> value.Values;
}