Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing multi-lingual entities #11698

Open
ebicoglu opened this issue Feb 24, 2022 · 4 comments
Open

Implementing multi-lingual entities #11698

ebicoglu opened this issue Feb 24, 2022 · 4 comments
Milestone

Comments

@ebicoglu
Copy link
Member

We have started to implement this feature in the past, but it was canceled due to some design problems.
This issue is for getting ideas from the community and tracking the progress of the this feature.
The previous related conversation is at #1754

This feature exists in ASP.NET Boilerplate and if you don't want to wait and implement it on your own, check out the ASP.NET Boilerplate implementation

@ebicoglu ebicoglu added this to the backlog milestone Feb 24, 2022
@rashedjawda
Copy link

Thank you, that's good news.
We already implement it in our solutions the same way implemented in aspnetboilerplate, I hope the migration go smoth :)

@julian-forster
Copy link

@ebicoglu can you please explain the key design problems, so that we can give you feedback and maybe some ideas for possible solutions?

@angel-sotabytes
Copy link

Any new about the progress? I want to buy the abp commercial but this feature is a must for my purpose.

@ahmednfwela
Copy link
Contributor

I have done some progress on this in these 2 PRs

#13384
#14837

and according to this test, there is no need to use sync over async at all!

public async Task TestBulkMapping()
{
using (CultureHelper.Use("en-us"))
{
var translations = await _multiLingualObjectManager.GetBulkTranslationsAsync<MultiLingualBook, MultiLingualBookTranslation>(_books);
var translationsDict = translations.ToDictionary(x => x.entity.Id, x => x.translation);
var mapped = _mapperAccessor.Mapper.Map<List<MultiLingualBook>, List<MultiLingualBookDto>>(_books, options =>
{
options.Items.Add(nameof(MultiLingualBookTranslation), translationsDict);
});
Assert.Equal(mapped.Count, _books.Count);
for (int i = 0; i < mapped.Count; i++)
{
var og = _books[i];
var m = mapped[i];
Assert.Equal(og.Translations.FirstOrDefault(x => x.Language == "en")?.Name, m.Name);
}
}
}

and this is the mapping profile that makes this possible:

public class MultiLingualObjectTestProfile : Profile
{
public MultiLingualObjectTestProfile()
{
CreateMap<MultiLingualBook, MultiLingualBookDto>()
.ForMember(x => x.Name,
x => x.MapFrom((src, target, member, context) =>
{
if (context.Items.TryGetValue(nameof(MultiLingualBookTranslation), out var translationsRaw) && translationsRaw is IReadOnlyDictionary<Guid, MultiLingualBookTranslation> translations)
{
return translations.GetValueOrDefault(src.Id)?.Name;
}
return null;
}));
}
}

it uses automapper's ability to pass parameters during the mapping process, see official docs

It would be easier if Abp had this by default, so that we don't have to go through automapper #14834
but it was discarded as an unnecessary feature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants