I’m using language files to allow users to switch between English and Dutch.
The language files contain site text in arrays named $lang. The language is chosen using a GET method by clicking language links on top of the page. All of that works fine.
If I have $lang['my_account']="My Account"; in the English language file, then adding echo $lang['my_account']; to the page correctly displays “My Account”.
But I have a lot of titles which include PHP variables which are set on the page itself, for instance:
Account Statement on <?php echo $today; ?> for user <?php echo $user; ?>
Now I need to add multiple language support for those, and I’m stuck, because I can’t have the $today and $user variables declared before I include the language file. So, my question is, do I have to add separate entries to the language files for “Account Statement on” and “for user” and do something like this on the page:
<?php echo $lang['acc_statement'].$today.$lang['for_user'].$user; ?>
Or is there a way around this?
I’m not sure if I understood you right, but shouldn’t something like sprintf() solve this problem:
and then echo like: