CodeIgniter Forums
How can I insert variables into translated sentences? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: How can I insert variables into translated sentences? (/thread-42992.html)



How can I insert variables into translated sentences? - El Forum - 06-26-2011

[eluser]suntrop[/eluser]
I've got a multi-lang website and using the language class. But how do put variables in the translated sentences?

For example:
I want "You need 25 extra points.".

Is there something possible like ...
$lang['ui_messages'] = "You need $num extra points.";


How can I insert variables into translated sentences? - El Forum - 06-26-2011

[eluser]tomcode[/eluser]
Code:
$lang['ui_messages'] = "You need %s extra points.";

$points = 25;
$fmt = $this->lang->line('ui_messages');

$ui_messages = sprintf($fmt, $points);



How can I insert variables into translated sentences? - 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...";

How can I keep my anchors when translating the text?

Thanks in advanced,


How can I insert variables into translated sentences? - El Forum - 03-08-2012

[eluser]Kristories[/eluser]
Try this..
Code:
$lang['home_dilemma_intro'] = "...is called <strong>".anchor('www.cnn.com', 'CNN')."</strong>.  It's a...";



How can I insert variables into translated sentences? - El Forum - 03-09-2012

[eluser]JuanG[/eluser]
That worked out.

Thanks!


How can I insert variables into translated sentences? - El Forum - 03-09-2012

[eluser]Kristories[/eluser]
Wink