Hi.
I am implementing a Translate function where the function receives a string as the parameter. This string will be used to dynamically reference a Language variable like {lang_string}.
The reason why I an doing this is because I don’t know in advance what this language variable will be. It’s name will be passed at runtime. The string may come from a form post and passed to the function.
For example, let’s say I pass the string “pet_name”. I want to dynamically call the language variable {lang_pet_name}.
In the calling code, I can have something like
<?php echo translate(‘pet_name’);?>
and the translate function would be something like this
<?php
function translate($token){
$translateVar = ${“lang_”.$token}; //This is where I would like to dynamically call the language variable
return $translateVar ;
}
?>
The code above does create a variable called $lang_pet_name. However, it is not referencing the {lang_pet_name} variable that I need.
Is there a better way to achieve this?
Thanks.