예제 #1
0
파일: UtilsTest.php 프로젝트: epiii/aros
 public function test_resolve_file_locale()
 {
     $locale = LocoAdmin::resolve_file_locale('/foo-en.po');
     $this->assertEquals('en_GB', $locale->get_code());
     $locale = LocoAdmin::resolve_file_locale('/foo-ja.po');
     $this->assertEquals('ja_JP', $locale->get_code());
 }
예제 #2
0
<?php

/**
 * Root admin screen - lists available themes and plugins
 */
$nav = array(Loco::__('Packages') => '', Loco::__('Settings') => LocoAdmin::uri(array(), 'settings'));
?>
 

<div class="wrap loco-admin loco-lists"><?php 
// show upgrade notice if available
if (isset($update)) {
    ?>
 
    <div class="loco-message updated loco-warning">
        <p>
            <strong>
                <?php 
    Loco::h(Loco::__('New version available'));
    ?>
:
            </strong>
            <a href="http://wordpress.org/extend/plugins/<?php 
    echo Loco::NS;
    ?>
">
                <?php 
    Loco::h(Loco::__('Upgrade to version %s of Loco Translate'), $update);
    ?>
            </a>
        </p>
예제 #3
0
 /**
  * construct a core package object from name
  * @return LocoPackage
  */
 private static function get_core($handle)
 {
     static $grouped;
     if (!isset($grouped)) {
         $grouped = array();
         foreach (LocoAdmin::find_grouped(WP_LANG_DIR . '/*{.po,.pot}', GLOB_NOSORT | GLOB_BRACE) as $ext => $files) {
             foreach ($files as $path) {
                 $domain = LocoAdmin::resolve_file_domain($path);
                 $grouped[$domain][$ext][] = $path;
             }
         }
     }
     $domain = $handle or $domain = 'default';
     $package = new LocoCorePackage($handle, $domain, '');
     if (isset($grouped[$handle])) {
         $package->add_po($grouped[$handle], $domain);
         // get name from po file
         $meta = $package->meta();
         foreach ($meta['po'] as $pmeta) {
             if ($pmeta['projid']) {
                 $package->name = $pmeta['projid'];
             }
         }
     }
     return $package;
 }
예제 #4
0
파일: loco-admin.php 프로젝트: epiii/aros
/**
 * extra visibility of settings link
 */
function _loco_hook__plugin_row_meta($links, $file = '')
{
    if (false !== strpos($file, '/loco.php')) {
        $links[] = '<a href="' . Loco::html(LocoAdmin::uri(array(), '')) . '"><strong>' . Loco::__('Manage translations') . '</strong></a>';
        $links[] = '<a href="' . Loco::html(LocoAdmin::uri(array(), 'settings')) . '"><strong>' . Loco::__('Settings') . '</strong></a>';
    }
    return $links;
}
예제 #5
0
        if ($pot_path = $package->get_pot($domain)) {
            $exp = LocoAdmin::parse_po($pot_path);
            if (!$exp || 1 === count($exp) && '' === $exp[0]['source']) {
                // throw new Exception( Loco::__('POT file is empty').' - '.basename($pot_path) );
                // fall through to try source code
            } else {
                $pot = basename($pot_path);
                break;
            }
        }
    }
    // Extract from sources by default
    if (!$package->has_source_dirs()) {
        throw new Exception(Loco::__('No source directories in this package, cannot sync from source code'));
    }
    if ($exp = LocoAdmin::xgettext($package, dirname($path))) {
        $pot = '';
        break;
    }
    throw new Exception(Loco::__('No strings could be extracted from source files'));
}
// sync selected headers
$headers = array();
if ('' === $exp[0]['source']) {
    $keep = array('Project-Id-Version', 'Language-Team', 'POT-Creation-Date', 'POT-Revision-Date');
    $head = loco_parse_po_headers($exp[0]['target']);
    $headers = array_intersect_key($head->to_array(), array_flip($keep));
    /*/ add prefixed header keys that can't be included above
      foreach( $head as $key => $value ){
          if( 0 === strpos($key, 'X-Poedit-' ) ){
              $headers[$key] = $value;
예제 #6
0
    ?>
 
            </label>
            <br />
            <label>
                <input type="radio" name="gforce" value="1"<?php 
    print $is_global ? ' checked' : '';
    print $gdir_ok ? '' : ' disabled';
    ?>
 />
                <?php 
    Loco::h(Loco::_x('create in global languages directory', 'Form label'));
    ?>
 
                <code><?php 
    Loco::h(LocoAdmin::trim_path($gdir));
    ?>
/</code>
            </label>
        </p><?php 
}
?>
 

        <p class="submit">
            <input type="submit" value="<?php 
Loco::h(Loco::_x('Start translating', 'Submit button'));
?>
" class="button button-primary button-large" disabled />
        </p>
    </form>
예제 #7
0
파일: loco-json.php 프로젝트: jonpalma/bcc
<?php

/**
 * Polyfiller for missing PHP json extension.
 * Simply avoids fatal errors. Doesn't attempt to really replace the functionality
 */
function loco_compat_json_encode($value)
{
    return '{"error":{"code":-1,"message":"json extension is not installed"}}';
}
if (!extension_loaded('json_encode') && WP_DEBUG && (!defined('DOING_AJAX') || !DOING_AJAX)) {
    LocoAdmin::warning(sprintf(Loco::__('PHP extension "%s" is not installed. If you experience problems you should install it'), 'json_encode'));
}
if (!function_exists('json_encode')) {
    function json_encode($value = '')
    {
        return loco_compat_json_encode($value);
    }
}
예제 #8
0
 public function testLanguageCodeSeparatesFromDomainByHyphen()
 {
     $domain = LocoAdmin::resolve_file_domain('/foo-en.po');
     $this->assertEquals('foo', $domain);
 }
예제 #9
0
        <p>
            <label for="f-loco-locale">
                &ndash;
                <?php 
Loco::h(Loco::_x('or enter any language code', 'Form label'));
?>
:
                <br />
            </label>
            <input type="text" maxlength="6" size="5" pattern="^[a-zA-Z]{2,3}([\-_][a-zA-Z]{2})?$" name="custom-locale" for="f-loco-locale" placeholder="xx_XX" />
            <span class="flag"></span>
        </p><?php 
// provide location choice if package and global dirs are both writable
if (is_writeable($pdir) && is_writable($gdir)) {
    $is_global = $package->is_global_path($path);
    $pdir = LocoAdmin::trim_path($pdir);
    ?>
 
        <p>
            <label>
                <input type="radio" name="gforce" value="0"<?php 
    print $is_global ? '' : ' checked';
    ?>
 />
                <?php 
    echo sprintf(Loco::_x('create in <code>%s</code>', 'Form label'), $pdir);
    ?>
            </label>
            <br />
            <label>
                <input type="radio" name="gforce" value="1"<?php 
예제 #10
0
 public function testFindGrouped()
 {
     $files = LocoAdmin::find_po(WP_CONTENT_DIR . '/themes/twentyfourteen/languages');
     $this->assertStringEndsWith('twentyfourteen.pot', $files['pot'][0]);
 }
예제 #11
0
 public function testUnknownThreeCharacterLanguageIgnored()
 {
     $locale = LocoAdmin::resolve_file_locale('/foo-th.po');
     // If "foo" was treated as a language this would give invalid locale "foo_TH".
     $this->assertEquals('th', $locale->get_code(), '"foo" is not a valid langauge, but "th" is');
 }
예제 #12
0
">
                <?php 
        Loco::h($label);
        ?>
 
            </a><?php 
    }
}
?>
 

        <a href="https://localise.biz/about/gettext?<?php 
Loco::h(Loco::utm_query('nav'));
?>
" class="nav-tab nav-tab-loco" target="_blank">
            <?php 
Loco::h(Loco::__('Powered by'));
?>
 
            <?php 
Loco::h(Loco::__('Loco, Translation Management'));
?>
 
        </a>
    </h2>
    
    <!--[if lt IE 9]><?php 
LocoAdmin::warning(__($ignore = 'Your browser is out of date!') . ' ' . Loco::html(Loco::__('Loco may not work as expected')));
?>
<![endif]-->
예제 #13
0
파일: UriTest.php 프로젝트: Makenrro/repos
 public function testDefaultPageWithParameters()
 {
     $args = array('foo' => 'bar-baz');
     $uri = LocoAdmin::uri($args);
     $this->assertEquals('http://test/wp-admin/admin.php?foo=bar-baz&page=loco-translate', $uri);
 }
예제 #14
0
<?php

/**
 * Root admin screen - lists available themes and plugins
 */
$nav = array(Loco::__('Packages') => array(), Loco::__('Settings') => array('href' => LocoAdmin::uri(array(), 'settings'), 'icon' => 'admin-settings'));
?>
 

<div class="wrap loco-admin loco-lists"><?php 
// show upgrade notice if available
if (isset($update)) {
    ?>
 
    <div class="loco-message updated loco-warning">
        <p>
            <strong>
                <?php 
    Loco::h(Loco::__('New version available'));
    ?>
:
            </strong>
            <a href="http://wordpress.org/extend/plugins/<?php 
    echo Loco::NS;
    ?>
">
                <?php 
    Loco::h(Loco::__('Upgrade to version %s of Loco Translate'), $update);
    ?>
            </a>
        </p>
예제 #15
0
            <?php 
}
?>
 
            </span>
            &mdash;
            <span id="loco-po-status">
                <!-- js will load status -->
            </span>
        </span>
    </h3>
    
    
    <?php 
foreach ($warnings as $text) {
    LocoAdmin::warning($text);
}
?>
 
    
    
    <div id="loco-poedit">
        
        <nav id="loco-nav" class="wp-core-ui">
            <form action="<?php 
echo $phpbase;
?>
/loco-fail.php" method="post">
                <input type="hidden" name="po" value="" />
                <input type="hidden" name="path" value="<?php 
Loco::h($path);
예제 #16
0
        Loco::h($error);
        ?>
</span>
        </li><?php 
    }
    ?>
 
    </ul><?php 
}
?>
 
    
    
    <p class="submit">
        <a class="button-primary" href="<?php 
Loco::h(LocoAdmin::uri());
?>
"><?php 
Loco::h(Loco::__('Back'));
?>
</a>
        <a class="button" href="http://wordpress.org/support/plugin/<?php 
echo Loco::NS;
?>
" target="_blank"><?php 
Loco::h(Loco::__('Get help'));
?>
</a>
    </p>

    
예제 #17
0
 public function testFindGrouped()
 {
     $pattern = WP_CONTENT_DIR . '/themes/twentyfourteen/languages/*{.po,.pot}';
     $files = LocoAdmin::find_grouped($pattern, GLOB_NOSORT | GLOB_BRACE);
     $this->assertStringEndsWith('twentyfourteen.pot', $files['pot'][0]);
 }
예제 #18
0
 /**
  * construct a core package object from name
  * @return LocoPackage
  */
 private static function get_core($handle)
 {
     static $grouped;
     if (!isset($grouped)) {
         $grouped = array();
         foreach (LocoAdmin::find_grouped(WP_LANG_DIR, '/\\.pot?$/') as $ext => $files) {
             foreach ($files as $path) {
                 $domain = LocoAdmin::resolve_file_domain($path);
                 $grouped[$domain][$ext][] = $path;
             }
         }
     }
     $domain = $handle or $domain = 'default';
     $package = new LocoCorePackage($handle, $domain, '');
     if (isset($grouped[$handle])) {
         // add PO file and POT files for this component
         $package->add_po($grouped[$handle], $domain);
         // get name from po file
         $meta = $package->meta();
         foreach ($meta['po'] as $pmeta) {
             if ($pmeta['projid']) {
                 $package->name = $pmeta['projid'];
             }
         }
         // disable source directories as Core packages cannot be synced
         $package->src = array();
     }
     return $package;
 }
예제 #19
0
 public function testInvalidLanguageCodeNotUsedAsDomainWhenPot()
 {
     $domain = LocoAdmin::resolve_file_domain('/en_EN.pot');
     $this->assertSame('', $domain);
 }
예제 #20
0
/**
 * callback when admin notices are being printed
 */
function _loco_hook_admin_notices()
{
    if (defined('WPLANG') && LocoAdmin::is_self() && WPLANG && 3 < (int) $GLOBALS['wp_version']) {
        LocoAdmin::warning(Loco::__('WPLANG is deprecated and should be removed from wp-config.php'));
    }
    LocoAdmin::flush_notices();
}
예제 #21
0
파일: loco-posync.php 프로젝트: epiii/aros
            $exp = LocoAdmin::parse_po($pot_path);
            if (!$exp || 1 === count($exp) && '' === $exp[0]['source']) {
                //throw new Exception( Loco::__('POT file is empty') );
                continue;
            }
            $pot = basename($pot_path);
            break;
        }
    }
    // Extract from sources by default
    if (!$package->get_source_dirs()) {
        throw new Exception(Loco::__('No source files in this package, nothing to sync'));
    }
    $relative_to = dirname($path);
    //$relative_to = $pot_path ? dirname($pot_path) : $package->get_root();
    if ($exp = LocoAdmin::xgettext($package, $relative_to)) {
        $pot = '';
        break;
    }
    throw new Exception(Loco::__('No strings could be extracted from source files'));
}
// sync selected headers
$headers = array();
if ('' === $exp[0]['source']) {
    $keep = array('Project-Id-Version', 'Language-Team', 'POT-Creation-Date', 'POT-Revision-Date');
    $head = loco_parse_po_headers($exp[0]['target']);
    $headers = array_intersect_key($head->to_array(), array_flip($keep));
    /*/ add prefixed header keys that can't be included above
      foreach( $head as $key => $value ){
          if( 0 === strpos($key, 'X-Poedit-' ) ){
              $headers[$key] = $value;
예제 #22
0
    try {
        $package->check_permissions();
        ?>
 
                            <li class="loco-ok">
                                <?php 
        echo LocoAdmin::fscheck_link($package, $domain, Loco::_x('OK', 'Message label'));
        ?>
 
                            </li><?php 
    } catch (Exception $Ex) {
        ?>
 
                            <li class="loco-warning">
                                <?php 
        echo LocoAdmin::fscheck_link($package, $domain, $Ex->getMessage());
        ?>
 
                            </li><?php 
    }
    ?>
 
                        </ul>
                    </td>
                </tr><?php 
}
?>
 
            </tbody>
        </table>
        
예제 #23
0
        // attempt to compile MO direct to file via shell
        if ($msgfmt = LocoAdmin::msgfmt_command()) {
            try {
                $bytes = 0;
                loco_require('build/shell-compiled');
                define('WHICH_MSGFMT', $msgfmt);
                $mopath = loco_compile_mo_file($path, $mopath);
                $bytes = $mopath && file_exists($mopath) ? filesize($mopath) : 0;
            } catch (Exception $Ex) {
                error_log($Ex->getMessage(), 0);
            }
            if (!$bytes) {
                throw new Exception(sprintf(Loco::__('Failed to compile MO file with %s, check your settings'), WHICH_MSGFMT));
            }
            $response['compiled'] = $bytes;
            break;
        }
        // Fall back to in-built MO compiler - requires PO is parsed too
        $mo = LocoAdmin::msgfmt_native($po);
        $bytes = file_put_contents($mopath, $mo);
        if (!$bytes) {
            throw new Exception(Loco::__('Failed to write MO file'));
        }
        $response['compiled'] = $bytes;
        break;
    } catch (Exception $e) {
        $response['compiled'] = $e->getMessage();
        break;
    }
}
return $response;
예제 #24
0
    <?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">
            <tbody>
                <tr valign="top">
                    <th scope="row"><?php 
Loco::h(Loco::__('Compiling MO files'));
?>
</th>
                    <td>
                        <fieldset>
                            <legend class="screen-reader-text">
                                <span><?php 
예제 #25
0
<?php

/**
 * Warns about missing PHP glob functionality under Solaris
 */
if (!defined('GLOB_BRACE') && (!defined('DOING_AJAX') || !DOING_AJAX)) {
    define('GLOB_BRACE', 0);
    LocoAdmin::warning(Loco::__("Loco Translate will not work properly on this server's operating system"));
}