0

For a custom module, I need to change the language of the registration form based on the subdomain the user is currently active on.

I tried changing the global $language variable in hook_form_user_register_form_alter, but that does not work ($language variable is also not set at that point). I also tried setting the language in the $user object, but also no dice (probably because it is an anonymous user).

Finally I took a look at the language negotiation api, but setting up negotiation providers seems overkill for this (and haven't it studied enough to get a grasp on how to use it).

I just need to render the registration page in a different (but already available) language on /user/register, based on the subdomain. What would be the best way to achieve this.

I'm using Drupal 7.

3 Answers 3

1

Maybe you can use the Domain Locale module. It allows you to change the available and default languages per domain.

1
  • This pointed me in the right direction. I didn't really want to add another module for this and it seems they might override the user selected language (text is not very clear), but I took a look at their code which showed my how to do it.
    – Whiskey
    Commented Jan 20, 2014 at 9:03
1

I may not be understanding the question, but if you go here:

/admin/config/regional/language/configure

You can set how languages are set (Determine the language from the URL (Path prefix or domain).

Domains can be configured here: /admin/config/regional/language/edit/

1
  • Good point! Totally forgot to check that. But it appears you can only define one domain per language and I need to specify more.
    – Whiskey
    Commented Jan 17, 2014 at 15:30
1

Based on how it's done in the Domain Locale module (thanks Matt for pointing it out), I am now using this in hook_init:

if (strpos($cp, 'user/register') === 0 || strpos($cp, 'user/password') === 0 || strpos($cp, 'user/reset') === 0) {
    global $language;
    $lang = my_get_language_function();
    $languages = language_list();
    if (!empty($lang) && isset($languages[$lang]))
        $language = $languages[$lang];
    return;
}
1
  • Glad I could help! A little +1 on my answer would be appreciated though :)
    – Matt
    Commented Jan 20, 2014 at 10:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.