Welcome Guest, Not a member yet? Register   Sign In
How to make a multi country web site? (Best practices)
#1

[eluser]Nonox[/eluser]
Hi.
I have to make a website that supports various content depending the visitor country. At the moment I have wrote the script for ip-to-country and lang detection.
But I have a doubt, Which is the best practices for this type of website?
Divide the structure in different directories for each country? and repeat all the programmings site countless times?
Note that the design and functionality are the same for all countries, just change some images, text and some link.
My intention is to make the user feel comfortable with the site and be able to use certain terms for each country.

Thanks a lot for any advice!
Nonox
#2

[eluser]JoostV[/eluser]
One way is to set the language in the session. Then you can act on that info, by setting different images, loading a different langauge class, restricting data from teh database to a certain language, and even setting different ways to displayes dates and so on.

If you already have a language detection class, you write a library that:
-checks to see if that language is available
-if it is, set that language in session
-if it is not, set a default language in session , e.g. English

You can then also add language buttons to your site that enable the visitor to choose a different language.
#3

[eluser]simonmaddox[/eluser]
[quote author="Nonox" date="1231289711"]Hi.
I have to make a website that supports various content depending the visitor country. At the moment I have wrote the script for ip-to-country and lang detection.
But I have a doubt, Which is the best practices for this type of website?
Divide the structure in different directories for each country? and repeat all the programmings site countless times?
Note that the design and functionality are the same for all countries, just change some images, text and some link.
My intention is to make the user feel comfortable with the site and be able to use certain terms for each country.

Thanks a lot for any advice!
Nonox[/quote]

For loading different languages of your site, have a look here:
http://ellislab.com/codeigniter/user-gui...guage.html

Make sure that, when you automatically detect the visitor's country and language, that you provide them with a simple way of changing it.

If I'm in Italy, I'll get the site in Italian. I don't have any idea how to speak Italian, so I won't want to go hunting through the site to try and change the language back to English.

For example, Amazon provides links to their other international websites in the footer of every page.
#4

[eluser]Phil Sturgeon[/eluser]
Have just finished a hook that does exactly this.

2x CI config variables.
- Supported languages = array('EN' => English, 'FR' => French, etc)
- Default language = 'EN'

1x Hook entry in config/hooks.php

Code:
$hook['pre_controller'] = array(
'function' => 'PickLanguage',
'filename' => 'pick_language.php',
'filepath' => 'hooks',
);

1x Hook file

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

session_start();

function PickLanguage() {
    require_once(APPPATH.'/config/languages.php');
      
    // Lang set in URL via ?lang=something
    if(!empty($_GET['lang']))
    {
        // Uppercase and only 2 characters long
        $lang = strtoupper(substr($_GET['lang'], 0, 2));
        $_SESSION['lang_code'] = $lang;
    }
    
    // Lang has already been set and is stored in a session
    elseif( !empty($_SESSION['lang_code']) )
    {
        $lang = $_SESSION['lang_code'];
    }
    
    // Still no Lang. Lets try some browser detection then
    else
    {
        $accept_langs = $this->obj->input->server('HTTP_ACCEPT_LANGUAGE');
        
        if (!empty( $accept_langs ))
        {
            // explode languages into array
            $accept_langs = explode(',', $accept_langs);
        
            log_message('debug', 'Checking browser languages: '.implode(', ', $accept_langs));
            
            // Check them all, until we find a match
            foreach ($accept_langs as $lang)
            {
                // Turn en-gb into EN
                $lang = strtoupper(substr($lang, 0, 2));
                
                // Check its in the array. If so, break the loop, we have one!
                if(in_array($lang, array_keys($config['supported_languages'])))
                {
                    break;
                }
            }
        }

        // Still not found a lang, lets just use the default
        if(empty($lang))
        {
            $lang = $config['default_language'];
        }
        
        // Whatever we decided the lang was, save it for next time to avoid working it out again
        $_SESSION['lang_code'] = $lang;
    }
    
    // Check the provided lang is available
    if(!in_array($lang, array_keys($config['supported_languages'])))
    {
        exit('This language doesnt exist boso!');
    }

    // Load CI config class
    $CI_config =& load_class('Config');

    // Set the language config. Getting 'English' from the array by calling it from its key of 'EN', and make it lowercase so CI looks for 'english'
    $CI_config->set_item('language', $config['supported_languages'][$lang]);

    // Sets a constant to use throughout ALL of CI.
    define('DEFAULT_LANGUAGE', $lang);
}

?>

Then, you can use DEFAULT_LANGUAGE in all your models and everywhere else in CI to reference your lang specific data. Works beautifully!

Edit - 07/01/09: Added in browser detection support.
#5

[eluser]xwero[/eluser]
pyromaniac you hook is based on a query string url, $_GET['lang'], and as the GET global is cleaned by CI you should add an $_SERVER['INFO_PATH'] and related checks to make the hook work with non query string urls.

Nonox like simonmaddox mentioned, it's not because the ip located in some country the language of the country should be the default. I think you better get the user_agent preferred language first and use the country language as a secondary default.
I'm from Belgium and we have three official languages, how would you solve a case like that based on country ip?
#6

[eluser]Nonox[/eluser]
First of all, THANKS everybody for your answer!

But my problem is not with the language, I have resolved it with a solution based in this:
Quote:http://roland.blochberger.us/index.php/p...ang_select

The ip-to-country was resolved based in this:
Quote:http://v3.thewatchmakerproject.com/journ...-and-mysql
(Recommended by Derek Allard in his web page http://www.derekallard.com/blog/category...ionengine/)

Even more, I resolve the timezone issue based in this:
Quote:http://www.desisofts.com/white-papers/ti...lculation/

My doubt is because I want to make the user feel comfortable with the site and be able to use certain terms for each country.

I have to divide the structure in different directories for each country? and repeat all the programmings site countless times?

My questions are based in this article:
Quote:http://codeigniter.com/wiki/Multiple_Sit...CI_system/

Again thanks.
Nonox
#7

[eluser]xwero[/eluser]
[quote author="Nonox" date="1231351860"]
I have to divide the structure in different directories for each country? and repeat all the programmings site countless times?[/quote]

Simple answer no. This is when the only thing that changes are the strings and some odd layout elements.
If you are talking about different data and totally different layouts than you should consider programming the common elements as modules and put country specific parts in separate directories.

But as i understand you are not planning to have many differences between the countries.
#8

[eluser]Nonox[/eluser]
[quote author="xwero" date="1231354132"][quote author="Nonox" date="1231351860"]
I have to divide the structure in different directories for each country? and repeat all the programmings site countless times?[/quote]

Simple answer no. This is when the only thing that changes are the strings and some odd layout elements.
If you are talking about different data and totally different layouts than you should consider programming the common elements as modules and put country specific parts in separate directories.

But as i understand you are not planning to have many differences between the countries.[/quote]

I have been thinking in detect the country by IP, keep the country code in a variable and put it into a function, who show this "alternative" piece of the page depending that variable. What do you think?
#9

[eluser]Phil Sturgeon[/eluser]
I'm using on purpose, so I can have links on the top of the site with ?lang=DE which would automatically switch the page they are on. Could be done using a controller and a redirect to the previous page or something, but this way seemed easy enough.

Also trying to handle as much of this before we have much of CI set, so if I set this in a controller I would have to have this session stuff in several files instead of one. IP based is another good idea, but lots of extra work. >.<


Btw, if you are using sub-domains, they don't have to be real sub-domains. Just setting some virtual ones would do the trick, then you can dynamically load the language in your config file or elsewhere based on the $_SERVER['SERVER_NAME'];
#10

[eluser]Nonox[/eluser]
Ok, thanks people, I'm thinking the best way to solve my issue.




Theme © iAndrew 2016 - Forum software by © MyBB