Welcome Guest, Not a member yet? Register   Sign In
Multilanguage site with different root domains
#1

[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?
#2

[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.
#3

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




Theme © iAndrew 2016 - Forum software by © MyBB