By joel_guesclin on
I have found that:
$user->language;
returns the language of the currently logged on user, but returns nothing when the user is 'anonymous'.
I'm trying to find some straightforward, simple way of determining what the default site language is (ie the language for 'anonymous'), whether or not the localisation module is switched on. For example, I rather hoped there might be a "$site-language" but there isn't.
Can anyone help me?
And if there is no simple way, then can I use the "locale_supported_languages" function even if localisation is not switched on?
Comments
Have a look at your database
You could look in your database in the "locales_meta" table. There is a field called "isdefault" which I suppose is the one that you're looking for. If you need a variable with the default language, you might try something like this:
I'm not sure, whether this was what you were looking for, neither am I very good at MySQL statements, so there may very well be errors in that code.
But I hope, it helps you a little :)
I would prefer something more "standard"
Thanks for the help - however, I was trying to avoid doing anything that doesn't go through the API.
I did come across this:
which uses the API and retrieves the default language into $ulang. It just so happens that the function returns an array with the default as the first value, so this actually works. But I would much rather have some kind of standard thing like "$site->language" if such existed.
Something more "standard"
All right, now I understand your question better... I happen to run into this problem quite often myself: "Is there a standard function/variable available or do I have to create it myself?" Under pressure I often choose the easier path to just call an SQL-statement, even if it is not the smartest thing to do and I think your method leads to slightly more reliable scripts :)
If anyone here could point us to good resources about where to find infos about available variables etc. I'd be very glad to hear them, too! (I know drupaldocs.org, but there's not everything there I'm looking for.)