0

Thanks to sof for its support.

I have developed my site in codeIgniter. Now my client came up with a requirement that to put website in different languages.

I have checked with

http://backlink-generator.arxiki.com/free-translate-translator-translation.html

It provided a button for translation.But Iam confused whether it is the perfect procedure or not.Please help me Iam new to this concept.

I have even checked this

How to setup CodeIgniter for a truly multi language website?.

Mywebsite is fully developed .I just to make it work for different languages.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Choco
  • 1,054
  • 1
  • 7
  • 20

2 Answers2

0

There will not be a one button solution for that. You will need to use a Language library like this: http://jeromejaglale.com/doc/php/codeigniter_i18n

and then get all your texts in the language files , this means that under the language folder you will have a folder for each language you support and in there you will have PHP files with variables that will hold the texts for all the pages. this files will be duplicated to each language folder and the content will be then translated.

On your controllers you will load the right language file and then in the view you will just call the string variable name and according to the language the user is currently in it will pull the string from the language file.

The url of your application will be like this http:www.domain.com/en/controller

hope this helps

Lupin
  • 1,225
  • 11
  • 17
0

Change existing website to multi language website : codeigniter

For this you can use language class. See the steps,

Step 1:

create a new file content_lang.php in application/language/english/ for english language. create another content_lang.php file directory dutch for dutch language in application/language/dutch (Create a directory if not exist).

In this file we can write the different languages. Like,

application/language/english/content_lang.php

<?php
 $lang['key']='en';    
 $lang['home']="Home";
 $lang['about']="About Us";
 $lang['login']="Sign In";
?>

application/language/dutch/content_lang.php

<?php
  $lang['key']='dh';    
  $lang['home']="huis";
  $lang['about']="over ons";
  $lang['login']="Aanmelden";
?>

Step 2:

Put the language values at the view at the place text. application/views, Like,

application/views/index.php

<ul>
  <li class="current_page_item"><a href="#"><?php echo $language['home'];?></a></li>
  <li><a href="#"><?php echo $language['about']?></a></li>
  <li><a href="#"><?php echo $language['login']?></a></li>
</ul>

Step 3:

In your controller you can load the language files like,

application/controllers/users.php

function Index()
{   $languages = $this->session->userdata('languages');
    $lg=$languages['language'];
    if($lg=='en'){
        $this->lang->load('content','english');
    }
    elseif($lg=='dh'){
        $this->lang->load('content','dutch');
    }
    else{
        $this->lang->load('content','english');
    }

    $data['language']=array(
        'home'=>$this->lang->line('home'),
        'about'=>$this->lang->line('about'),
        'login'=>$this->lang->line('login')         
    );

    $lg=$this->lang->line('key');
    $data['val']=array(
        'lang'=>$lg
    );

    $this->load->view('index',$data);
    }

Here we can pass two language data and their key value for switching language to view. $data['language'] and $data['val'].

To change the language, (application/controllers/users.php)

function changeLanguage(){
    if(isset($_POST)){
        $this->session->unset_userdata('languages');
        $lg=$this->input->post('sel_lang');
        $lang=array(
            'language'=>$lg
        );
        $this->session->set_userdata(array('languages'=>$lang));

        redirect('users/Index');
    }
}

Step 4:

Code to switching languages on views. (application/views/index.php)

<form id="frm_lg" action="changeLanguage" method="post">
    <?php echo $language['lang_select'];?>
    <select id="sel_lang" name="sel_lang">
        <option value='en' <?php if($lang=='en'){?> selected <?php } ?>>English</option>
        <option value='dh' <?php if($lang=='dh'){?> selected <?php } ?>>Nederlands</option>
    </select>
</form>

Like this way we can load nay number of languages.

Download the example code, Github

Vinod VT
  • 6,946
  • 11
  • 51
  • 75