Welcome Guest, Not a member yet? Register   Sign In
multi-language site organization
#1

[eluser]Mit[/eluser]
In advance: I'm sorry if my question happens to be too lame.

I consider using CI for a site with 3 or more languages (all the site's parts will be the same, I'll just use language file).

I have thougnt of a few options to organize the site, but the one that really stuck in my mind is using something like this:

http://mysite.com/en/class/function/ where en would be one of those: en, de, ru . This would give the best perma-links .

so I guess I want to run some code to include the language files before the code continues to the classes and in the sametime rerout to them.

PLS help me with this scenario.

And I will be happy to hear how you would organize such site
#2

[eluser]beseku[/eluser]
Hey Mit ...

Our whitelabel CMS is entirely language independant - it takes a lot of work and quite a bit of extension of CI to prevent hair pulling. The stuff we did that would be of help to you is ...

1) Create a function, (mine is in the extended config library and called in the controller constructor) that looks for a language change in the URI then the session. If this is found, it updates the session and sets the CI default language accordingly.

Code:
function get_langs() {
    $CI =& get_instance();
    
    $default_language = $this->item('language');
    $languages = $this->item('languages');
    
    preg_match('/\?language=(' . implode('|', $languages) . ')$/', $_SERVER['REQUEST_URI'], $get);
    
    if (count($get) == 2) {
    
        $default_language = $get[1];
        $get = array();
        
    } elseif (in_array($CI->session->userdata('gcms_language'), $languages)) {
        $default_language = $CI->session->userdata('gcms_language');
    }
    
    $this->set_item('language', $default_language);
    $this->set_item('languages', $languages);
    $CI->session->set_userdata(array('gcms_language' => $default_language));
}

2) Extend the language loader class to look for a language then fall back to a default, (in this case 'english', because I am) - It means your site won't break if lang files are missing ...

3) I then use mod_rewrite to map /en/news/2007 to /news/2007/?language=en, just to make things a bit simpler in CI.
#3

[eluser]Mit[/eluser]
10x a lot, that just what I needed. I didn't thought of making it GET query with mod_rewrite.


It'll make mine life easyer if u tell me the code for the rewrite thing. I have some experience with it, but I find it hard to debug.
#4

[eluser]sikkle[/eluser]
yeah, you could just also give a look into the wiki, for languague url :

http://codeigniter.com/wiki/URI_Language_Identifier/

good luck !
#5

[eluser]Mit[/eluser]
[quote author="sikkle" date="1214941980"]yeah, you could just also give a look into the wiki, for languague url :

http://codeigniter.com/wiki/URI_Language_Identifier/

good luck ![/quote]

that's even better, i will use it...
I just opened the mod_rewrite manual when u posted. You saved me. Smile
#6

[eluser]sikkle[/eluser]
Yea, save me hells of a time realy. i even make small donation for his job realy well done.

see ya around.
#7

[eluser]Nima A.[/eluser]
[quote author="beseku" date="1214939260"]... that looks for a language change in the URI then the session. If this is found, it updates the session and sets the CI default language accordingly....

[/quote]

sorry dude, but can you tell me why did you use SESSIONS for lanugage management ? , I think, query string can do this, but if you want more, cookies can be useful,
consider a situation which 100000 people are visiting your website, then ,what do you think about the cost that you'll pay on the server for using sessions ?
#8

[eluser]sikkle[/eluser]
magpie : this is what i suggest with http://codeigniter.com/wiki/URI_Language_Identifier/

see ya around.
#9

[eluser]beseku[/eluser]
[quote author="Magpie" date="1214957749"]sorry dude, but can you tell me why did you use SESSIONS for lanugage management ? , I think, query string can do this, but if you want more, cookies can be useful,
consider a situation which 100000 people are visiting your website, then ,what do you think about the cost that you'll pay on the server for using sessions ?[/quote]

To clarify, a CI session is generated for every visitor anyway, so adding a variable to hit means the performance is negligable. And CI handles session data much more neatly than cookies.

[quote author="Magpie" date="1214957749"]consider a situation which 100000 people are visiting your website[/quote]

I don't know how much hyperbole was involved in this statement, but the system held up fine for the BRIT awards during a heavy voting period, and for the 46664 site during the 90th birthday gig on Friday! Both clocked up more than 100K hits in an hour
#10

[eluser]Nima A.[/eluser]
Quote:A CI session is generated for every visitor anyway,

are you sure about that ? well, I'm a bit newbie in CI and thus I'm not familiar with the inner structure of the CodeIgniter, but I don't think it's (creating session for each user) necessary; so my question is this : "what's the reason to create a session for every visitor in the core of CI ?" ;
anyhow, I performed a search on the CI's core code for the keyword $_SESSION , and just found it on a function called " _sanitize_globals " (to unset register globals !!!), so don't think CI act so, but anyway, If CI create one, please let me know ,

Quote:I don’t know how much hyperbole was involved in this statement, but the system held up fine for the BRIT awards during a heavy voting period, and for the 46664 site during the 90th birthday gig on Friday! Both clocked up more than 100K hits in an hour

sorry buddy, it was just a mistake ! just pressed it one more accidentally ! , but what I meant is not the statistics, but the cost that you and your shared server will pay inorder to use sessions for a task that does not need it. as far as I know, yahoo use cookies even for it's autentication (I just heard it, I don't know it's true or not), and the reason is , session can make a huge load on the server (such as many other web-based systems)




Theme © iAndrew 2016 - Forum software by © MyBB