Welcome Guest, Not a member yet? Register   Sign In
language by url
#1

[eluser]Unknown[/eluser]
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']=false;

$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()
{
parent::__construct();
$config =& get_config();
if(isset($config['languages']) && isset($config['redirect_urls']))
{
global $URI, $CFG, $IN;
//var_dump($URI);
$lang = (isset($URI->segments['1']))?$URI->segments['1']:'';
$uri=$URI->segments;
if(strlen($lang) == 2 && array_key_exists($lang,$config['languages']) == true)
{
$config['language']=$config['languages'][$lang];
}
elseif($config['redirect_urls'] == true || strlen($lang) == 2 && array_key_exists($lang,$config['languages']) == false)
{
$url=$config['base_url'];
$url.=(empty($config['index_page']))?'':$config['index_page'].'/';
$url.=array_search($config['language'],$config['languages']).'/';
if(strlen($lang)==2)
{
array_shift($uri);
$url.=implode('/',$uri);
}else
{
$url.=implode('/',$uri);
}
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.





Messages In This Thread
language by url - by El Forum - 10-18-2012, 04:29 PM
language by url - by El Forum - 10-18-2012, 11:03 PM
language by url - by El Forum - 10-18-2012, 11:07 PM
language by url - by El Forum - 10-19-2012, 01:40 AM
language by url - by El Forum - 10-19-2012, 04:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB