I have a site (using Smarty template) which is multilingual. All the languages are in a different lang.ini file.
E.g.:
lang/eng/lang.ini: (In English)
WELCOME = "Welcome"
lang/hun/lang.ini: (In Hungarian)
WELCOME = "Üdvözöllek"
Then in the index.php:
...
$error=array();
if($condition!=$condition2)
{
$error1 = "This is an error msg";
array_push($error, $error1);
}
...
$this->tpl->assign('error', $error);
$lang_file=parse_ini_file("lang/". $_SESSION["lang_folder"] ."/lang.ini",true);
$this->tpl->assignByref("lang",$lang_file);
$this->tpl->display('index.tpl');
Finally in the index.tpl:
...
{$lang.WELCOME}
<br />
{if isset($error) && $error ne "" }
{foreach $error as $error_list}
{$error_list}
{/foreach}
{/if}
...
Now the Welcome can appear in different languages (the path stored in session).
But the $error appears only one language, only print out it’s value.
How can I print it out depending which language is selected? Where should I add value to the $error?
When detecting the error, rather than pushing the English string into your array, push the code you want to retrieve from your INI file:
Then in Smarty, use that as a key in your
$langarray using normal array access syntax: