Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By rvk on
Hi there,
Surely this has been done before, but I cannot find an example. The documentation doesn't seem to have the answer. Anyway I'd like to retrieve 'global variables' (not sure if that's proper lingo) such as the currently used interface language. I thought that simply using $language would do the trick, but it doesn't. I do know how to use php in a node. Would anyone know the proper PHP code to get the current interface language?
or how about the username?
Thanks for any pointers (also pointers to documentation of course).
RvK
Comments
i18n_get_lang()
$language = i18n_get_lang;
Hiveminds Magazine | FireOrb | Drupal Street | Drupal offline manual
That results in an error
That results in an error (and without the "()" it results in $language being a string):
Fatal error: Call to undefined function i18n_get_lang() in
/public_html/includes/common.inc(1537) : eval()'d code on line 2
I did activate the locale module in my Drupal 6 installation.
oops!
Sorry, I thought you were using drupal 5 and the internationalization module. In Drupal 6 without the internationalization module try this function. Just set in the property you want like language_default('language').
Though this is core code it is stuppid and ugly. I have no idea why they chose to cast the out put into an object and allow the return of only one property. It would have been better to leave the array alone and allow you the grab all the properties at once then choose them by key.
Choose the method you think will suit you over time.
Hiveminds Magazine | FireOrb | Drupal Street | Drupal offline manual
re: Stupid & ugly
You remark regarding language_default (reproduced below):
By simply reading the code:
$language and $language_default are — unsurprisingly — similar objects. The array is just used as an easy / elegant object notation for the variable_get 'default' argument. First building an object on stdclass, then using it as the second argument to variable_get is much messier.
Also, if you do not pass any argument to language_default, $property will be NULL. This causes
return $property ? $language->$property : $language;
to return the entire object, not just a property.--
The Manual | Troubleshooting FAQ | Tips for posting | How to report a security issue.
Globals
Drupal 6 globals are documented on http://api.drupal.org/api/globals/6
This gives you the current interface locale, not the default.
See also http://www.php.net/global about variable scope, the global keyword and the $GLOBALS superglobal.
--
The Manual | Troubleshooting FAQ | Tips for posting | How to report a security issue.
Thanks Hiveminds and Heine
Thanks Hiveminds and Heine for your tips!
I'll have to improve my knowledge on php a bit to use all of them, but I'm able to do what I wanted now. So my problem is solved: great!
Thanks!