My question looks almost the same as this Is it possible to put variables inside config files?
I have a config file that controls the language. Also I have a feedback div that is showed for the feedback.
Now I want to assign feedback like this:
$smarty->assign('feedback', 'the_age_of_user_' . $user->name . '_is_changed_to_' . $user->age . '_years');
nl.conf
the_age_of_user_%s_is_changed_to_%s_years = De leeftijd van gebruiker %s gewijzigd naar %s jaar
en.conf
the_age_of_user_%s_is_changed_to_%s_years = The age of user %s is changed to %s years
Does anyone know how I can accomplish this? Or is there a better solution to assign variables to the config file?
Sorry, but I don’t completely understand what are you trying to accomplish.
In our project, we have following solution for similar problem:
Language file:
the_age_of_user_is_changed = The age of user {user} is changed to {year} yearsNotice that there is no %s or any variables on left side. It is always constant.
Option 1:
Smarty/code assigment:
$smarty->assign("VARIABLE_TO_USE_IN_TEMPLATE", getLang('the_age_of_user_is_changed', array('user' => $user->name,'year' => $user->age));Then, in Smarty, you can use following code:
{$VARIABLE_TO_USE_IN_TEMPLATE}Function getLang reads string information from language files and replaces all {symbol} to corresponding data.
Option 2:
In template, we have smarty userspace function:
{LANG key='the_age_of_user_is_changed' name=$user->name year=$user->age}Lang is actually calls function getLang from previous example.
In code you have to assign user:
$smarty->assign("user", $user);. After that, smarty will do everything by itself.