for a localized website I want to create different language files. But my main problem before starting the localiuation is, that i probably have strings with variables.
My theory is that i can use placeholders within my language files like:
$lang['somekey'] = "Hello Mr. %s, how are you?";
Is there a clean and nice way to parse those variables or do i have to develop a function for that?
Thanks.
I have the same problem and do it simply by using,
echo sprintf($this->lang->line('somekey'),'XYZ');//load language library before use
Read sprintf()
you can use codeigniter i18n with PHP .sprintf() to achieve what you want. load up the codeigniter non-variable strings (with those format stuff), then pass it on to .sprintf()
for formatting and assignment of values. it should replace the %s
part.
it's similar to this question. .sprintf() works like .printf(), only that it returns the string rather than printing it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With