jeudi 1 octobre 2015

simplify massive same php conditions

I have a question, I wonder what is the best way to print many different strings depending a language, I mean, today I have sthg simple :

function getStringA($lang,$data1,$data2){
   if($lang=='en'){return 'my string is '.$data1.' and '.$data2;}
   elseif($lang=='fr'){return 'ma chaine est '.$data1.' et '.$data2;}
   elseif($lang=='it'){return $data1.'blabla '.$data2.' blabla';}
   ..
   [50 conditions]
}

function getStringB($lang,$data){
    [same 50 conditions, one per language]
}

function getStringC($lang,$data){
  ..
}
...

and then :

echo getStringA('en','test','test1');
echo getStringB('en','AAAA');
echo getStringB('en','BBBB');
..

  • there is always those same 50 languages conditions on each function

I thought to use printf but I don't know if it will be really better, I need sthg fast and most important, easy to maintain.

Any idea ?

Aucun commentaire:

Enregistrer un commentaire