CodeIgniter Forums
passing variables to lang file - 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: passing variables to lang file (/thread-41437.html)



passing variables to lang file - El Forum - 05-07-2011

[eluser]blorriman[/eluser]
I must be missing something here. I'm trying to pass a variable to a lang file using
Code:
//controller
$msg_data = 'put something here';
$data['message'] = $this->lang->line('my_lang-test', $msg_data);
$this->load->view('test/test-lang', $data);

//my_lang file
$lang['my_lang-test'] = 'This is my data = %s';

//view
echo $message;

But this is what I get :
This is my data = %s

What do I need to do to pass the $msg_data to the lang file?


passing variables to lang file - El Forum - 05-07-2011

[eluser]pickupman[/eluser]
The language library only fetches the argument string from your language file. It only passes one argument not two. If you are wanting to do argument swapping, you want to use [url="http://us.php.net/manual/en/function.sprintf.php"]sprintf()[/url] to echo in your view.


passing variables to lang file - El Forum - 05-07-2011

[eluser]blorriman[/eluser]
Thanks pickupman, got it working.


passing variables to lang file - El Forum - 02-24-2012

[eluser]JuanG[/eluser]
Hi, I was asking myself the same question but regarding to anchors.

Before adding internationalization to my web I had the following string:

Code:
"...is called <strong>&lt;?php echo anchor('www.cnn.com', 'CNN'); ?&gt;</strong>.  It's a..."

Now it won't work when included into:

Code:
$lang['home_dilemma_intro'] = "...is called <strong>&lt;?php echo anchor('www.cnn.com', 'CNN'); ?&gt;</strong>.  It's a...";

Thanks in advanced,