开发者

Last 2 letters of the uri defining the used language

<?php
$pageurl = "http://".$_SERVER["SERVER_NAME"].开发者_StackOverflow社区$_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.


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜