CodeIgniter Forums
Updating URL based on language selection and displaying translated page - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Updating URL based on language selection and displaying translated page (/thread-58372.html)



Updating URL based on language selection and displaying translated page - El Forum - 06-06-2013

[eluser]thekrow[/eluser]
Hello

This issue is driving me crazy! I'll try to be brief. I have a dropdown menu that holds several languages. Upon submission I'm basically trying to accomplish two things:

1. I need my URL to update, it means my new URL would look something like this (for example): www.mydomain.com/sp/something.php It basically inserts the language key.

2. In my default controller within my index(), I need to process $this->input->post('lang') so that I'm able to load a number of content files whose variables will be passed into $this->smarty->assign(), and finally display my page with my translated content. Here's my index function:

Code:
function index($page = 'home')      
{    
  not_found($page);        // Quit if page is not found

  $language = $this->multilanguage->language;  // Default lang if no input lang is selected from dropdown
  
  // Load files
  require_once(APPPATH.'language/'.$language.'/'.str_replace('-','_',$page).'_lang.php');
  require_once(APPPATH.'language/'.$language.'/includes_mid_content_lang.php');  
  require_once(APPPATH.'language/'.$language.'/includes_top_lang.php');    
  require_once(APPPATH.'language/'.$language.'/includes_right_content_lang.php');  
  require_once(APPPATH.'language/'.$language.'/includes_footer_lang.php');    
  require_once(APPPATH.'language/'.$this->multilanguage->select_meta_file($language));    
  
  // Assign variables
  $this->smarty->assign('url',$this->multilanguage->url_to_be_assigned($page)); // URL assigned for switching language
  $this->smarty->assign('page',$page.'.tpl');    
  $this->smarty->assign('title',title($page));    // title() helper used
  $this->smarty->assign('meta',meta($meta[$page]));   // meta() helper passes array of meta tags based on input page  
  $this->smarty->assign('top',$top);      
  $this->smarty->assign('category',$category);  
  $this->smarty->assign('right_content',$right_content);
  $this->smarty->assign('footer',$footer);    
  $this->smarty->assign('data',$data);      // Main content
  
  ob_start();
   isset($_SESSION['poll_result']) ? $this->poll_result() : $this->poll_item();
   $this->smarty->assign('poll', ob_get_contents());
   unset($_SESSION['poll_result']);
  ob_end_clean();
  
  // Display template based on input
  $this->display_template($this->select_template($page));  

}


The question:

How do I update my URL upon submission if in order to read the selected language by the user it first has to go through my index function? In other words, On the FIRST submission I need to insert the key into my URL and then assign and display my page with the translated content, how do I do that? what would the 'action' attribute in the dropdown form look like?

If anything is unclear please don't hesitate to ask. Anything, I mean any thing you tell/suggest/recommend me will be much appreciated.