当前位置: 首页>>代码示例>>PHP>>正文


PHP parent::load_tables方法代码示例

本文整理汇总了PHP中parent::load_tables方法的典型用法代码示例。如果您正苦于以下问题:PHP parent::load_tables方法的具体用法?PHP parent::load_tables怎么用?PHP parent::load_tables使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在parent的用法示例。


在下文中一共展示了parent::load_tables方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: buildHashFile

 /**
  * buildHashFile
  *
  * This constructs a file, usually named something.mo.php, which will
  * contain a PHP hash array literal. The literal can be included later
  * and used by this class to provide a translation via functions
  * declared below such as __()
  */
 static function buildHashFile($mofile, $outfile = false, $return = false)
 {
     if (!$outfile) {
         $stream = fopen('php://stdout', 'w');
     } elseif (is_string($outfile)) {
         $stream = fopen($outfile, 'w');
     } elseif (is_resource($outfile)) {
         $stream = $outfile;
     }
     if (!$stream) {
         throw new InvalidArgumentException('Expected a filename or valid resource');
     }
     if (!$mofile instanceof FileReader) {
         $mofile = new FileReader($mofile);
     }
     $reader = new parent($mofile, true);
     if ($reader->short_circuit || $reader->error) {
         throw new Exception('Unable to initialize MO input file');
     }
     $reader->load_tables();
     // Get basic table
     if (!($table = $reader->cache_translations)) {
         throw new Exception('Unable to read translations from file');
     }
     // Transcode the table to UTF-8
     $header = $table[""];
     $info = array();
     preg_match('/^content-type: (.*)$/im', $header, $info);
     $charset = false;
     if ($content_type = $info[1]) {
         // Find the charset property
         $settings = explode(';', $content_type);
         foreach ($settings as $v) {
             @(list($prop, $value) = explode('=', trim($v), 2));
             if (strtolower($prop) == 'charset') {
                 $charset = trim($value);
                 break;
             }
         }
     }
     if ($charset && strcasecmp($charset, 'utf-8') !== 0) {
         foreach ($table as $orig => $trans) {
             // Format::encode defaults to UTF-8 output
             $source = new Unicode($orig, $charset);
             $trans = new Unicode($trans, $charset);
             $table[(string) $source->encode('utf-8')] = (string) $trans->encode('utf-8');
             unset($table[$orig]);
         }
     }
     // Add in some meta-data
     $table[self::META_HEADER] = array('Revision' => $reader->revision, 'Total-Strings' => $reader->total, 'Table-Size' => count($table), 'Build-Timestamp' => gmdate(DATE_RFC822), 'Format-Version' => 'A', 'Encoding' => 'UTF-8');
     // Serialize the PHP array and write to output
     $contents = sprintf('<?php return %s;', var_export($table, true));
     if ($return) {
         return $contents;
     } else {
         fwrite($stream, $contents);
     }
 }
开发者ID:iHunt101,项目名称:phlite,代码行数:67,代码来源:Translation.php


注:本文中的parent::load_tables方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。