ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

referencement, best practices for multilanguage sites

March 22, 2008 8:35am

Subscribe [3]
  • #1 / Mar 22, 2008 8:35am

    tomcode

    654 posts

    Hi,

    For a multilanguage site I want to implement an automatic language attribution in the default controller. But I wonder whether my solution using the URL helper function redirect() will not perturb Google referencing the pages. I’ve already had bad
    experiences using redirects (that was a HTML refresh, though).

    My solution

    class Front extends Controller{
    
        function index()
        {
            $langs = $this->agent->languages();
            
            // the critical part of it
            redirect($langs[0]);
        }
    }
    class En extends Controller {
    
        function _remap()
        {
            $lang = 'en';
            
            $data['menu'] = $this->_menu($lang);
            
            $this->load->view($this->html_template, $data);
        }
    }
    class Fr extends Controller {
    
        function _remap()
        {
            $lang = 'fr';
            
            $data['menu'] = $this->_menu($lang);
            
            $this->load->view($this->html_template, $data);
        }
    }

    The above gives me :
    1. no routing required
    2. I obtain short URLs http://www.site.com/fr/content, www.site.com/en/content
    3. I need the language detection only in the front controller
    4. Google has a 1:1 relation for address and content

    Do You think that my solution will work out for the referencement?
    Is there a risk that Google or any other motor will reject my site due to the redirect?
    Do You have a better solution 😉

  • #2 / Apr 01, 2008 11:24pm

    rhapdog

    10 posts

    Are you talking about Google’s translate engine?  Or Google’s search engine indexing each of the languages?  There shouldn’t be a problem with the search engine indexing.  However, if you are talking about using the translate engine, then read on.  (Your post wasn’t clear on which you were speaking of.)

    Accessing Google’s translate engine without using the script snippet they provide is actually a violation of Google’s Terms of Service, and they can blacklist your site if you are caught.  This is pretty much the case with every free translation engine out there, as I have done extensive research on this.

    Also, if your site requires the use of sessions, the sessions will be rendered useless when you call Google translate, or any other translate engine.

    I had actually come up with a workaround for that and coded it into a nice class, however, further research into the issue revealed the legal issues that were involved.  Trust me, it isn’t worth it.

    Here’s what I did, and what I recommend.  Hard code the language translations.  I set up a language file for each language I wanted the site to use.  All the views were templated with variables so that they could be replaced by the appropriate language.  If the site is using static data and is not depending on constantly changing user input that needs constant translation (like a wiki) then this is definitely the best route.  The translation sites will add between 3 and 10 seconds, sometimes more, to each page load.  Hard coding it makes it lightening fast.  Nobody likes to wait, and the wait could make people not want to visit the site.  It’s also best to use a professional translation.

  • #3 / Apr 03, 2008 3:06am

    tomcode

    654 posts

    I have all the strings of my site already translated. I am talking about Google’s search engine indexing. One of my clients had a HTML refresh installed and Google did not index it’s site, my guess because this kind of technique is also used by spam sites.

    Since my new site will completely be based onto the redirect function (every visit of the home page is redirected to one of the languages) and I want the site and it’s content to be indexed by Google & Co., I want to be sure that it’ll work.

  • #4 / Apr 03, 2008 8:00am

    rhapdog

    10 posts

    Redirects themselves are not considered by Google to be bad.  However, redirects within javascript generally are not detected by the search engine and it is best to duplicate them in a <noscript> tag. 

    If you would like more information on exactly why Google removes sites from it’s indexing, read Google’s Webmaster Guidelines at http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=35769

    You might also want to take a look at their section on redirects at http://www.google.com/support/webmasters/bin/answer.py?answer=66355

  • #5 / Jun 07, 2010 10:34pm

    sihijau

    25 posts

    my solution for multi language app are:
    - extend language helper for setting default language from config such as create function setLanguage() which is lang file as parameter.
    - create language controller to select/change language which are lang code and current URI as parameter.

    thats all.. 😊

    here are my code

    for function setLanguage in language_helper. This function always load in every controller.

    function setLanguage($lang_file='general'){
        $ci=get_instance();
        $lang_app = $ci->session->userdata('lapak_lang');
        $lang_system = $ci->config->item('language');
                
        if(!empty($lang_app) || !empty($lang_system)){
            $ci->config->set_item('language', $lang_system); 
            $ci->session->set_userdata('lapak_lang',$lang_app);
        }else{
            $ci->config->set_item('language', 'english'); 
            $ci->session->set_userdata('lapak_lang','en-US');
        }
        $ci->lang->load($lang_file, $ci->session->userdata('lapak_lang'));
    }

    example controller to select lang and redirect to current page

    <?php
    class language extends Controller {
        function __construct(){
            parent::__construct();
        }
        
        function index(){
            redirect('home');
        }
        
        function select(){
            $r = $this->uri->segment(4);
            $redirect=explode('_',$r);
            
            if(empty($r) ){
                $redirect = 'home';
            }else{
                $redirect=implode('/',$redirect);
            }
            $lang = $this->uri->segment(3);
            
            //echo $redirect;
            //exit;
            
            if($lang=='us'){ 
                $this->config->set_item('language', 'english'); 
                $this->config->set_item('lapak_lang', 'en-US'); 
                
                $this->session->set_userdata('lapak_lang', 'en-US');
            }
            if($lang=='id'){ 
                $this->config->set_item('language', 'indonesian'); 
                $this->config->set_item('lapak_lang', 'id'); 
                
                $this->session->set_userdata('lapak_lang', 'id');
            }
            
            redirect($redirect);
            
        }
    }

    In my view file i put anchor like this

    <?php 
    $str = str_replace('/','_',$this->uri->uri_string());
    $lnk_id = base_url()."language/select/id/".$str;
    $lnk_us = base_url()."language/select/us/".$str;
    ?>
    <?php echo $this->lang->line('l_Lang')?> 
    <a href="http://&lt?=$lnk_us?&gt"> </a> <a href="http://&lt?=$lnk_id?&gt"> </a>

    what do you think about my solution?

  • #6 / Jul 01, 2010 3:22am

    celine

    4 posts

    Maybe we could also try that one….So far i couldn’t think of a better idea…

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases