Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drupal: how to set theme language programmatically?

How can i change drupal default language programmatically somewhere in code (like template.php)? (i need to overwrite default language set by admin in some cases.) i'm using drupal 6.

PS: please read my own answer for more detail. and if you may help solve that

PS: later i saw a module that was what i wanted. make sure take a look at it:

Administration Language Drupal Module

like image 992
Alexar Avatar asked Jul 03 '26 11:07

Alexar


2 Answers

The global $language determines the language. So if you change it you'll change the language. But that will be a language switch and not just for a page. It might be possible to switch back and forth. Haven't experimented with it though.

like image 125
googletorp Avatar answered Jul 05 '26 06:07

googletorp


PS at last I did it in template.php like this:

// get the list of availabel languages
$langs = language_list();
// now switch global $language back to 'en'
$vars['language'] = $langs['en'];

it solved some problems but there are still some problems alive. because of i am doing this in theme function, before the code some modules have used drupal defined language and it rises some problems like css directions and so.

If anyone has a better solution to do the code above somewhere perior to template.php i will thank.

like image 40
Alexar Avatar answered Jul 05 '26 08:07

Alexar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!