Prado\I18N\core\Gettext\TGettext::factory PHP Метод

factory() статический публичный Метод

Factory
static public factory ( string $format, string $file = '' ) : object
$format string MO or PO
$file string path to GNU gettext file
Результат object Returns File_Gettext_PO or File_Gettext_MO on success or PEAR_Error on failure.
    static function factory($format, $file = '')
    {
        $format = strToUpper($format);
        $filename = dirname(__FILE__) . '/' . $format . '.php';
        if (is_file($filename) == false) {
            throw new Exception("Class file {$file} not found");
        }
        include_once $filename;
        $class = 'TGettext_' . $format;
        return new $class($file);
    }

Usage Example

Пример #1
0
 protected function createMessageTemplate($catalogue)
 {
     if ($catalogue === null) {
         $catalogue = 'messages';
     }
     $variants = $this->getCatalogueList($catalogue);
     $variant = array_shift($variants);
     $mo_file = $this->getSource($variant);
     $po_file = $this->getPOFile($mo_file);
     $dir = dirname($mo_file);
     if (!is_dir($dir)) {
         @mkdir($dir);
         @chmod($dir, PRADO_CHMOD);
     }
     if (!is_dir($dir)) {
         throw new TException("Unable to create directory {$dir}");
     }
     $po = TGettext::factory('PO', $po_file);
     $result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s');
     $result['strings'] = array();
     $po->fromArray($result);
     $mo = $po->toMO();
     if ($po->save() && $mo->save($mo_file)) {
         return array($variant, $mo_file, $po_file);
     } else {
         throw new TException("Unable to create file {$po_file} and {$mo_file}");
     }
 }