mysql - Creating a php file for translating the content dynamically -


i have database has around 700 terms. write single php file called internationalize check mysql database , return proper translation. php variables have been setup , there view contains translation of languages. there 11 languages. have looked in lot of places, there isn't 1 fits situation. suggestions appreciated.

if (!isset($_session)) {     session_start(); }  if (isset($setup)) {     $lang=$_session['setuplang']; } elseif (isset($_session['lang'])) {     $lang=$_session['lang']; } else { require("fetchmainconfig.php"); }  $lang_code = $lang;  //file_dir contains language codes example: il,fr,pt,ge , on $sql = "select file_dir `hydroserver_translation`.`language_file_dir`"; if($lang_code = $sql){     // should go in here??? best way     // dynamically translate database? } 

i attaching copy of database view. plan write code such way if there no language translation default translation in english.

user image

this have done , works. thank help!

<?php //connects database $mysqlserver="servername"; $mysqlusername="langreader"; $mysqlpassword="readhsllang@9"; $error=0; $link=mysqli_connect($mysqlserver, $mysqlusername, $mysqlpassword) or $error=1;  $dbname = 'translation'; mysqli_select_db($link, $dbname) or $error=1; if(!$error) {//check session language  $language = $lang_code; //language file path $file_path = "languages/" .$language. ".php"; //check if file exists  $file_exists = file_exists($file_path); if($file_exists){ // file exists. check when last time created. $file_created_time =  filemtime($file_path); $timezone = date_default_timezone_set('utc'); $current_time = time(); //time lapse check difference between current time , last created time $time_lapse = (abs($current_time-$file_created_time)/60/60); //sql statement access view database $sql = "select * translation.translations_by_language"; $terms = mysqli_query($link, $sql); //will create new file if has been more 4 hours if($time_lapse >= '4.0'){ //deleting existing file avoid parsing errors unlink($file_exists); //writing new language_file $lang_file= fopen("languages/" .$language. ".php","c+"); //loops through query , shows translated terms  //and english terms if there no translations term $new_file = "<?php" . "\n ";  fwrite($lang_file, $new_file); while($row = mysqli_fetch_array($terms)) {           if ($row[$language] != "")             fwrite($lang_file,$row['php_variable']. " = " . '"' . addslashes($row[$language]) . '"' . ";" . "\n ");         else             fwrite($lang_file,$row['php_variable']. " = " . '"' . addslashes($row['english_phrase']) . '"' . ";" . "\n ");     }     $last_line = "?>"; fwrite($lang_file, $last_line); fclose($lang_file); }    } else{ // creating new file if file doesn't exist $sql = "select * hydroserver_translation.translations_by_language"; $terms = mysqli_query($link, $sql); $lang_file= fopen("languages/" .$language. ".php","c+"); $new_file = "<?php" . "\n ";  fwrite($lang_file, $new_file); while($row = mysqli_fetch_array($terms)) { print_r($row);         if ($row[$language] != "") //provide translation             fwrite($lang_file,$row['php_variable']. " = " . '"' . addslashes($row[$language]) . '"' . ";" . "\n "); //if translation doesn't exist, use english phrase         else             fwrite($lang_file,$row['php_variable']. " = " . '"' . addslashes($row['english_phrase']) . '"' . ";" . "\n ");     }     $last_line = "?>"; fwrite($lang_file, $last_line); fclose($lang_file); //new language file succesfully created!!!! } } 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -