示例#1
0
 public function testValidWordpressLocales()
 {
     // regionless
     $this->assertTrue(LocoLocale::is_valid_wordpress('th'), '"th" should be a valid WP locale ');
     $this->assertFalse(LocoLocale::is_valid_wordpress('th_TH'), 'th_TH is not valid, it should be "th"');
     $this->assertFalse(LocoLocale::is_valid_wordpress('TH'), '"TH" should be invalid due to uppercasing');
     // regionfull
     $this->assertTrue(LocoLocale::is_valid_wordpress('fr_FR'), '"fr_FR" should be a valid WP locale ');
     $this->assertFalse(LocoLocale::is_valid_wordpress('fr'), 'fr is not valid, it should be "fr_FR"');
     $this->assertFalse(LocoLocale::is_valid_wordpress('FR'), '"FR" should be invalid due to uppercasing');
     // three characters official
     $this->assertTrue(LocoLocale::is_valid_wordpress('bel'), '"bel" should be a valid WP locale ');
     $this->assertTrue(LocoLocale::is_valid_wordpress('rup_MK'), '"rup_MK" should be a valid WP locale ');
 }
示例#2
0
 /**
  * Admin diagnostics page render call
  */
 public static function render_page_diagnostics()
 {
     self::check_capability();
     loco_require('loco-locales', 'loco-packages');
     // global data
     global $wp_version;
     $user = wp_get_current_user();
     // collect data about Loco plugin
     $config = Loco::config();
     $caching = Loco::$cache_enabled ? Loco::$apc_enabled ? 'APC' : 'WP' : 'Off';
     // collect data about current theme
     $theme = wp_get_theme();
     $package = LocoPackage::get($theme->get_stylesheet(), 'theme');
     $theme_locale = apply_filters('theme_locale', get_locale(), $theme->get('TextDomain'));
     // collect data about all plugins
     $plugins = array();
     foreach (get_plugins() as $plugin_file => $plugin) {
         $package = LocoPackage::get($plugin_file, 'plugin') and $plugins[$package->get_name()] = $package->get_domain();
     }
     // check if locale is a valid WordPress language code
     if (!LocoLocale::is_valid_wordpress($theme_locale)) {
         self::warning(sprintf(Loco::__('%s is not an official WordPress language'), $theme_locale));
     }
     $args = compact('wp_version', 'theme', 'theme_locale', 'package', 'config', 'caching', 'user', 'plugins');
     Loco::enqueue_scripts('build/admin-common', 'debug');
     Loco::render('admin-debug', $args);
 }
示例#3
0
 /**
  * Get package errors, or things that may cause problems displaying translations
  */
 public function get_author_warnings()
 {
     $warn = array();
     $type = $this->get_type();
     if ('core' !== $type) {
         $camelType = strtoupper($type[0]) . substr($type, 1);
         // check package declares Text Domain
         $domain = $this->get_original('TextDomain');
         if (!$domain) {
             $domain = $this->get_domain();
             $warn[] = sprintf(Loco::__('%s does not declare a "Text Domain"'), $camelType) . ' .. ' . sprintf(Loco::__('Loco has guessed "%s"'), $domain);
         }
         // check package declares "Domain Path"
         $path = $this->get_original('Domain Path');
         if (!$domain) {
             $warn[] = sprintf(Loco::__('%s does not declare a "Domain Path"'), $camelType) . ' .. ' . sprintf(Loco::__('Loco has guessed "%s"'), $this->domainpath);
         }
         // check POT exists and looks correct
         $path = $this->get_pot($domain);
         if (!$path) {
             $warn[] = sprintf(Loco::__('%s has no POT file. Create one at "%s/%s.pot" if you need one.'), $camelType, $this->domainpath, $domain);
         } else {
             if ($domain . '.pot' !== basename($path)) {
                 $warn[] = sprintf(Loco::__('%s has a strange POT file name (%s). A better name would be "%s.pot"'), $camelType, basename($path), $domain);
             }
         }
         // TODO check references to other domains in xgettext
     }
     // Check if any locale codes are not an official WordPress languages
     $meta = $this->meta();
     foreach ($meta['po'] as $po_data) {
         $wplang = $po_data['locale']->get_code() or $wplang = $po_data['locale']->get_name();
         if (!LocoLocale::is_valid_wordpress($wplang)) {
             $warn[] = sprintf(Loco::__('%s is not an official WordPress language'), $wplang);
         }
     }
     return $warn;
 }