I am currently working on a project .Net Core that has data stored in DB (SQL) that needs to be translated for the client.
To give a simple example I have the following table of products and i want to translate the column "description":
Product table with columns to be translated:
To get the data in the service, I use Automapper and I thought in a solution like this, but is not posible to use IMemberValueResolver with Iqueryables.
CreateMap<Product, ProductDto>()
.ForMember(dest => dest.Description, opt => opt.ResolveUsing<TranslateResolver, string>(src => src.Description));
public class TranslateResolver : IMemberValueResolver<object, object, string, string> {
private readonly IStringLocalizer<TranslateResolver> _localizer;
public TranslateResolver(IStringLocalizer<TranslateResolver> localizer)
{
_localizer = localizer;
}
public string Resolve(object source, object destination, string sourceMember, string destMember,
ResolutionContext context)
{
**// Logic to find the translation in a json file or table from database with the translations.**
return translation;
}
}
question from:
https://stackoverflow.com/questions/65853954/localization-solution-with-resource-data-in-database 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…