views:

37

answers:

1
<?php
$pageurl = "http://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
$pageurl_noslashes = str_replace("/","",$pageurl);
$lang = substr($pageurl_noslashes,-3);
echo $lang;
?>
{exp:channel:entries channel="products" limit="10"}
<p>Product title: <span>{if title<?php echo $lang; ?>} {title<?php echo $lang; ?>} {if:else} {title} {/if}</span></p>
{/exp:channel:entries}

I am hacking expression engine to return the appropriate language variables.

I am aware that the way I am getting the language code (fr/en/etc...) is far from ideal, which is why I need advice on it :)

What happens:

  • host.com/products/item/_fr/ — loads French
  • host.com/products/item/_en/ — loads English
  • host.com/products/item/ — loads English (after failing the if condition)

So in essence, it does exactly what I want, however I feel that it is not the best way to do it.

A: 

You should be able to get it from the http headers sent by the users browser...

echo $_SERVER["HTTP_ACCEPT_LANGUAGE"];

It explains how here

Mark
Appreciate the response, however I do not care what language their browser is set to. I start caring about their language preference, after they have selected a language from the drop-down that the site will provide. The issue is reading this language selection from the url (as apposed to retrieving it from a cookie or a session).
daulex
I guess you mean $_GET['field name here']The field name of the language combobox
Mark
$_GET would require a get-powered form and would do a trick on seo. I'm getting the lang attribute in there via simple anchors.
daulex