Question:
How could I make my URL language specific, for example:
Additional information:
In the future, I plan to redirect users for different languages to different subdomains, eg lt.website.com, but right now I want URI segments to be translated depending on users language.
I want to make clear that:
My (bad) ideas:
I thought this could be done via translated routing addresses $route[lang('url_market')] = 'market/index';
but when routing is done, language library is not yeat loaded.
Based On @AdrienXL answer, Here's a sample without using a database.
$config['routes_translation']['en'] = array(
'home' => 'home'
);
$config['routes_translation']['fr'] = array(
'home' => 'accueil'
);
Obviously, You know the language for the user using a session, And you have the controller name, You can get the translation easily by accessing the config item.
$translatedNamed = $config['routes_translation'][$language_code][$controller]
which should give you 'home' for en & 'accueil' for fr
The only way I see is through the db.
Build a table that looks like this :
routes_translation
*****************************************
*id | controller | translation | lang*
*****************************************
* 1 | home | home | en *
* 2 | home | accueil | fr *
...
*****************************************
Then in your routes.php
require_once( BASEPATH .'database/DB'. EXT );
$db =& DB();
$query = $db->get('routes_translation');
$result = $query->result();
foreach( $result as $row )
{
$route[$row->translation] = $row->controller;
}
Simple....
Eg: $this->lang->load("message",$SESSION['selected_language']);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.