How to share the page to facebook / twitter with different language? How to share the page to facebook / twitter with different language? codeigniter codeigniter

How to share the page to facebook / twitter with different language?


Have you explored the internationalization documentation?

Using og:locale:alternate meta tags (one pointing to each language) should show the link in the Facebook users native language across Facebook.com.

Try it out :D


If you put the information about the language inside the link like this http://example.com/video/view/1/english, then the language info can be taken as a parameter by the controller (it would have helped if you mentioned what was the controller here, but let's say it's view()), and use it, like this:

function view($param1, $lang = false){}

You can then modify function set_lang(), to take two parameters, $var(the original one) and $lang:

function set_lang($var, $lang = false){   if(!$lang){       $CI = & get_instance();       $lang = $CI->session->userdata('site_lang');   }   if ($lang == "english") {       return $var;   } else if ($lang == "zh_tw") {       return $var . "_tw";   } else if ($lang == "zh_cn") {       return $var . "_cn";   }}

This way, if the language is set in url, $CI->session->userdata('site_lang') will be ignorred.

Now if you want to pass $lang to your view, you do it like this:

function view($param1, $lang = false){     $local['lang_by_url'] = $lang;        $this->load->view('the_view', $local);}

And in your view:

echo "<meta name='twitter:card' content='summary' />";echo "<meta property='og:title' content='" $video->{set_lang("title", $lang_by_url)} . "' />";......

It's a little hacky, but it should work.