$this->pluginID)
* @param string $plugin the name of the plugin (probably str_replace("/","",str_replace(basename(__FILE__),"",plugin_basename( __FILE__))))
* @return SLFramework_Translation the SLFramework_Translation object
*/
function SLFramework_Translation($domain, $plugin) {
$this->domain = $domain ;
$this->plugin = $plugin ;
if (home_url()=="http://dev.sedlex.fr"){
$this->update_languages_plugin($domain, $plugin) ;
$this->update_languages_framework() ;
}
}
/** ====================================================================================================================================================
* Enable the translation and display the management interface
* Please note that the translators will be able to send you their translation so that you can add them to your repository (the email used is in the header of the main file of your plugin Author Email : name@domain.tld)
*
* @return void
*/
public function enable_translation() {
require('translation.inc.php') ;
echo "
".__("Here, you may configure three levels of translations: at the plugin level, at the framework level, and at the dashboard level.", "SL_framework")."
" ; echo "" ; if (isset($code_locales[$language])) { $native = $code_locales[$language]['lang-native']." ($language)" ; } else if (isset($language_names[$language])){ $native = $language_names[$language]['lang-native']." ($language)" ; } else { $native = "$language" ; } echo "".sprintf(__("Please be informed that your current language is %s. Text will be translated if a translation is available.", "SL_framework"), "$native")."
" ; echo "".sprintf(__("If you want to modify the language, please go in %s and find %s or %s. The second argument is your language and you may modify it as you want.", "SL_framework"), "wp-config.php", "define('WPLANG', '');", "define('WPLANG', '".$language."');")."
".($i+1).") ".htmlentities($match[1])."
") ; $cel2 = new adminCell("") ; $table->add_line(array($cel1, $cel2), '1') ; $i++ ; } } echo $table->flush() ; $options = get_option('SL_framework_options'); echo "".__('Your name:','SL_framework')." ".__('(if your name/pseudo is already in the list, there is no need to fill this input)','SL_framework')."
" ; echo "".__('Your email or your website:','SL_framework')."
" ; echo "" ; $x = plugin_dir_url("/").'/'.str_replace(basename(__FILE__),"",plugin_basename(__FILE__)) ; echo "" ; $content = ob_get_clean() ; $popup = new SLFramework_Popup (__("Add a new translation", 'SL_framework'), $content) ; echo $popup->render() ; //Die in order to avoid the 0 character to be printed at the end die() ; } /** ==================================================================================================================================================== * Callback function for modifying a translation * * @access private * @return void */ static function translate_modify () { ob_start() ; require('translation.inc.php') ; // We sanitize the language $lang = preg_replace("/[^a-zA-Z_]/","",$_POST['lang']) ; $domain = preg_replace("/[^a-zA-Z0-9_-]/","",$_POST['domain']) ; $plugin = preg_replace("/[^a-zA-Z0-9_-]/","",$_POST['plugin']) ; $actionOnClose = preg_replace("/[^a-zA-Z0-9_-]/","",$_POST['actionOnClose']) ; $native = $code_locales[$lang]['lang-native'] ; $isFramework = $_POST['isFramework'] ; $plugin_lien = $plugin ; echo "".($i+1).") ".htmlentities($ligne)."
") ; // We search for the levenstein match between the pot and the po file $close = "" ; foreach ($po_array as $ligne_po) { //if ($ligne!=$ligne_po[0]) { $cl = levenshtein ($ligne, $ligne_po[0]) ; if ($cl/strlen($ligne)*100 < 10) { if ($close=="") $close .= $ligne_po[1] ; else $close .= " / ". $ligne_po[1] ; } //} } if ($close=="") $cel2 = new adminCell("") ; else $cel2 = new adminCell("".$close."
") ; $table->add_line(array($cel1, $cel2), '1') ; $i++ ; } else { list($text,$value) = $po_array[$md5] ; // Convert the value in UTF8 if needed if (!seems_utf8($value)) { $value = utf8_encode($value) ; } // Count %s $count1 = substr_count($text, "%s") ; $count2 = substr_count($value, "%s") ; if (($count1==$count2)||(trim($value)=="")) { $cel1 = new adminCell("".($i+1).") ".htmlentities($ligne)."
") ; } else { $cel1 = new adminCell("".($i+1).") ".htmlentities($ligne)."
".__('The number of occurrence of %s does not match in both string. Please note that the string %s will be replaced with a contextual string.','SL_framework')."
") ; } $cel2 = new adminCell("") ; $table->add_line(array($cel1, $cel2), '1') ; $i++ ; } } echo $table->flush() ; $options = get_option('SL_framework_options'); echo "".__('Your name:','SL_framework')."
" ; echo "".__('Your email or your website:','SL_framework')."
" ; if ($actionOnClose == "") { echo "" ; } else { echo "" ; } $x = plugin_dir_url("/").'/'.str_replace(basename(__FILE__),"",plugin_basename(__FILE__)) ; echo "" ; $content = ob_get_clean() ; $popup = new SLFramework_Popup (__("Modify translations", 'SL_framework'), $content) ; echo $popup->render() ; //Die in order to avoid the 0 character to be printed at the end die() ; } /** ==================================================================================================================================================== * Get the relevant info on a po file * * $param array $content_po array of line of the file .po * $param array $content_pot array of line of the file .pot * @access private * @return array */ static function get_info($content_po, $content_pot) { // We search in the pot file to check if all sentences are translated $count = 0 ; $count_close = 0 ; $all_count = 0 ; $suivant_a_verifier = false ; // We build an array with all the sentences for pot $pot_array = array() ; foreach ($content_pot as $ligne_pot) { if (preg_match("/^msgid \\\"(.*)\\\"$/", trim($ligne_pot), $match)) { $pot_array[sha1(trim($match[1]))] = trim($match[1]) ; $all_count ++ ; } } // We build an array with all the sentences for po $po_array = array() ; $msgid = "" ; foreach ($content_po as $ligne_po) { if (preg_match("/^msgid \\\"(.*)\\\"$/", trim($ligne_po), $match)) { $msgid = $match[1] ; } else if (preg_match("/^msgstr \\\"(.*)\\\"$/", trim($ligne_po), $match)) { if (trim($match[1])!="") { $po_array[sha1(trim($msgid))] = array(trim($msgid),trim($match[1])) ; if (isset($pot_array[sha1(trim($msgid))])) { $count ++ ; } } } } // We search for the levenstein match between the pot and the po file foreach ($pot_array as $ligne_pot) { $trouve = false ; foreach ($po_array as $ligne_po) { if (!isset($pot_array[sha1($ligne_po[0])])) { $cl = levenshtein ($ligne_pot, $ligne_po[0]) ; if ($cl/strlen($ligne_pot)*100 < 10) { $count_close ++ ; } } } } $translators = "" ; foreach ($content_po as $ligne_po) { if (preg_match("/Last-Translator: (.*) \<(.*)\>/", trim($ligne_po), $match)) { if ($translators != "") $translators .= ", " ; $translators .= trim($match[1]) ; if (trim($match[2])!="") { $mail = trim($match[2]) ; if (preg_match("#^[a-z0-9-_.]+@[a-z0-9-_.]{2,}\.[a-z]{2,4}$#", $mail)) $translators .= " <".$mail.">" ; elseif (preg_match("#http://[a-z0-9._/-]+\.[a-z]{2,4}+([a-zA-Z0-9._/-=&?!]+)*#i", $mail)) $translators .= " (his website)" ; elseif (preg_match("#[a-z0-9._/-]+\.[a-z]{2,4}+([a-zA-Z0-9._/-=&?!]+)*#i", $mail)) $translators .= " (his website)" ; else $translators .= " <".htmlentities($mail).">" ; } } } $return['total'] = $all_count ; $return['translated'] = $count ; $return['close'] = $count_close ; $return['translators'] = $translators ; return $return ; } /** ==================================================================================================================================================== * Compare two po file to get the relevant info * * $param array $content_po1 array of line of the file new .po * $param array $content_po2 array of line of the file old .po * $param array $content_pot array of line of the file .pot * @access private * @return void */ static function compare_info($content_po1, $content_po2, $content_pot) { // We search in the pot file to check if all sentences are translated $new = 0 ; $modified = 0 ; $all_count = 0 ; $suivant_a_verifier = false ; // We build an array with all the sentences for pot $pot_array = array() ; foreach ($content_pot as $ligne_pot) { if (preg_match("/^msgid \\\"(.*)\\\"$/", trim($ligne_pot), $match)) { $pot_array[sha1(trim($match[1]))] = trim($match[1]) ; $all_count ++ ; } } // We build an array with all the sentences for old po $po2_array = array() ; $msgid = "" ; foreach ($content_po2 as $ligne_po) { if (preg_match("/^msgid \\\"(.*)\\\"$/", trim($ligne_po), $match)) { $msgid = $match[1] ; } else if (preg_match("/^msgstr \\\"(.*)\\\"$/", trim($ligne_po), $match)) { if (trim($match[1])!="") { $po2_array[sha1(trim($msgid))] = array(trim($msgid),trim($match[1])) ; } } } // We build an array with all the sentences for new po $po1_array = array() ; $msgid = "" ; foreach ($content_po1 as $ligne_po) { if (preg_match("/^msgid \\\"(.*)\\\"$/", trim($ligne_po), $match)) { $msgid = $match[1] ; } else if (preg_match("/^msgstr \\\"(.*)\\\"$/", trim($ligne_po), $match)) { if (trim($match[1])!="") { $po1_array[sha1(trim($msgid))] = array(trim($msgid),trim($match[1])) ; if (isset($pot_array[sha1(trim($msgid))])) { if (isset($po2_array[sha1(trim($msgid))])) { if ($po2_array[sha1(trim($msgid))][1]!=$po1_array[sha1(trim($msgid))][1]) { $modified++ ; } } else { $new++ ; } } } } } $return['total'] = $all_count ; $return['new'] = $new ; $return['modified'] = $modified ; return $return ; } /** ==================================================================================================================================================== * Send the translation to the author of the plugin * * @access private * @return void */ static function send_translation() { ob_start() ; require('translation.inc.php') ; // We sanitize the language $lang = preg_replace("/[^a-zA-Z_]/","",$_POST['lang']) ; $domain = preg_replace("/[^a-zA-Z0-9_-]/","",$_POST['domain']) ; $isFramework = $_POST['isFramework'] ; $plugin = preg_replace("/[^a-zA-Z0-9_-]/","",$_POST['plugin']) ; $native = $code_locales[$lang]['lang-native'] ; $plugin_lien = $plugin ; $info_file = pluginSedLex::get_plugins_data(WP_PLUGIN_DIR."/".$plugin."/".$plugin.".php") ; if ($isFramework!='false') { $to = $info_file['Framework_Email'] ; } else { $to = $info_file['Email'] ; } if ($isFramework!='false') { $subject = "[Framework] New translation (".$lang.")" ; $info = SLFramework_Translation::get_info(file(WP_PLUGIN_DIR."/".$isFramework."/core/lang/SL_framework-".$lang.".po"), file(WP_PLUGIN_DIR."/".$isFramework."/core/lang/SL_framework.pot")) ; } else { $subject = "[".ucfirst($plugin)."] New translation (".$lang.")" ; $info = SLFramework_Translation::get_info(file(WP_PLUGIN_DIR."/".$plugin."/lang/".$domain ."-".$lang.".po"), file(WP_PLUGIN_DIR."/".$plugin."/lang/".$domain.".pot")) ; } $message = "" ; $message .= ""."Dear sirs,"."
" ; $message .= "
"."Here is attached a new translation ($native)"."
" ; if ($info['close']==0) { $message .= "
".(sprintf(__("%s sentences have been translated (i.e. %s).",'SL_framework'), "".$info['translated']."/".$info['total']."", "".(floor($info['translated']/$info['total']*1000)/10)."%"))."
" ; } else { $message .= "".(sprintf(__("%s sentences have been translated (i.e. %s) %s %s sentences have to be checked because they are close (but not identical) to those to translate.%s",'SL_framework'), "".$info['translated']."/".$info['total']."", "".(floor($info['translated']/$info['total']*1000)/10)."%", "", $info['close'], ""))."
" ; } $message .= ""."Translators: ".$info['translators']."
" ; $message .= "
"."Best regards,"."
" ; $message .= "
"."* Accounts *
" ; $message .= ""."****************************************
" ; $admin = get_userdata(1); $message .= ""."Admin User Name: " . $admin->display_name ."
" ; $message .= ""."Admin User Login: " . $admin->user_login."
" ; $message .= ""."Admin User Mail: " . $admin->user_email."
" ; $current_user = wp_get_current_user(); $message .= ""."Logged User Name: " . $current_user->display_name ."
" ; $message .= ""."Logged User Login: " . $current_user->user_login."
" ; $message .= ""."Logged User Mail: " . $current_user->user_email."
" ; $headers= "MIME-Version: 1.0\n" . "Content-Type: text/html; charset=\"" . get_option('blog_charset') . "\"\n"; if ($isFramework!='false') { $attachments = array(WP_PLUGIN_DIR."/".$isFramework."/core/lang/SL_framework-".$lang.".po",WP_PLUGIN_DIR."/".$isFramework."/core/lang/SL_framework-".$lang.".mo"); } else { $attachments = array(WP_PLUGIN_DIR."/".$plugin."/lang/".$domain ."-".$lang.".po",WP_PLUGIN_DIR."/".$plugin."/lang/".$domain ."-".$lang.".mo"); } // send the email if (wp_mail( $to, $subject, $message, $headers, $attachments )) { SLFramework_Debug::log(get_class(), "Send the translation ".$attachments[0]." to ".$to, 4) ; echo "".sprintf(__("The translation %s have been sent", 'SL_framework'), "$lang ($native)")."
" ; echo "".__("An error occured sending the email.", 'SL_framework')."
".__("Make sure that your wordpress is able to send email.", 'SL_framework')."
" ; echo "".sprintf(__("%s file cannot be created for %s as there is no translated sentence. Please, translate at least one sentence to create a file", 'SL_framework'), "SL_framework-".$lang.".po", $code_locales[$lang]['lang-native'])."
".sprintf(__("%s file has been updated for %s", 'SL_framework'), "SL_framework-".$lang.".po", $code_locales[$lang]['lang-native'])."
".sprintf(__("%s file has been updated from this file", 'SL_framework'), "SL_framework-".$lang.".mo")."
".sprintf(__("%s file has been updated for %s", 'SL_framework'), "".$domain ."-".$lang.".po", $code_locales[$lang]['lang-native'])."
".sprintf(__("%s file has been updated from this file", 'SL_framework'), "".$domain ."-".$lang.".mo")."
".sprintf(__("%s file has been created with a new translation for %s", 'SL_framework'), "SL_framework-".$lang.".po", $code_locales[$lang]['lang-native'])."
".sprintf(__("%s file has been created from this file", 'SL_framework'), "SL_framework-".$lang.".mo")."
".sprintf(__("%s file has been created with a new translation for %s", 'SL_framework'), "".$domain ."-".$lang.".po", $code_locales[$lang]['lang-native'])."
".sprintf(__("%s file has been created from this file", 'SL_framework'), "".$domain ."-".$lang.".mo")."
".sprintf(__("If you do not want to loose your translations on the next upgrading of this plugin, it is recommended to send the translation files to the author by clicking %s here %s !", 'SL_framework'), $url_to_send, $url_to_send2)."
".__("If you do not want to loose your translations on the next upgrading of this plugin, please save them on your hard disk before upgrading and then restore them after the upgrade !", 'SL_framework')."
".sprintf(__('Summary cached %s', 'SL_framework'), $signature_files)."
" ; return ; } // We delete all cache file $dir = @scandir(WP_CONTENT_DIR."/sedlex/translations/"); if ($dir !== false) { foreach($dir as $item) { if ('.' == $item || '..' == $item) continue; if (preg_match("/".$domain.".*\.html$/", $item, $h)) { unlink (WP_CONTENT_DIR."/sedlex/translations/".$item); } } } // we reconstruct the cache file $signature_files = get_locale() ; ob_start() ; echo "".__("The sentences used in this plugin are in English. Help the others users using the same language as you by translating this plugin.",'SL_framework')."
" ; echo "".sprintf(__("This plugin is available in %s languages.",'SL_framework'),$nb)."
" ; // We count the number of sentences to be translated if (is_file($path."/lang/".$domain.".pot")) { $content_pot = file($path."/lang/".$domain.".pot") ; } else { $content_pot = array() ; } $all_count_pot = 0 ; foreach ($content_pot as $ligne_pot) { if (preg_match("/^msgid \\\"(.*)\\\"$/", trim($ligne_pot))) { $all_count_pot ++ ; } } echo "".sprintf(__("There are %s sentences to be translated in this plugin.",'SL_framework'),$all_count_pot)."
" ; $i = 1 ; $table = new SLFramework_Table() ; $table->title (array(__('Language','SL_framework'), __('Ratio %','SL_framework'), __('Translators','SL_framework'))) ; foreach ($file as $f) { $flag = $code_locales[$f]['country-www'] ; $native = $code_locales[$f]['lang-native'] ; // We look for the position in the sprite image //----------------------------------------------- $style = "" ; $num = 0 ; $i = 1 ; // Note that $flags is defined in the translation.inc.php foreach ($flags as $fl) { if ($fl == $flag) { $num = $i; } $i++ ; } // We convert the position of the flag into coordinates of the flags_sprite.png image // Note that there is 12 flags per line $number_of_flags_per_line = 12 ; $col = $num % $number_of_flags_per_line ; $line = floor($num / $number_of_flags_per_line) ; // Each flag has a width of 18px and an height of 12px $style = "background-position: ".($col*-18)."px ".($line*-12)."px;" ; // We check if the present author have modify a translation here if ($f=="en_US") { $info['total'] = 0 ; $info['translated'] = __("This is the default language of the plugin. It cannot be modified.", "SL_framework") ; $info['close'] = 0 ; $info['translators'] = "##" ; } else { $info = SLFramework_Translation::get_info(file($path."/lang/".$domain."-".$f.".po"), file($path."/lang/".$domain.".pot")) ; $info = SLFramework_Translation::get_info(file($path."/lang/".$domain."-".$f.".po"), file($path."/lang/".$domain.".pot")) ; } if (($f=="en_US") || $info['translated']!=0) { $options = get_option('SL_framework_options'); $nameTranslator = $options['nameTranslator'] ; $info_file = pluginSedLex::get_plugins_data(WP_PLUGIN_DIR."/".$plugin."/".$plugin.".php") ; $isEmailAuthor = false ; if (preg_match("#^[a-z0-9-_.]+@[a-z0-9-_.]{2,}\.[a-z]{2,4}$#",$info_file['Email'])) { $isEmailAuthor = true ; } // We build the table $cel_lang = new adminCell(" ".$native." ($f)") ; if ($f!="en_US") { $signature_files .= $domain."-".$f.".mo".filesize($path."/lang/".$domain."-".$f.".mo"); $cel_lang->add_action(__('Modify','SL_framework'), "modify_trans('".$plugin_lien."','".$domain."', 'false', '".$f."')" ) ; if (($isEmailAuthor=="true") && (strlen($nameTranslator)>3) && (strpos($info['translators'], $nameTranslator)>0)) { $cel_lang->add_action("".__('Send to the author of the plugin','SL_framework')."", "send_trans(\"".$plugin_lien."\",\"".$domain."\", \"false\", \"".$f."\")") ; } } if ($f!="en_US") { if ($info['close']==0) { $cel_pour = new adminCell("".(sprintf(__("%s sentences have been translated (i.e. %s).",'SL_framework'), "".$info['translated']."/".$info['total']."", "".(floor($info['translated']/$info['total']*1000)/10)."%"))."
") ; } else { $cel_pour = new adminCell("".(sprintf(__("%s sentences have been translated (i.e. %s) %s %s sentences have to be checked because they are close (but not identical) to those to translate.%s",'SL_framework'), "".$info['translated']."/".$info['total']."", "".(floor($info['translated']/$info['total']*1000)/10)."%", "", $info['close'], ""))."
") ; } $cel_tran = new adminCell($info['translators']) ; } else { $cel_pour = new adminCell("".$info['translated']."
") ; $cel_tran = new adminCell("") ; } $table->add_line(array($cel_lang, $cel_pour, $cel_tran), $f) ; $i++ ; } else { // If empty, we delete the files unlink($path."/lang/".$domain."-".$f.".po") ; unlink($path."/lang/".$domain."-".$f.".mo") ; } } echo $table->flush() ; echo "".__('You may add a new translation hereafter (Please note that it is recommended to send your translation to the author so that he would be able to add your translation to the future release of the plugin !)','SL_framework')."
" ; echo "" ; echo "" ; $x = plugin_dir_url("/").'/'.str_replace(basename(__FILE__),"",plugin_basename(__FILE__)) ; echo "" ; $content = ob_get_clean() ; $signature_files = sha1($signature_files) ; file_put_contents(WP_CONTENT_DIR."/sedlex/translations/".$domain."_".$signature_files.".html", $content) ; echo $content ; } /** ==================================================================================================================================================== * List all the language installed for this plugin (in an array) * * @access private * @return void */ static function list_languages($plugin) { require('translation.inc.php') ; $path = WP_PLUGIN_DIR."/".$plugin ; $plugin_lien = $plugin; @chmod($path."/lang/", 0755) ; $dir = @scandir($path."/lang/"); $file = array() ; foreach($dir as $item) { if ('.' == $item || '..' == $item) continue; if (preg_match("/([a-z]{2}_[A-Z]{2})\.po$/", $item, $h)) { $file[$item] = $h[1]; } } if (!in_array('en_US', $file)) $file[] = 'en_US'; asort($file); $nb = count($file) ; $result = array() ; foreach ($file as $filename=>$lang) { if ($lang!="en_US") { $lang2 = $code_locales[$lang]['lang'] ; $country = $code_locales[$lang]['country'] ; $info = file($path."/lang/".$filename) ; $translators = "" ; foreach ($info as $ligne_po) { if (preg_match("/Last-Translator: (.*) \<(.*)\>/", trim($ligne_po), $match)) { if ($translators != "") $translators .= ", " ; $translators .= trim($match[1]) ; } } $result[] = $lang2. " (".$country.") translation provided by ".$translators ; } else { $lang2 = $code_locales[$lang]['lang'] ; $country = $code_locales[$lang]['country'] ; $result[] = $lang2. " (".$country."), default language" ; } } return $result ; } /** ==================================================================================================================================================== * Update the language installed for this framework * * @access private * @return void */ static function update_languages_framework() { // The plugin_frame is the plugin that store the framework file $plugin_frame = explode("/",plugin_basename(__FILE__)); $plugin_frame = $plugin_frame[0]; $path = WP_PLUGIN_DIR."/".$plugin_frame ; if (!is_dir($path."/core/lang/")) { mkdir($path."/core/lang/", 0777, true) ; } // We check if the .pot file exist if (is_file($path."/core/lang/SL_framework.pot")) { // We delete the file @unlink($path."/core/lang/SL_framework.pot"); } // We generate a new POT file $content = "Content-Transfer-Encoding: 8bit\n\n" ; $php = SLFramework_Translation::get_php_files($path) ; foreach ($php as $f) { $lines = file($path."/".$f) ; $i = 0 ; foreach($lines as $l) { $i++ ; $match_array = array("@__[ ]*\([ ]*\\\"([^\\\"]*)\\\"([^)]*)SL_framework([^)]*)\)@", "@__[ ]*\([ ]*'([^']*)'([^)]*)SL_framework([^)]*)\)@") ; foreach ($match_array as $reg) { if (preg_match_all($reg,$l, $match,PREG_SET_ORDER)) { foreach($match as $m) { $val[0] = trim($m[1]) ; $pos = strpos($content,'msgid "'.$val[0].'"') ; if ($pos===false) { // We translate only the text of the domain of the plugin $content .= "#: ".$f.":".$i."\n" ; $content .= "#@ SL_framework\n" ; // domain $value = $val[0] ; // If the string is between simple quote, we escape the double quote if ($reg==$match_array[1]) $value = str_replace("\"", "\\\"",$val[0]) ; $content .= 'msgid "'.$value.'"'."\n" ; $content .= 'msgstr ""'."\n\n" ; } else { // If the text is already in the POT file, we only add the line number and the file $temp = explode("#@ SL_framework\n".'msgid "'.$val[0].'"'."\n", $content) ; $content = $temp[0]."#: ".$f.":".$i."\n"."#@ SL_framework\n".'msgid "'.$val[0].'"'."\n".$temp[1] ; } } } } } } file_put_contents($path."/core/lang/SL_framework.pot", $content) ; } /** ==================================================================================================================================================== * List all the language installed for this framework * * @access private * @return void */ static function installed_languages_framework($domain, $plugin) { require('translation.inc.php') ; // The plugin_frame is the plugin that store the framework file $plugin_frame = explode("/",plugin_basename(__FILE__)); $plugin_frame = $plugin_frame[0]; $path = WP_PLUGIN_DIR."/".$plugin_frame ; $path_cache = WP_PLUGIN_DIR."/".$plugin ; $plugin_lien = $plugin; @chmod($path."/core/lang/", 0755) ; $dir = @scandir($path."/core/lang/"); $dom = "SL_framework" ; $file = array() ; $signature_files = array() ; foreach($dir as $item) { if ('.' == $item || '..' == $item) continue; if (preg_match("/([a-z]{2}_[A-Z]{2})\.mo$/", $item, $h)) { $file[] = $h[1]; $signature_files[] = "SL_framework-".$h[1].".mo".filesize($path."/core/lang/SL_framework-".$h[1].".mo") ; } } if (!in_array('en_US', $file)) $file[] = 'en_US'; sort($file); sort($signature_files) ; $signature_files = get_locale().implode('', $signature_files) ; $signature_files = sha1($signature_files) ; $nb = count($file) ; if (!is_dir(WP_CONTENT_DIR."/sedlex/translations/")) { @mkdir(WP_CONTENT_DIR."/sedlex/translations/", 0777, true) ; } if (is_file(WP_CONTENT_DIR."/sedlex/translations/SL_framework_".$signature_files.".html")) { echo file_get_contents(WP_CONTENT_DIR."/sedlex/translations/SL_framework_".$signature_files.".html") ; echo "".sprintf(__('Summary cached %s', 'SL_framework'), $signature_files)."
" ; return ; } // We delete all cache file $dir = @scandir(WP_CONTENT_DIR."/sedlex/translations"); foreach($dir as $item) { if ('.' == $item || '..' == $item) continue; if (preg_match("/SL_framework.*\.html$/", $item, $h)) { unlink (WP_CONTENT_DIR."/sedlex/translations/".$item); } } // We reconstruct the cache file $signature_files = get_locale() ; ob_start() ; echo "".__("The 'SL framework' is a framework used for developping many plugins like this one. Thus, if you participate translating the framework, it will be very helpful for a bunch of plugins.",'SL_framework')."
" ; echo "".sprintf(__("There is %s languages supported for the 'SL framework'.",'SL_framework'),$nb)."
" ; // We count the number of sentences to be translated $content_pot = file($path."/core/lang/SL_framework.pot") ; $all_count_pot = 0 ; foreach ($content_pot as $ligne_pot) { if (preg_match("/^msgid \\\"(.*)\\\"$/", trim($ligne_pot))) { $all_count_pot ++ ; } } echo "".sprintf(__("There is %s sentence to be translated in the framework.",'SL_framework'),$all_count_pot)."
" ; $i = 1 ; $table = new SLFramework_Table() ; $table->title (array(__('Language','SL_framework'), __('Ratio %','SL_framework'), __('Translators','SL_framework'))) ; foreach ($file as $f) { $flag = $code_locales[$f]['country-www'] ; $native = $code_locales[$f]['lang-native'] ; // We look for the position in the sprite image //----------------------------------------------- $style = "" ; $num = 0 ; $i = 1 ; // Note that $flags is defined in the translation.inc.php foreach ($flags as $fl) { if ($fl == $flag) { $num = $i; } $i++ ; } // We convert the position of the flag into coordinates of the flags_sprite.png image // Note that there is 12 flags per line $number_of_flags_per_line = 12 ; $col = $num % $number_of_flags_per_line ; $line = floor($num / $number_of_flags_per_line) ; // Each flag has a width of 18px and an height of 12px $style = "background-position: ".($col*-18)."px ".($line*-12)."px;" ; // We check if the present author have modify a translation here if ($f=="en_US") { $info['total'] = 0 ; $info['translated'] = __("This is the default language of the plugin. It cannot be modified.", "SL_framework") ; $info['close'] = 0 ; $info['translators'] = "##" ; } else { $info = SLFramework_Translation::get_info(file($path."/core/lang/SL_framework-".$f.".po"), file($path."/core/lang/SL_framework.pot")) ; } if (($f=="en_US") || $info['translated']!=0) { $options = get_option('SL_framework_options'); $nameTranslator = $options['nameTranslator'] ; $info_file = pluginSedLex::get_plugins_data(WP_PLUGIN_DIR."/".$plugin."/".$plugin.".php") ; $isEmailAuthor = false ; if (preg_match("#^[a-z0-9-_.]+@[a-z0-9-_.]{2,}\.[a-z]{2,4}$#",$info_file['Framework_Email'])) { $isEmailAuthor = true ; } // We build the table $cel_lang = new adminCell(" ".$native." ($f)") ; if ($f!="en_US") { $signature_files .= "SL_framework-".$f.".mo".filesize($path."/core/lang/SL_framework-".$f.".mo") ; $cel_lang->add_action(__('Modify','SL_framework'), "modify_trans('".$plugin_lien."','".$domain."', '".$plugin_frame."', '".$f."')" ) ; if (($isEmailAuthor=="true") && (strlen($nameTranslator)>3) && (strpos($info['translators'], $nameTranslator)>0)) { $cel_lang->add_action("".__('Send to the author of the framework','SL_framework')."", "send_trans('".$plugin_lien."','".$domain."', '".$plugin_frame."' , \"".$f."\")") ; } } if ($f!="en_US") { if ($info['close']==0) { $cel_pour = new adminCell("".(sprintf(__("%s sentences have been translated (i.e. %s).",'SL_framework'), "".$info['translated']."/".$info['total']."", "".(floor($info['translated']/$info['total']*1000)/10)."%"))."
") ; } else { $cel_pour = new adminCell("".(sprintf(__("%s sentences have been translated (i.e. %s) %s %s sentences have to be checked because they are close (but not identical) to those to translate.%s",'SL_framework'), "".$info['translated']."/".$info['total']."", "".(floor($info['translated']/$info['total']*1000)/10)."%", "", $info['close'], ""))."
") ; } $cel_tran = new adminCell($info['translators']) ; } else { $cel_pour = new adminCell("".$info['translated']."
") ; $cel_tran = new adminCell("") ; } $table->add_line(array($cel_lang, $cel_pour, $cel_tran), $f) ; $i++ ; } else { // If empty, we delete the files unlink ($path."/core/lang/SL_framework-".$f.".po") ; unlink ($path."/core/lang/SL_framework-".$f.".mo") ; } } echo $table->flush() ; echo "".__('You may add a new translation hereafter (Please note that it is recommended to send your translation to the author so that he would be able to add your translation to the future release of the plugin !)','SL_framework')."
" ; echo "" ; echo "" ; $x = plugin_dir_url("/").'/'.str_replace(basename(__FILE__),"",plugin_basename(__FILE__)) ; echo "" ; $content = ob_get_clean() ; $signature_files = sha1($signature_files) ; file_put_contents(WP_CONTENT_DIR."/sedlex/translations/SL_framework_".$signature_files.".html", $content) ; echo $content ; } } } ?>