开发者

Drupal: how to set theme language programmatically?

开发者 https://www.devze.com 2022-12-19 23:13 出处:网络
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.)

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 La开发者_JAVA百科nguage Drupal Module


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.


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.


In Drupal 7, paste the following into template.php:

//Get the list of languages
$languages = language_list();

//Overwrite the global language object
global $language;
$language = $languages['en'];

More info here

0

精彩评论

暂无评论...
验证码 换一张
取 消