예제 #1
0
파일: UtilsTest.php 프로젝트: epiii/aros
 public function test_resolve_file_domain()
 {
     $domain = LocoAdmin::resolve_file_domain('/foo.pot');
     $this->assertEquals('foo', $domain);
     $domain = LocoAdmin::resolve_file_domain('/foo-en_GB.po');
     $this->assertEquals('foo', $domain);
     $domain = LocoAdmin::resolve_file_domain('/foo-en.po');
     $this->assertEquals('foo', $domain);
 }
예제 #2
0
// path is allowed to not exist yet
if ('/' !== $path[0]) {
    $path = WP_CONTENT_DIR . '/' . $path;
}
// but package must exist so we can get POT or source
/* @var $package LocoPackage */
loco_require('loco-packages', 'loco-locales');
$package = LocoPackage::get($name, $type);
if (!$package) {
    throw new Exception(sprintf(Loco::__('Package not found called %s'), $name), 404);
}
while (true) {
    // If file we're syncing is POT, we can only sync from sources
    if (!LocoAdmin::is_pot($path)) {
        // if a POT file exists, sync from that
        $domain = LocoAdmin::resolve_file_domain($path) or $domain = $package->get_domain();
        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'));
    }
예제 #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, '/\\.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;
 }
예제 #4
0
 public function testLanguageCodeSeparatesFromDomainByHyphen()
 {
     $domain = LocoAdmin::resolve_file_domain('/foo-en.po');
     $this->assertEquals('foo', $domain);
 }
예제 #5
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;
 }
예제 #6
0
 public function testInvalidLanguageCodeNotUsedAsDomainWhenPot()
 {
     $domain = LocoAdmin::resolve_file_domain('/en_EN.pot');
     $this->assertSame('', $domain);
 }