0

I have an application build in Codeigniter framework.which have functionality of multi language.It works fine In view to convert the each line.But for alert messages which is set from controller i try to use the language key but failed to show the message on view in multi language.

Here is the code of controller from the message has been set to show on view:-

the function of controller to set the message:

function serial_coupon()
    {
     $admin_session_data= $this->session->userdata('user_logged_in');
     $key=$this->input->post('serial');
     $res=explode("000",$key);
     $key=$res[1];
     $result['coupon']=$this->provider_model->get_coupon($key);
          if(empty($result['coupon']))
           {
                       $msg=$this->lang->line('language_srch_msg');
               $this -> session -> set_flashdata('message',$msg);//if no search found than set the message.
               redirect('/provider/');//provider is controller
           }
           else
           {

               $this->load->view('header',$admin_session_data);
               $this->load->view('show_coupon',$result);
               $this->load->view('footer',$admin_session_data);
           }
    }

Hence it comes to the Provider controller's Index Function to send the message on view:-

function index()
        {
            $msg=$this->session->flashdata('message');//get the message 
            $result['msg']=$msg;and set to the array to send in view

                $result['rows']=$this->session->userdata('provider_detail');
        $user_id=$result['rows'][0]['id'];
            $result['coupons']=$this->provider_model->show_coupons($user_id);
            $this->load->view('header');
            $this->load->view('provider_interface',$result);
        $this->load->view('footer');

    }

So the message should be display in view:

<p><?php echo $msg; ?></p>

And the other lines where i am using language key Like: for name:

<?php echo $this->lang->line('language_name');?>

Now please Let me know how can i use the above language key for message in controller??

Thanks In advance and still any doubt feel free to Ask.

Short description : the problem is not to show the falshdata message.i want the message should be in a particular language in which the user selected.my application in multi language in which the user can select the language from drop down box.and the whole content in convert in to the selected language .but the alert messages comes from controller so how can i convert them in selected language?

I changed my code in function search_coupon but it works for only English language not for Portuguese.Here is my constructor code of provider controller:

public function __construct()
        {
            parent::__construct();
            $this->load->helper('url');
            $this->load->helper('form');
            $this->load->library('session');
            $this->load->model('provider_model');

            $lng=$this->session->userdata('about_language');

                 if($lng=='' ) 
                 {

                $this->load->language('language','english');

                 }
                 else
                 {

                $this->load->language('language',$lng);

                 }



            if($this->session->userdata('provider')=="")
            {
              redirect('/login/', 'refresh');   
            }


        }

Code for select The language using ajax:

<script type="text/javascript">
         jQuery(document).ready(function() {
          jQuery('#port').click(function(){
                                    var dummy = 2;
                                    $.ajax({
                                            type: "POST",
                                            url: "<?php echo BASE_PATH; ?>/session/sessions",
                                        data: "&ID="+dummy+ "&lang="+'portuguese',
                                            success: function(response)
                                                {

                                                    if (response == false)
                                                        {   
                                                            location.reload();

                                                        }  
                                                }
                                           });

                                   });

            jQuery('#eng').click(function(){
                                        var dummy = 1;
                                        $.ajax({
                                                    type: "POST",
                                                    url: "<?php echo BASE_PATH; ?>/session/sessions",
                                                 data: "&ID="+dummy+ "&lang="+'english',
                                                    success: function(response)
                                                        {

                                                            if (response == false)
                                                                {
                                                                    location.reload();
                                                                }
                                                        }
                                                });

                                         });
         });
          </script> 

And here is the session controller :

function sessions(){

         $value=  $this->input->post('ID');
         $lang=  $this->input->post('lang');

         $lang=$this->session->set_userdata('about_language',$lang);
         return $lang;
        }
4
  • You want that flashdata message to be displayed in view? Commented Oct 17, 2012 at 7:14
  • @JamshidHashimi,the problem is not to show the falshdata message.i want the message should be in a particular language in which the user selected.my application in multi language in which the user can select the language from drop down box.and the whole content in convert in to the selected language .but the alert messages comes from controller so how can i convert them in selected language? Commented Oct 17, 2012 at 7:21
  • Do you also know that the flashdata messages are destroyed after the very first page refresh? Commented Oct 17, 2012 at 7:58
  • yeah i know very well,but atleast first time it should work for selected language. Commented Oct 17, 2012 at 8:13

2 Answers 2

1

One solution, perhaps not the best, is to store in the flash var the message key instead of the message. At this moment you are storing:

$this -> session -> set_flashdata('message','No Search Found Of This Serial Number');//if no search found than set the message.

and then you are loading the message:

$msg=$this->session->flashdata('message');//get the message 
$result['msg']=$msg;

And showed in the view:

<p><?php echo $msg; ?></p>

I proposed you this solution:

$this -> session -> set_flashdata('message','message_key');//if no search found than set the message.

$msg_key = $this->session->flashdata('message');//get the message key
$result['msg_key'] = $msg_key;

And in the view:

<p><?php echo $this->lang->line('msg_key'); ?></p>
Sign up to request clarification or add additional context in comments.

1 Comment

thanks for the answer but showing the message is not my problem.it works fine for English But when user selects the Portuguese than it redirects me to login page because at that time my provider session value becomes null. i don't know why this is happen.
0

Ok, then do like this: Every time you change your language, set it into session. Load your language file according to your language session value. Then you will have all your messages into your changed language.

$this->lang->load('filename', $this->session->userdata('user_lang'));

4 Comments

thanks for the answer but showing the message is not my problem.it works fine for English But when user selects the Portuguese than it redirects me to login page because at that time my provider session value becomes null. i don't know why this is happen.
Direct after changing the language, set the language into session. Then you will have the portuguese language in.
my dear i did that ,see my constructor in which i am getting the value of session(about_language). it works fine.i think you didn't understand my question correctly.
Could you please write here the place where you change your language?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.