/** * Execute native msgfmt command * @param string po source * @return string binary mo source */ public static function msgfmt_native($po) { try { $conf = Loco::config(); loco_require('build/gettext-compiled'); $gen_hash = (bool) $conf['gen_hash']; $use_fuzzy = (bool) $conf['use_fuzzy']; $mo = loco_msgfmt($po, $gen_hash, $use_fuzzy); } catch (Exception $Ex) { error_log($Ex->getMessage(), 0); } if (!$mo) { throw new Exception(sprintf(Loco::__('Failed to compile MO file with built-in compiler'))); } return $mo; }
<?php /** * Admin ajax action wrapper */ try { // no errors ruining json response please if (false === ini_set('display_errors', 0)) { error_reporting(0); } if (!function_exists('current_user_can') || !class_exists('LocoAdmin')) { throw new Exception('Ajax action only'); } if (!current_user_can(Loco::CAPABILITY)) { throw new Exception(Loco::__('User does not have permission to manage translations'), 403); } $incphp = isset($action) ? dirname(__FILE__) . '/' . $action . '.php' : ''; if (!$incphp || !file_exists($incphp)) { throw new Exception('Bad Ajax action'); } // Ajax action can only exit 200 try { $response = (include $incphp); } catch (Exception $Ex) { $response = array('error' => array('code' => $Ex->getCode(), 'message' => $Ex->getMessage())); } if (!is_array($response)) { throw new Exception('Ajax action did not return a response'); } // json ok $body = json_encode($response);
/** * Get a package - from cache if possible * @param string unique name or identifier known to WordPress * @param string "core", "theme" or "plugin" * @return LocoPackage */ public static function get($handle, $type) { $key = $type . '_' . $handle; $package = Loco::cached($key); if ($package instanceof LocoPackage) { if ($package->invalidate()) { $package = null; } } if (!$package instanceof LocoPackage) { $getter = array(__CLASS__, 'get_' . $type); $package = call_user_func($getter, $handle); if ($package) { $package->meta(); Loco::cache($key, $package); } } return $package; }
<?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); } }
"> <?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 get_name() { return empty($this->label) ? Loco::__('Unknown language') : $this->label; }
?> /loco-fail.php" id="loco-filter"> <div class="loco-clearable"> <input type="text" maxlength="100" name="q" id="loco-search" placeholder="<?php Loco::h(Loco::__('Filter translations')); ?> " autocomplete="off" disabled /> </div> </form> <form action="http://wordpress.org/support/plugin/<?php echo Loco::NS; ?> " target="_blank" class="loco-right"> <button class="button loco-help" data-loco="help" type="submit"> <span><?php Loco::h(Loco::_x('Help', 'Editor button')); ?> </span> </button> </form> </nav> <div id="loco-poedit-inner" class="loco-editor loading"> <span>Loading..</span> </div> </div> <script> loco = window.loco || {};
// 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; } }*/ $exp[0] = array(); }
// 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;
<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>
<?php /** * Admin ajax include that returns compiled-in data * Included by loco-ajax.php during Ajax action */ DOING_AJAX or die; // default is single locale response if (isset($locale)) { loco_require('loco-locales'); $data = loco_locale_resolve($locale); return array('locales' => array($locale => $data->export())); } throw new Exception(Loco::__('Invalid data posted to server'), 422);
try { loco_require('build/shell-compiled'); define('WHICH_MSGFMT', $msgfmt); // use temp file if possible, due to stdin size restrictions if ($popath = tempnam(sys_get_temp_dir(), 'loco-')) { register_shutdown_function('unlink', $popath); file_put_contents($popath, $po); $mopath = loco_compile_mo_file($popath, $mopath); register_shutdown_function('unlink', $mopath); $mo = file_get_contents($mopath); } else { $mo = loco_compile_mo($po); } } catch (Exception $Ex) { error_log($Ex->getMessage(), 0); } if (!$mo) { throw new Exception(sprintf(Loco::__('Failed to compile MO file with %s, check your settings'), WHICH_MSGFMT)); } } else { $mo = LocoAdmin::msgfmt_native($po); } // exit with binary MO header('Content-Type: application/x-gettext-translation; charset=UTF-8', true); header('Content-Length: ' . strlen($mo), true); header('Content-Disposition: attachment; filename=' . $name, true); echo $mo; exit(0); } catch (Exception $Ex) { require dirname(__FILE__) . '/loco-fatal.php'; }
</li><?php } ?> </ul> </td> <td> <ul><?php try { $package->check_permissions(); ?> <li class="loco-ok"> <?php echo LocoAdmin::fscheck_link($package, $domain, Loco::__('OK')); ?> </li><?php } catch (Exception $Ex) { ?> <li class="loco-warning"> <?php echo LocoAdmin::fscheck_link($package, $domain, $Ex->getMessage()); ?> </li><?php } ?>
<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> </div>
/** * Abstract enquement of Stylesheets */ public static function enqueue_styles() { static $v, $i = 0; isset($v) or $v = WP_DEBUG ? time() : Loco::VERSION; foreach (func_get_args() as $stub) { $css = Loco::baseurl() . '/pub/css/' . $stub . '.css'; wp_enqueue_style(self::NS . '-css-' . ++$i, $css, array(), $v); } }
</li><?php } ?> </ul> </td> <td> <ul><?php 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 } ?>
public function testDefaultAdminCapabilityIsManageOptions() { $this->assertSame('manage_options', Loco::admin_capablity()); }
</legend> <p> <label for="loco--enable-core"> <input type="checkbox" name="loco[enable_core]" value="1" id="loco--enable-core"<?php echo $enable_core ? ' checked' : ''; ?> /> <?php Loco::h(Loco::__('Enable WordPress core translations')); ?> </label> </p> </fieldset> </td> </tr> </tbody> </table> <p class="submit"> <input type="submit" class="button-primary" value="<?php Loco::h(Loco::__('Save settings')); ?> " /> <a class="button" href="https://localise.biz/help/wordpress/translate-plugin/support" target="_blank"><?php Loco::h(Loco::__('Get help')); ?> </a> </p> </form> </div>
<?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")); }