By ptmkenny on
How can I allow users to set their language upon registration? I know that by using the language switcher block, they can change the language of the site, but I would like to have a button on the form that clearly allows the user to select their language.
I found the thread below, but the code offered is for Drupal 6, and I don't know how to update it to Drupal 7:
http://drupal.org/node/773500
Does anyone know of a way to do this in Drupal 7?
Comments
User registration language custom code
This can be set by the admin when creating a user, but not by the user when registering (which seems strange to me).
One solution is posted here but I didn't try it out:
http://stackoverflow.com/questions/5556895/how-to-add-language-switcher-...
The code is for Drupal 6 but you can use the Coder module to convert it from Drupal 6 to Drupal 7.
[update] Ah, I am now seeing that you already linked to a post that linked to the article above... so... you can try converting it with Coder or maybe someone else has an idea. I really find it odd that this is not solved.
Kristen
-Kristen
Profile: https://www.linkedin.com/in/kristenpol
Drupal 7 Multilingual Sites: http://kristen.org/book
Thanks for your reply. I was
Thanks for your reply. I was unable to update it with the coder module, as user_hook(), which the linked code relies on, is deprecated in D7 and I can't figure out how it's supposed to be now.
In the meantime, I have arrived at a "sort-of" solution by displaying an i18n block above the form for each language that says "You are completing this form in English (Spanish, etc.) To use the site in another language, first change the language using the links to the left before proceeding with registration."
Ugly but it works...
Code to do this
With some help from the fine folks at Drupal answers, here's the code to do this:
Place inside a custom module:
Code work
This code really worked i am too facing the same problem. But not getting any solution lastly i got it. It your hard work but it help many of us.
Offshore software product development
This works out of the box,
This works out of the box, autoselects current language and provides list of system available languages:
How to use with LoginToboggan
Which code to use? This one or the first one? What's the difference?
Both don't work if used with the LoginToboggan module (for user login and registration on the same page).
Does anyone know how to use this in conjunction with this module? (https://drupal.org/project/logintoboggan)
Thanks!
Missing closing brace
Closing brace before function MYMODULE was missing in the first code..
just change #access value
I needed this lately and saw that when you hook to user_register_form, the form item is actually there. The only thing you have to do is change its #access value, which is set to false by default.