Problem/Motivation

"As a russian site visitor, i want to see at least an english content version if no russion is present" is an example use case of the core language fallback system, for which Language Hierarchy is a GUI.

As a site builder i want to create a content view that leverages this fallback system, showing e.g. a russian node if available, english if not.

Proposed resolution

No idea if this should be done on indexing or on query.

Comments

axel.rutz created an issue. See original summary.

geek-merlin’s picture

mkalkbrenner’s picture

Interesing idea. But I wonder if the implementation should really depend on the language_hierarchy module. There's no activity for more than a year.

BTW we already have soemething in place for locales: "de-AT" falls back to "de".

geek-merlin’s picture

> But I wonder if the implementation should really depend on the language_hierarchy module.

Hi Markus, that's a misunderstanding. In fact

> of the core language fallback system,

this is the core hook

> for which Language Hierarchy is a GUI.

and this is just an example for convenience how to play with it.

geek-merlin’s picture

Title: Support language_hierarchy » Use core's language fallback system
mkalkbrenner’s picture

Do you know of any integration with Views using such language fallbacks?

Anyway, we can add something to our module.

Can you describe some concrete examples as a guideline for implementing it?

neoxavier’s picture

just an idea, we have similar use case in our solution. We did the fallback check on query.

mkalkbrenner’s picture

Version: 8.x-2.x-dev » 8.x-3.x-dev
Component: Multilingual Backend » Code
mkalkbrenner’s picture

Project: Search API Solr » Search API
Version: 8.x-3.x-dev » 8.x-1.x-dev
Component: Code » General code

I think that this should be solved by Search API itself and not the backend.
The simple approach would be to contain the targeted AND the fallback language in the Search API Query. The fallback language(s) should be added automatically if requested.

drunken monkey’s picture

In what way would that be different from #1960684: Allow filtering by "Language (with fallback)" or the (WIP) patch proposed there?
(Having this processor directly in Search API instead of the CLIR module would of course be an option either way.)

geek-merlin’s picture

Hussa!

entity_language_fallback contains a processor that does the work on indexing. I like that approach as it allows fallback sequences that vary by entity.
https://cgit.drupalcode.org/entity_language_fallback/tree/src/Plugin/sea...

What i did not grok instantly is why they need a different datasource:
https://cgit.drupalcode.org/entity_language_fallback/tree/src/Plugin/sea...

EDIT: From readme:

USAGE WITH SEARCH API
-------------
This module contains 2 Search API components:
processor (https://www.drupal.org/docs/8/modules/search-api/getting-started/processors) and datasource (https://www.drupal.org/docs/8/modules/search-api/developer-documentation/providing-a-new-datasource-plugin)
Using datasource is preferred way, since it will correctly report number of items to index. Use processor only if you cannot change datasource setting.
drunken monkey’s picture

Great to hear, thanks for sharing!
Maybe ping them about adding the “Search API” ecosystem to the project description so it will be listed in our ecosystem.

geek-merlin’s picture

Hmm, i'd also like to explore where this should be going. While the processor works (i tested it), my gut feeling is that this should some day live in search_api's entity processor. What do you mean? See links to the source above.

drunken monkey’s picture

Hm, not sure whether that’s the best approach. If I understand this correctly (didn’t try it out) this will, e.g., when indexing an English node also index a copy of that node as French if there is no French translation (depending on the fallback settings, of course)?
Then apart from bloating the index unnecessarily, it also seems this would mean that Solr would try to do French text preprocessing on the English text content of that node on indexing, right? Needless to say, this wouldn’t work properly.
I also don’t see a big market for varying fallback sequences by entity, but even so, it seems that could equally well be accomplished by switching the current missing_translations property for a fallback_for_languages property that will be filtered for as a fallback for search_api_language at search time (please shout if I’m not making any sense here). However, while this would be more flexible, the downside would be that you’d then have to search all languages at search time and just let that filter do the filtering – decreasing performance, as long as there’s more than a couple of languages.

All in all, I still think our approach in the CLIR issue is the better one. People who want the other one can just use the entity_language_fallback module right now, nothing preventing you from doing that. (You can probably just search/replace the datasource ID in the exported index config and re-import, that should give you the exact same index just with the added language fallback functionality.)

geek-merlin’s picture

OK thanks for thinking about this. No objections to proceed like this.

geek-merlin’s picture

Status: Active » Closed (duplicate)