A site I’m currently working on currently uses an approach for language fallback that is so hackish, it’s crossed the line twice and is actually rather interesting.
First, if it detects that it might need to do something, it takes control of the page delivery callback and invokes its own.
It figures out the corresponding alias for the “parent” node (the node the user would see if they went to the same alias in a language that had a source or translation there). From there, it can load the parent node.
And long story short, it then uses hook_page_build() to intercept page rendering and add the actual rendered node to the $page render array. It also hacks it up in other ways…rendering blocks, etc.
This is obviously not the optimal solution. We find ourselves having to implement many things twice because the system doesn’t have the same context as us about what we’re doing.
Recently, I’ve thought of a potentially better solution, which is using hook_inbound_url_alter() to do essentially the same sort of alias checking. This is the approach I took in https://drupal.org/project/i18n_404.
So basically I’d swap out the underlying node in a similar way but still show the same alias. I’m not sure if the language context would be properly preserved like that, but it seems easier to deal with than what I have now.
So my main question is: Is there a module for this? Or at least something I could base off? I have a number of regression tests in our custom module now, and we are planning a refactor. I want to make it count.
Generic replies OK — I am expecting to need some custom code regardless. We handle some edge cases that I don’t think a module would, like if you have a View at /frontpage and a node at /frontpage/some-node. If you go to the latter on an untranslated language domain, it would normally show you /frontpage. We intercept that and still show the node.
There’s also a “you are not being shown the language you went to” popup, but that part doesn’t really need refactoring.