Add URI Segment for Language in Codeigniter

喜你入骨 提交于 2019-12-10 11:05:42

问题


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

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

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

and I want the links to be like this

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.


回答1:


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

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

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.

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.




回答2:


The right way, is using routes.php look for it inside (application/config/routes.php)

You can use regex expressions for your specific problem.

here is the manual: http://ellislab.com/codeigniter/user-guide/general/routing.html



来源:https://stackoverflow.com/questions/14091171/add-uri-segment-for-language-in-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!