uri的后2个字母定义了所使用的语言 [英] Last 2 letters of the uri defining the used language

查看:66
本文介绍了uri的后2个字母定义了所使用的语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<?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.

我知道我获取语言代码(fr/en/etc ...)的方法远非理想,这就是为什么我需要对此提出建议的原因:)

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 :)

会发生什么:

  • host.com/products/item/_fr/—加载法语
  • host.com/products/item/_en/—加载英语
  • host.com/products/item/-加载英语(如果if条件失败)

因此,从本质上讲,它确实可以实现我想要的功能,但是我觉得这不是最好的方法.

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

推荐答案

您应该能够从用户浏览器发送的http标头中获取它...

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

echo $_SERVER["HTTP_ACCEPT_LANGUAGE"];

它说明了此处

这篇关于uri的后2个字母定义了所使用的语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆