本文整理汇总了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;
}