Orchard Localization and query with current culture filter does not return items with no translation

Topics: Administration, General, Localization
Jan 28, 2015 at 9:31 AM
I'm using orchard cms and I use localization part for my content types like news , product and ...

I also use ForCurrentCulture filter in queries to prepare cultured specific items for projection widgets and it works fine.

But the problem is that when I create a new item from a content type like news, after publishing it; the query doesn't return it until I click New Translation and save for one another language.

This bug occurs because the first created item does not belong to any language but this is not good. I think there should be a default culture for localization added content types.

Please guide me

Thank you
Developer
Jan 29, 2015 at 11:58 PM
What branch are you using? are you on 1.x?

The default culture for all content items should be the site culture - are you not seeing that?
Jan 31, 2015 at 6:32 AM
Thanks Jetski5822
I'm using 1.8.1
Yes the bug exist. Query does not return any record because the record doesn't belong to any culture.
If I add any translated version for the item , the query works and return correct items even if I remove or unpublish the new translated version immediately.
Also if I remove the "For Current Culture" filter from the query , it returns the item.
Feb 1, 2015 at 5:13 AM
Edited Feb 1, 2015 at 5:16 AM
Tried on a quite recent 1.8.x version (not the 1.8.1)

I have the same symptoms for items already created when I first add the LocalizationPart to the content type (all CultureId = 0). In fact, the item.LocalizationPart.Culture = null, but the corresponding row in the LocalizationPartRecord exists with CultureId = 0

Then, with the 1.8.x version (not tested with 1.8.1), when I create a new item, all previous items with no culture are assigned to the site culture, but not for the last created item (if I don't use New Translation)

See this discussion: https://orchard.codeplex.com/discussions/573398

Here, one workaroud with a projection filter is to replace in CurrentCultureFilter.cs this
context.Query = query.Where(x => x.ContentPartRecord<LocalizationPartRecord>(),
    x => x.Eq("CultureId", currentCultureId));
With
context.Query = query.Where(x => x.ContentPartRecord<LocalizationPartRecord>(),
    x => x.Or(a => a.Eq("CultureId", 0), b => b.Eq("CultureId", currentCultureId)));
Regards
Marked as answer by popcom on 1/31/2015 at 10:00 PM
Feb 1, 2015 at 6:00 AM
Thank you very much jtkech

I tried your solution on v.1.8.1 and the bug is fixed.

Best Regards
Marked as answer by popcom on 1/31/2015 at 10:01 PM
Developer
Feb 18, 2015 at 4:59 PM
Its interesting that the culture of the content would be null, I guess that would happen if you enable the Localization Module after you create that content.

I have pushed a change to the 1.x branch that allows you to assign a culture to a piece of content that has no culture - however that still only partly fixes your problem.

I am wondering if in the CurrentCultureFilter we provide the option to include Orphaned Culture Items, as the fix applied above will include then regardless of culture which is not really the end goal.

What do you think?