示例#1
0
 /**
  * Render poedit screen
  * @param string optional package root directory
  * @param string PO or PO file path
  * @param array data to load into editor
  */
 private static function render_poeditor(LocoPackage $package, $path, array $data, LocoHeaders $head = null)
 {
     $pot = $po = $locale = null;
     $warnings = array();
     // remove header and check if empty
     $minlength = 1;
     if (isset($data[0]['source']) && $data[0]['source'] === '') {
         $data[0] = array();
         $minlength = 2;
     }
     // path may not exist if we're creating a new one
     if (file_exists($path)) {
         $modified = self::format_datetime(filemtime($path));
     } else {
         $modified = 0;
     }
     if ($is_pot = self::is_pot($path)) {
         $pot = $data;
         $type = 'POT';
     } else {
         $po = $data;
         $type = 'PO';
         $locale = self::resolve_file_locale($path);
         $domain = self::resolve_file_domain($path);
         $haspot = $package->get_pot($domain);
     }
     // warn if new file can't be written
     $writable = self::is_writable($path);
     if (!$writable && !$modified) {
         //$message = $modified ? Loco::__('File cannot be saved to disk automatically'): Loco::__('File cannot be created automatically');
         //$warnings[] = $message.'. '.sprintf(Loco::__('Fix the file permissions on %s'),$path);
         $warnings[] = Loco::__('File cannot be created automatically. Fix the file permissions or use Download instead of Save');
     }
     // Warnings if file is empty
     if (count($data) < $minlength) {
         $lines = array();
         if ($is_pot) {
             if ($modified) {
                 // existing POT, may need sync
                 $lines[] = sprintf(Loco::__('%s file is empty'), 'POT');
                 $lines[] = Loco::__('Run Sync to update from source code');
             } else {
                 // new POT, would have tried to extract from source. Fine you can add by hand
                 $lines[] = Loco::__('No strings could be extracted from source code');
             }
         } else {
             if ($modified) {
                 $lines[] = sprintf(Loco::__('%s file is empty'), 'PO');
                 if ($haspot) {
                     // existing PO that might be updatable from POT
                     $lines[] = sprintf(Loco::__('Run Sync to update from %s'), basename($haspot));
                 } else {
                     // existing PO that might be updatable from sources
                     $lines[] = Loco::__('Run Sync to update from source code');
                 }
             } else {
                 // this shouldn't happen if we throw an error during msginit
                 throw new Exception(Loco::__('No translatable strings found'));
             }
         }
         $warnings[] = implode('. ', $lines);
     } else {
         if ($modified) {
             if ($is_pot) {
                 $sources = $package->get_source_files();
                 if ($sources && filemtime($path) < self::newest_mtime_recursive($sources)) {
                     $warnings[] = Loco::__('Source code has been modified, run Sync to update POT');
                 }
             } else {
                 if ($haspot && filemtime($haspot) > filemtime($path)) {
                     $warnings[] = Loco::__('POT has been modified since PO file was saved, run Sync to update');
                 }
             }
         }
     }
     // extract some PO headers
     if ($head instanceof LocoHeaders) {
         $proj = $head->trimmed('Project-Id-Version');
         if ($proj && 'PACKAGE VERSION' !== $proj) {
             $name = $proj;
         }
     } else {
         $head = new LocoHeaders();
     }
     // set Last-Translator if PO file
     if (!$is_pot) {
         /* @var WP_User $user */
         $user = wp_get_current_user() and $head->add('Last-Translator', $user->get('display_name') . ' <' . $user->get('user_email') . '>');
     }
     // overwrite source location headers
     // create a relative path to target source directory from location of PO
     if (!$head->has('X-Poedit-Basepath')) {
         $head->add('X-Poedit-Basepath', '.');
         foreach ($package->get_source_dirs($path) as $i => $dir) {
             $dir or $dir = '.';
             $head->add('X-Poedit-SearchPath-' . $i, $dir);
         }
     }
     // compiled keywords for running source extraction in POEdit
     // note that these aren't just wordpress keywords, but they're the same as we're using in self::xgettext
     $ext = new LocoPHPExtractor();
     $head->add('X-Poedit-KeywordsList', implode(';', $ext->get_xgettext_keywords()));
     // ensure nice name for project
     if (!isset($name)) {
         $meta = $package->meta();
         $name = $meta['name'];
     }
     $head->add('Project-Id-Version', $name);
     $headers = $head->export();
     // no longer need the full local paths
     $path = self::trim_path($path);
     // If parsing MO file, from now on treat as PO
     if (!$is_pot && self::is_mo($path)) {
         $path = str_replace('.mo', '.po', $path);
     }
     Loco::enqueue_scripts('build/admin-common', 'build/admin-poedit');
     Loco::render('admin-poedit', compact('package', 'path', 'po', 'pot', 'locale', 'headers', 'name', 'type', 'modified', 'writable', 'warnings'));
     return true;
 }
示例#2
0
<?php

/**
 * Admin options screen - changes loco plugin settings
 */
$nav = array(Loco::__('Packages') => array('href' => LocoAdmin::uri()), Loco::__('Settings') => array('icon' => 'admin-settings'));
?>

<div class="wrap loco-admin loco-settings">
    
    <?php 
Loco::render('admin-nav', compact('nav'));
?>
 
    
    <div>&nbsp;</div>
    <div class="icon32 icon-settings"><br /></div>
    <h2>
        <?php 
Loco::h(Loco::__('Configure Loco Translate'));
?>
 
    </h2>
    
    <?php 
isset($success) and LocoAdmin::success($success);
?>
 

    <form action="" method="post">
        <table class="form-table">
示例#3
0
    <div class="loco-list loco-list-plugins">
        <?php 
    Loco::render('admin-list', array('items' => $plugins));
    ?>
 
    </div><?php 
}
// Core packages
//
if ($core) {
    ?>
 
    <div class="icon32 icon-generic"><br /></div>
    <h2 class="dashicons-wordpress">
        <?php 
    Loco::h(Loco::_x('Core', 'Package list header'));
    ?>
 
    </h2>
    <div class="loco-list loco-list-core">
        <?php 
    Loco::render('admin-list', array('items' => $core));
    ?>
 
    </div><?php 
}
?>
 

</div>