本文整理匯總了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);
}
}