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

Feature request: LocalizeAlways #5

Open
MrRosendahl opened this issue Apr 25, 2019 · 6 comments
Open

Feature request: LocalizeAlways #5

MrRosendahl opened this issue Apr 25, 2019 · 6 comments

Comments

@MrRosendahl
Copy link

Hi, I must say great localization feature and very easy to use!

Would it be possible to Always force localization, and not just when selecting specific members?
For example when returning a mapped dto using Automapper the translations aren't included since the mapping isn't forcing selections.

@popcatalin81
Copy link
Member

popcatalin81 commented Apr 25, 2019

Hmm ... I will need to look at what AutoMapper does and figure out what needs to be done for localization to work.

You are using Querialbe extensions of AutoMapper right? http://docs.automapper.org/en/stable/Queryable-Extensions.html

@itisbugra
Copy link

itisbugra commented Mar 11, 2020

Do you have any plans to make this thing work? I'm actually trying to find the related implementation on the source code, if I could, I will try to implement it.

@popcatalin81
Copy link
Member

popcatalin81 commented Mar 11, 2020

@Chatatata what thing? It works fine when using http://docs.automapper.org/en/stable/Queryable-Extensions.html

@popcatalin81
Copy link
Member

@Chatatata Oh, I see. If I understood correctly, is whether the feature to localize without projections will be added.
No. There's no plan for that.

@itisbugra
Copy link

@popcatalin81 Could you show me the related code segment for that issue? I see https://github.com/iQuarc/DataLocalization/blob/master/src/iQuarc.DataLocalization/Data/LocalizationExpressionVisitor.cs#L32 is not getting called when there is no projection on the query.

@popcatalin81
Copy link
Member

popcatalin81 commented Mar 11, 2020

@Chatatata When there's no projection, it's really hard to determine what Visit method will be called. There are multiple choices, this is 1st problem,
Ex, all the following are posibilities:

var p1 = db.Products.AsEnumerable();
var p2 = db.Categories.Where(c => c.Name == "Food").SelctMany(c => c.Products).Distinct();
var p3 = db.Products.OrderBy(x => x.Name).Skip(10).Take(1);
var p4 = db.Products.GroupBy(p => p.Category.Name).ToList();

And there are more ... all these methods will create a different query tree, and withouth having a specific place to intercept, localization becomes very very hard.

The 2nd problem is that translation can't be made to work for Include() statements.

Edit: You could conceivably insert a Projection forcefully in the Query something like:

var p4 = db.Products.GroupBy(p => p.Category.Name).ToList();
// becomes

var p4 = db.Products.Select( p => new Product
{
       Id = p.Id,
       Name = p.ProductLoalizations.Where(pl => pl.ProductId = p.Id && pl.Language.Code ="{IsoCode}").Select(pl =>pl.Name).FirstOrDefault() ?? p.Name,
       CategoryId = p.CategoryId
})
.GroupBy(p => p.Category.Name).ToList();

For this you use VisitMember, and when the member is an DbSet<> you insert an projection from TEntity to TEntity. This could work, but still, includes will not work.

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

No branches or pull requests

3 participants