Language related question |
[eluser]Tsu88[/eluser]
Hello! I am new to codeigniter (using it for less than a month and already have two project to make) and new to using framework for doing job done. I learned about MVC quite quickly and I like CI a lot. So here is my situation: I am making a school project - renewal of laboratory site - and it has to be in our native language (slovenian) and in english. I read about language classes and all but I don't get one thing. Let's say I have a table called News and there are usual fields, where I have two fields for content: content_sl and content_en. In my view file I would like to display content of content_sl if user defines his language as Slovenian and vice versa. So I would create set of controllers for english and another one for slovenian interface? I don't know the right approach, because I never worked on multilanguage page before. Could I just create unique controller that would have a variable that defines language? Therfore when visitor selects english, query would be sent to controller saying I want english and controller would look in a database and get values for english ... ? I am sorry if all together sounds a little bit confusing, but take in consideration that I am new with all this framework work. I would be really happy if one could direct me in right direction, I will do my work (teaching and reading) I just need a hint ![]() ADDED: I forgot to add that i would like my URL to look like www.example.com/en/something and www.example.com/sl/something ... So when user selects his language that en or sl would always be before all other functions. Thanks in advance, Matic
[eluser]Dam1an[/eluser]
To acheive the URL structure you want, your best bet is URI routing, so you'd have the example you gave map to the 'something' controller. To then get the language code, you could use Code: $this->uri->segment(1); You will probably also then use the corresponding language table for dynamic stuff like news
[eluser]Tsu88[/eluser]
So i have a function let's say news and variable for language. example.com/en/news I make case sentence in controller to do some language specific work. But how do I do this, that before every link there would be /en/ or /sl/. And when one clicks on a language flag, that all links change to another /en/ or /sl/. I am reading internationalization thread ATM, but i don't know how to dinamicaly build those links that have the first segment a language value. You know what I mean? Thanks for help
[eluser]Dam1an[/eluser]
Well, you will always have the current language code, so unless they click a linkt o change the language, just get the first URI segment, and stick it at the front of the anchor function You could extend the URL helper to automate this so you wouldn't have to worry about adding it manually for each link
[eluser]Tsu88[/eluser]
Just a thought here ... I am looking at this $config['url_suffix'] = ""; setting Am I able to change this on a fly? So the logic would be i have default suffix .sl and when I would click english flag it would change to .en. I would only have to check .something to choose the right function in controller. Is this posible? Thanks for reply in advance
[eluser]Klaatush[/eluser]
I am also facing the same situation, actually a little more worse We have currently 3 languages ENG/DUT/FRE (English, Dutch, French). Any of the language can be set to default and saved in DB. for the default language we don't need the lang parameter but the rest will show with the lang in URI. Structure of URI is http://domain.com/[lang/]controller/function/parameters... so for example if eng is default lang of site, page will be http://domain.com/news/show/1 but if the user selects DUT as language, the page URI will become http://domain.com/dut/news/show/1 if you find the solution of your problem, kindly post here, so with the help of that solution, I can solve my problem. Thanks in advance.
[eluser]sl3dg3hamm3r[/eluser]
I personally don't like the method of adding the language to the URI. I store the language in a session-var and wrote a small helper which let me read and set the language. As for the DB, if you have for example two columns representing two languages, lets say 'description_de' and 'description_en', you could form your query like that: Code: $lang = hlp_getLanguage(); //Helper, which would return either 'de' or 'en' This would keep your model and controller language-independent.
[eluser]Klaatush[/eluser]
@sl3dg3hamm3r The idea of keeping the language information in session was rejects, because we need the search engines to read and index each language page. If we have same page link but different contents (in terms of language) on the page, the search engines will only index one page with maybe the default language or some other.
|
Welcome Guest, Not a member yet? Register Sign In |