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()); }
<?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>
/** * 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; }
/** * 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; }
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;
?> </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>
<?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); } }
public function testLanguageCodeSeparatesFromDomainByHyphen() { $domain = LocoAdmin::resolve_file_domain('/foo-en.po'); $this->assertEquals('foo', $domain); }
<p> <label for="f-loco-locale"> – <?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
public function testFindGrouped() { $files = LocoAdmin::find_po(WP_CONTENT_DIR . '/themes/twentyfourteen/languages'); $this->assertStringEndsWith('twentyfourteen.pot', $files['pot'][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'); }
"> <?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]-->
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); }
<?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>
<?php } ?> </span> — <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);
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>
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]); }
/** * 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; }
public function testInvalidLanguageCodeNotUsedAsDomainWhenPot() { $domain = LocoAdmin::resolve_file_domain('/en_EN.pot'); $this->assertSame('', $domain); }
/** * 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(); }
$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;
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>
// 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;
<?php Loco::render('admin-nav', compact('nav')); ?> <div> </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
<?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")); }