H
what is the best way to execute some PHP commands when user swicth website to another language?
D7 have some hooks concerning language but there is no hook for switching the language.

I can change language switcher links in that way that I add some URL parameter to them. Then I can test in hook_init() whether some language switcher link was clicked.

Is there any simplier solution?

Comments

jaypan’s picture

You can always store the current language in a $_SESSION variable, and if you load the page and the language is different from the previous one, execute your code.

Contact me to contract me for D7 -> D10/11 migrations.

Web Assistant’s picture

You can use the variable $language, for example:

<?php
global $language;
if ($language->name != 'English') {
  ..
}
?>

The language information for each user is already stored here, so might as well make use of it. More info here.

tomas.teicher’s picture

thanks for the tips
I will test language change using session (using global $language)
thanks
Tomas