• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
language by url

I have a multilanguage app. I translate the web writting in routes.php

$route['(\w{2})/(.*)'] = '$2';

$route['(\w{2})'] = $route['default_controller'];

and in config.php

$config['languages'] = array("es" => "espanol", "en" => "english");

$config['redirect_urls'] = true;

$autoload['helper'] = array('language','url');
$autoload['language'] = array("app");

and extending lang.php

<?php (defined('BASEPATH')) OR exit('No direct script access allowed');

class MY_Lang extends CI_Lang
function __construct()
$config =& get_config();
if(isset($config['languages']) && isset($config['redirect_urls']))
global $URI, $CFG, $IN;
$lang = (isset($URI->segments['1']))?$URI->segments['1']:'';
if(strlen($lang) == 2 && array_key_exists($lang,$config['languages']) == true)
elseif($config['redirect_urls'] == true || strlen($lang) == 2 && array_key_exists($lang,$config['languages']) == false)
header("location: $url");

In language, I have the diferents languaje, english, spanish... app_lang.php

$lang['msj_welcome'] = "Welcome to Codeigniter";

$lang['msj_welcome'] = "Bienvenido a Codeigniter";

It works.

But my problem is that I don't know how I can keep the language when I do a redirect for example in a login

function login(){

if (($this->session->userdata('ses_usuario'))){

redirect('home', 'location');


My problem is when I submit, the url is always redirected to english url. So,
en/login go to en/home, but es/login go to en/home too, and I want to go to es/home.

Any hints.

Have you tried Google Translate API ?

It will save you tons of time.

Have you tried putting your language into SESSION?

Just like the way you put a username when you login and logout in your site.

Thanks, but I would like to have the language in my url,


On a side note about Google Translate and SEO... if you use it, you should block ALL translated pages from the google search engine bot, you DO NOT want auto-translated pages indexed, you'll suffer in the rankings.

Why? It's to stop people from:
1. translating their entire site into every available language, which would be a huge drain on googles resources if, for example, there where 1+ billion websites (and constantly growing) translating into 200+ different languages!
2. Google knows its auto translator is just that, crappy to say the least. It only wants to index high quality pages (regardless of the language).

So while it's fine to use it to provide a service to your customer base, make sure those pages are not indexed by google :-)

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.