php_guest Posted March 5, 2011 Share Posted March 5, 2011 I am developing a multilingual site. I use array to save translations in one file which I include it inside settings.php. //Example of english $LANG['welcome']="Welcome"; $LANG['status']="Status"; I am wondering about two things: 1. How would be the best option to print those arrays? a) Echo all html and inside html I use echo " <body> <div> <p>{$LANG['welcome']}</p> </div> "; b) Close php and write html and inside html I open and close php for each time <div><p><?php echo $LANG['welcome']; ?></p></div> Each one has own downsides. Option a) spends extra resources to print html. Option b) spends extra resources to close and open php each time (could means that single script needs to open and close php even 30 times per script). Is that bad or is the ammount of resources spend for this negligible? 2. Also how do you translate words inside javascript? I was thinking to put all translation that are need for javascript into $LANG['js'] array. Then I would use at the head of the script foreach $LANG['js'] to print html to assign javascript language variables. <script type="javascript"> <?php foreach($LANG['js'] as $keyword => $translation){ echo "var ".$keyword."= ".$translation.";\n"; } ?> </script> Is there any better way? Thank you! Link to comment https://forums.phpfreaks.com/topic/229701-how-to-organize-language-translations/ Share on other sites More sharing options...
silkfire Posted March 5, 2011 Share Posted March 5, 2011 Do you got acces to a database like mysql? For 2, use JSON. Link to comment https://forums.phpfreaks.com/topic/229701-how-to-organize-language-translations/#findComment-1183329 Share on other sites More sharing options...
php_guest Posted March 5, 2011 Author Share Posted March 5, 2011 I have mysql but the question is not how to store variables but how to print them. So to print as option a) as whole html or as b) as closing and opening for each translation php. Regarding JSON, is there any other option since I am not familiar with JSON? Link to comment https://forums.phpfreaks.com/topic/229701-how-to-organize-language-translations/#findComment-1183336 Share on other sites More sharing options...
n3r0x Posted March 5, 2011 Share Posted March 5, 2011 my multiligual website uses 1, a) with small mod (using single quotes instead of double) echo ' <body> <div> <p>'.$LANG['welcome'].'</p> </div> '; as for javascript... I use a php file as javascript file.. that way I can alter it using PHP variables <script src="javascript.js.php" type="text/javascript" /> and <?php header("Content-type: text/javascript"); ?> // Javascript down here but that´s just me.. Link to comment https://forums.phpfreaks.com/topic/229701-how-to-organize-language-translations/#findComment-1183354 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.