在Codeigniter中添加语言的URI段 [英] Add URI Segment for Language in Codeigniter

查看:105
本文介绍了在Codeigniter中添加语言的URI段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站;我需要开发支持多种语言,例如en,tr,ar,sp等。

I have a site; I need to develop to support multiple languages, for example en, tr, ar, sp, etc.

但是问题是,什么是最好的处理方法Codeigniter?

But the problem is , what is the best way to do it with Codeigniter?

我有一个控制器(SITE)。我有很多功能,例如(hotel,city,page,blog)

I have a controller ( SITE ). I have a lot of functions LIKE ( hotel , city , page , blog )

我想在此方法之前添加一个细分(语言)。这是旧链接

I want to before this method add a segment ( language ). This is old links

http://example.com/hotel/mariot
http://example.com/hotel/hilton
http://example.com/city/london
http://example.com/city/paris
...
..

我希望链接像这样

http://example.com/en/hotel/mariot
http://example.com/ar/hotel/mariot
http://example.com/sp/hotel/mariot
http://example.com/tr/hotel/mariot
http://example.com/en/city/london
http://example.com/ar/city/paris
....
..

有时认为每种语言都有控制器,但有可能...

sometimes thinking every language have a controller but it is possible...

更改所有链接以支持语言的最佳方法是什么?

What is the best way to change all links to support the languages?

很抱歉,如果我的问题不清楚,这是我的英语。

I'm sorry If my question is not clear, this is my English.

推荐答案

如果您希望您的链接像这样
http://example.com/en/something

if you want your links to be like this http://example.com/en/something

然后,您可能需要在项目中拥有名为en的子域或文件夹。

then you might need to have subdomain or folder in your project called en. but yet this is not the perfect solution.

您要做的就是将文本输出分配到变量中,这些变量从xml文件中获取值。例如,如果您有一些名为您的房间号为:0的文本,并且此值是硬编码的HTML,则应将其放在en.xml文件中的某个标签下,并从用户根据以下要求所请求的xml文件中获取它所需的语言。

what you have to do is to make your text output assigned into variables which takes their values from an xml file. like if you have some text called "your room number is: 0" and this value is hard coded HTML then you should put it in en.xml file under some tag and get it from the xml file which is requested by the user according to the required lang.

您可以使用所有语言进行以前的解决方案,但是您必须考虑阿拉伯语是RTL语言,因此请在您的CSS中考虑。但是通常您可以使用xml文件来控制语言。

you might can do the previous solution in all languages but you have to consider that Arabic language is RTL language so just consider that in your css. But generally you can use xml files to control the languages.

希望这就是您所需要的。

hope that is what you needed.

这篇关于在Codeigniter中添加语言的URI段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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