Welcome Guest, Not a member yet? Register   Sign In
How to manage Multi language in portal?
#1

[eluser]web_developer[/eluser]
Hello

I have several question regards Multi-language which is mentioned below:

Q1) I want to set default language "English" and for that I don't want to use "en" parameter in URL.
Home page should be clean like "http://www.xyz.com" Currently it's working fine.
But now below syntax won't working in home page.

Code:
echo anchor($this->lang->switch_uri('fr'),'French');

Because while changing language it is simply replacing "en" with "fr" and "fr" with "en".
Is there any alternative way to append "fr" in URL?

Q2) How to manage all hyperlinks with language? i.e: news, product, blogs, etc..
in each link i have to add "en" and "fr" like anchor("en/blogs")? Each time I have to check what is current language and have to set 1st segment in link? Is there any way to auto detect current language? and append "language" parameter automatic?

Q3) I want to escape "en" and "fr" from uri segment.
That means if URL is like http://www.xyz.com/en/page/1 and if I print uri->segment(1) then it should be print "page" (instead of "en|fr")




#2

[eluser]SmokeyJoe[/eluser]
Try an other solution using jquery:

first set your language anchors
Code:
echo anchor('language/change','FR','data-lang="fr"');

then make the javascript
Code:
$(function(){
$('.lang_anchor').on('click',function(){
  $.post($(this).attr('href'),{lang: $(this).attr('data-lang')},function(){
   w_ind_ow.loca_tion.reload(); // withour underscores
  });
});
});

create a controller language and add a function change
Code:
class Language extends CI_Controller {

function change() {

  switch($this->input->post('lang')) {
   case 'fr': $language = 'french'; break;
   case 'en': $language = 'english'; break;
   case 'de': $language = 'german'; break;
   case 'it': $language = 'italian'; break;
   default: $language = 'english';
  }
  
  $this->session->set_userdata('language',$language);

}

}

after that you only have to check in your __construct if there is a session value for language:
Code:
public function __construct()
{
parent::__construct();


if($this->session->userdata('language')) {
  $language = $this->session->userdata('language');
  $this->load->lang($language,$language);
} else {
  $this->load->lang('english','english');
}
}

this should work. if not please tell me. haven't tested this




Theme © iAndrew 2016 - Forum software by © MyBB