本文整理匯總了PHP中Gettext\Translations::fromPhpCodeFile方法的典型用法代碼示例。如果您正苦於以下問題:PHP Translations::fromPhpCodeFile方法的具體用法?PHP Translations::fromPhpCodeFile怎麽用?PHP Translations::fromPhpCodeFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Gettext\Translations
的用法示例。
在下文中一共展示了Translations::fromPhpCodeFile方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: parseDirectoryDo_php
/**
* Extracts translatable strings from PHP files with xgettext.
*
* @param string $rootDirectory The base root directory
* @param array[string] $phpFiles The relative paths to the PHP files to be parsed
*
* @throws \Exception Throws an \Exception in case of problems
*
* @return \Gettext\Translations
*/
protected static function parseDirectoryDo_php($rootDirectory, $phpFiles)
{
$prefix = $rootDirectory . '/';
$originalExtractComments = \Gettext\Extractors\PhpCode::$extractComments;
\Gettext\Extractors\PhpCode::$extractComments = 'i18n';
$originalFunctions = \Gettext\Extractors\PhpCode::$functions;
\Gettext\Extractors\PhpCode::$functions['t'] = '__';
\Gettext\Extractors\PhpCode::$functions['t2'] = 'n__';
\Gettext\Extractors\PhpCode::$functions['tc'] = 'p__';
try {
$absFiles = array_map(function ($phpFile) use($prefix) {
return $prefix . $phpFile;
}, $phpFiles);
$newTranslations = \Gettext\Translations::fromPhpCodeFile($absFiles);
\Gettext\Extractors\PhpCode::$extractComments = $originalExtractComments;
\Gettext\Extractors\PhpCode::$functions = $originalFunctions;
} catch (\Exception $x) {
\Gettext\Extractors\PhpCode::$extractComments = $originalExtractComments;
\Gettext\Extractors\PhpCode::$functions = $originalFunctions;
throw $x;
}
$startAt = strlen($prefix);
foreach ($newTranslations as $newTranslation) {
$references = $newTranslation->getReferences();
$newTranslation->deleteReferences();
foreach ($references as $reference) {
$newTranslation->addReference(substr($reference[0], $startAt), $reference[1]);
}
}
return $newTranslations;
}