Posted by pol on September 17, 2011 at 7:11am
Hi all,
I'm looking to get feedback on a module I made for Drupal 6.
It allows you to create a custom landing page if no language is found from url.
I know Drupal has mechanisms to automatically detect language, but one of my client absolutely need that Language Selection Page, so I made a configurable module so it can be helpful for other people too.
The module will save the language prefix in a cookie and use it if not found also.
You can configure the module through a setting page, as seen in the attached screenshot.
Let me know what you think !
The module: http://drupal.org/sandbox/Pol/1191004
The full project apply issue: http://drupal.org/node/1273954
Thanks.
| Attachment | Size |
|---|---|
| snapshot8.png | 52.09 KB |

Comments
Drupal 7 applicability
What do you think about the pluggable language selector in Drupal 7? Do you think any of this would not be possible there? Any improvements you think would be great to see in core for Drupal 8?
Hi Gabor, The module is for
Hi Gabor,
The module is for D6 for the moment and as I'm not aware (yet) about a lot of stuff in D7, I still need to study how it works in D7.
I'm planning to do that in one or two month. That's why I never heard about the pluggable language selector.
Right now, I'm trying to simplify my module as much as I can and remove all bugs, I think I'm at 99% of completion since yesterday evening.
I'll keep you updated.
-Pol-
Hi Pol, The module looks like
Hi Pol,
The module looks like a good starting point.
Looking into the code, the main issue is using numbered options as opposed to defined constants, which makes the code very difficult to understand.
The cookie option may make sense as a stand alone module, and also the 'enable/disable' option may not be really needed, as you can do the same by enabling/disabling the module itself.
But definitely, you should see D7 language negotiation settings before working more on this, because I am sure you'll be able to get some ideas from it, like having a list of language selection methods and assigning priorities for each, which would simplify the UI a great deal.
Hello Jose, I just pushed the
Hello Jose,
I just pushed the 7.x branch of my module.
It took me a bit of time because D7 coding stuff is brand new and it's a monster... but I love it, possibilities are endless, at least, we can do much more than in D6 and it's great.
For this version, I've learned to use
hook_language_negotiation_info()to declare a new language provider and have the 'Selection Page' listed in the detection method.The problem using that method is that the callback of that provider is not returning anything as the others, that's why I used the url callback from locale. (
locale_language_from_url()).During my research, I also needed to identify which provider provided the language to Drupal, for this, I made this patch for D8 and D7.
Thanks to this patch, in the
hook_init(), I can identify which provider is returning the language.If the provider is
LOCALE_LANGUAGE_NEGOTIATION_URL_FALLBACK, I redirect the user request (and all it's GET arguments) to thelanguage_selectionpage.It still needs a lot of work, but I wanted to post this first version to know if I'm in the right direction.
There is another solution to the problem, using
hook_language_negotiation_info_alter()and alter the language detection by URL provider, I don't know which one is better, we can do the same using both code.For the cookie part in D7, I still need to look for that because it seems that there is already a couple of module providing the same functionality.
-Pol-
Maybe you just need to
Maybe you just need to provide a language negotiation method and add it before the url fallback, so all you need to do is a redirect (and maybe redirect back after language is selected).
Any documentation available
Any documentation available for the pluggable language selector? I've seen references to it, but other than by reading the PHP, don't know how to find out what it's for and how to use it.
Talking about futures, D8 should respect language preference order from browser settings, not just the first language. Maybe additional options for language preferences (multiple languages in order of preference) in account options too, but that would only be important when users are not using their own machine.
This is just my personal preferences, but as an example: I can read Spanish quite well but prefer English (in fact, given a choice, I prefer British English.) So, my browser is configured to accept languages en-GB, en and es in that order. If I'm reading Spanish content on a site then I want the site interface to stay in English, and if the content is available in English as well as Spanish I would like the site to automatically offer that option.
Currently part of the team at https://lastcallmedia.com in a senior Drupal specialist role.
pluggable language selector
Well, the pluggable language selector is all hooks, so its documented in the code:
For improvements on the built-in language negotiation handler and more test coverage, http://drupal.org/node/221712 is a great issue to look at. Testing feedback is more than welcome! For advanced language selection like selecting both English and Spanish if you prefer both, that is indeed some development required to plug that information in your views providing the listings for example. Drupal currently selects one language and attempts to use that proper per language type (content, ui, url).
Thanks Gábor - I don't mind
Thanks Gábor - I don't mind reading code :)
When considering needs, I think it's important to recognise the difference between complete and partial multi-language sites. By complete I mean a site where all content is available in all relevant languages - deciding what content to serve is relatively simple. Existing (D6 and D7) functionality is adequate in that case - whatever language a site visitor wants will be available for both content and site interface. There is the case that a user may want the site interface in German even though content is only available in English and French, but that's still relatively simple to handle.
With a partial multi-language site, things get more complex. This is the area I'm interested in improving. You may know I have a module MultiLink - it offers redirection to the "best-fit" url given any combination of user language preferences and available node translations. So now I want to look at extending that idea to hook into core content-selection instead of doing a redirect. The final objective - that a user will always see the "best" combination of content and interface based on their preferred language(s).
So, I will study the language selector hooks - it seems that would be the best way to meet my objective.
Currently part of the team at https://lastcallmedia.com in a senior Drupal specialist role.
sorry, how can i try this
sorry, how can i try this module?