CodeIgniter Forums

Full Version: How can I insert variables into translated sentences?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[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.";

El Forum

[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);

El Forum

[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,

El Forum

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

El Forum

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

Thanks!

El Forum

[eluser]Kristories[/eluser]
Wink