コード例 #1
0
 protected function add_translations($contexts, $context_prefix)
 {
     if ($contexts) {
         $path = $this->current_path;
         $mo_files = icl_st_get_mo_files($path);
         foreach ((array) $mo_files as $m) {
             $i = preg_match('#[-]?([a-z_]+)\\.mo$#i', $m, $matches);
             if ($i && ($lang = $this->get_lang_code($matches[1]))) {
                 $tr_pairs = icl_st_load_translations_from_mo($m);
                 foreach ($tr_pairs as $original => $translation) {
                     foreach ($contexts as $tld) {
                         $this->fix_existing_string_with_wrong_context($original, $context_prefix . $tld);
                         if ($this->add_translation($original, $translation, $lang, $context_prefix . $tld)) {
                             break;
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #2
0
ファイル: functions.php プロジェクト: edgarter/wecare
function icl_st_get_mo_files($path)
{
    static $mo_files = array();
    if (function_exists('realpath')) {
        $path = realpath($path);
    }
    if (is_dir($path) && is_readable($path)) {
        $dh = opendir($path);
        if ($dh !== false) {
            while ($f = readdir($dh)) {
                if (0 !== strpos($f, '.')) {
                    if (is_dir($path . '/' . $f)) {
                        icl_st_get_mo_files($path . '/' . $f);
                    } else {
                        if (preg_match('#\\.mo$#', $f)) {
                            $mo_files[] = $path . '/' . $f;
                        }
                    }
                }
            }
        }
    }
    return $mo_files;
}
コード例 #3
0
 function tl_rescan_p()
 {
     global $wpdb, $sitepress_settings;
     set_time_limit(0);
     if (preg_replace('#M$#', '', ini_get('memory_limit')) < 128) {
         ini_set('memory_limit', '128M');
     }
     $plugins = array();
     if (!empty($_POST['plugin'])) {
         foreach ($_POST['plugin'] as $plugin) {
             $plugins[] = array('file' => $plugin, 'mu' => 0);
             // regular plugins
         }
     }
     if (!empty($_POST['mu-plugin'])) {
         foreach ($_POST['mu-plugin'] as $plugin) {
             $plugins[] = array('file' => $plugin, 'mu' => 1);
             //mu plugins
         }
     }
     $scan_stats = '';
     foreach ($plugins as $p) {
         $plugin = $p['file'];
         if (false !== strpos($plugin, '/') && !$p['mu']) {
             $plugin = dirname($plugin);
         }
         if ($p['mu']) {
             $plugin_path = WPMU_PLUGIN_DIR . '/' . $plugin;
         } else {
             $plugin_path = WP_PLUGIN_DIR . '/' . $plugin;
         }
         $scan_stats .= icl_st_scan_plugin_files($plugin_path);
         if ($_POST['icl_load_mo'] && !$p['mu']) {
             $mo_files = icl_st_get_mo_files($plugin_path);
             foreach ($mo_files as $m) {
                 $i = preg_match('#[-]([a-z_]+)\\.mo$#i', $m, $matches);
                 if ($i && ($lang = $wpdb->get_var("SELECT code FROM {$wpdb->prefix}icl_locale_map WHERE locale='" . $matches[1] . "'"))) {
                     $tr_pairs = icl_st_load_translations_from_mo($m);
                     foreach ($tr_pairs as $original => $translation) {
                         $string_id = icl_get_string_id($original, 'plugin ' . basename($plugin_path));
                         if (!$wpdb->get_var("SELECT id FROM {$wpdb->prefix}icl_string_translations WHERE string_id={$string_id} AND language='{$lang}'")) {
                             icl_add_string_translation($string_id, $lang, $translation, ICL_STRING_TRANSLATION_COMPLETE);
                         }
                     }
                 }
             }
         }
     }
     echo '1|' . $scan_stats;
     exit;
 }
コード例 #4
0
function icl_st_get_mo_files($path)
{
    static $mo_files = array();
    $dh = opendir($path);
    while ($f = readdir($dh)) {
        if (0 !== strpos($f, '.')) {
            if (is_dir($path . '/' . $f)) {
                icl_st_get_mo_files($path . '/' . $f);
            } else {
                if (preg_match('#\\.mo$#', $f)) {
                    $mo_files[] = $path . '/' . $f;
                }
            }
        }
    }
    return $mo_files;
}
コード例 #5
0
     //mu plugins
 }
 $scan_stats = '';
 foreach ($plugins as $p) {
     $plugin = $p['file'];
     if (false !== strpos($plugin, '/') && !$p['mu']) {
         $plugin = dirname($plugin);
     }
     if ($p['mu']) {
         $plugin_path = WPMU_PLUGIN_DIR . '/' . $plugin;
     } else {
         $plugin_path = WP_PLUGIN_DIR . '/' . $plugin;
     }
     $scan_stats .= icl_st_scan_plugin_files($plugin_path);
     if ($_POST['icl_load_mo'] && !$p['mu']) {
         $mo_files = icl_st_get_mo_files($plugin_path);
         foreach ($mo_files as $m) {
             $i = preg_match('#[-]([a-z_]+)\\.mo$#i', $m, $matches);
             if ($i && ($lang = $wpdb->get_var("SELECT code FROM {$wpdb->prefix}icl_locale_map WHERE locale='" . $matches[1] . "'"))) {
                 $tr_pairs = icl_st_load_translations_from_mo($m);
                 foreach ($tr_pairs as $original => $translation) {
                     $string_id = icl_get_string_id($original, 'plugin ' . basename($plugin_path));
                     if (!$wpdb->get_var["SELECT id FROM {$wpdb->prefix}icl_string_translations WHERE string_id={$string_id} AND language='{$lang}'"]) {
                         icl_add_string_translation($string_id, $lang, $translation, ICL_STRING_TRANSLATION_COMPLETE);
                     }
                 }
             }
         }
     }
 }
 echo '1|' . $scan_stats;