CodeIgniter : Using variables in language files

Posted by Matt Bryson on 12-Nov-2012 12:14:57

Codeigniter uses a fairly standard way of inserting values into strings within its language files.

You define your string with placeholders, and then use sprintf to format the string.

//In your language file... $lang['welcome_username'] = 'Welcome %s.'; //then in your view or controller..
echo ( sprintf( lang("welcome_username"), "Bob") ); //Results in "Welcome Bob."

However, for values that only really change per environment / deployment, it would be beneficial to be able to refer to them from within the language file, rather than having to format the string every time you want to use it.

Read More

Topics: PHP, CodeIgniter