CodeIgniter Forums
Multilanguage site with different root domains - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Multilanguage site with different root domains (/thread-40410.html)



Multilanguage site with different root domains - El Forum - 04-07-2011

[eluser]Joa[/eluser]
Hi. I'm quite new to CI wonder if anyone can help me with this:

I'm building a site with three languages: english, finnish, swedish. Since we have three different domain names for the language setting I would like to use

domain.com -> english version
domain.fi -> finnish version
domain.se -> swedish version

Hence the preferred method by using uri segment 1 like the "/en/controller/method/argument" approach won't work.

The site suppose to be database driven for contents so I like to set a global variable ($lang) to use for getting the correct language specific fields from the database (ie "title_en", "title_fi" etcetera).

I wonder where to start looking for a solution. Would it be a .htaccess rewrite or a routing thing? Any suggestions?


Multilanguage site with different root domains - El Forum - 04-07-2011

[eluser]wh1tel1te[/eluser]
I do this sort of thing to switch between desktop and mobile versions of my sites.

Put in your index.php:

Code:
<?php
switch($_SERVER['HTTP_HOST'])
{
    case 'domain.com':
    case 'www.domain.com':
        // Either
        define('LANG', 'en');
        // Or
        $GLOBALS['lang'] = 'en';
    break;
    
    case 'domain.fi':
    case 'www.domain.fi':
        // Either
        define('LANG', 'fi');
        // Or
        $GLOBALS['lang'] = 'fi';
    break;
    
    case 'domain.sw':
    case 'www.domain.sw':
        // Either
        define('LANG', 'sw');
        // Or
        $GLOBALS['lang'] = 'sw';
    break;
}
?>

Then you have access to either LANG constant or $GLOBALS['lang'] variable.


Multilanguage site with different root domains - El Forum - 04-07-2011

[eluser]Joa[/eluser]
YESS! Just what I needed, easy as that! Thanks a lot!