I found locale_language_from_url() needs a work-around. This was with Drupal 7.8, but presumably true of other D7 versions. The following code works for me:
// Due to an apparent bug somewhere in Drupal language processing,
// locale_language_from_url() doesn't work because it expects $_GET['q'] to
// include the language prefix, but the prefix has already been removed.
// As a work-around, temporarily set $_GET['q'] to request_path().
// This works because request_path() statically caches the original value.
$languages = language_list();
$saveq = $_GET['q'];
$_GET['q'] = request_path();
$url_language_id = locale_language_from_url($languages);
$_GET['q'] = $saveq;
I know that the same language value can normally be accessed via the global $language object, but in my case I needed to detect language from url during bootstrap, when $language is not initialised.
It also seems that this is probably only an issue when serving cached pages:
bootstrap.inc #2218:
// Restore the metadata cached with the page.
$_GET['q'] = $cache->data['path'];
So, this seems like a bug. Should I make a patch for locale.inc so that locale_language_from_url() uses request_path() ? Or is the underlying issue that the page $cache->data['path'] should really hold the original path with prefix?
Comments
Comment #1
dddave CreditAttribution: dddave commentedChanging the version to see if someone in the know cares...