當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Translations::fromPhpCodeFile方法代碼示例

本文整理匯總了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;
 }
開發者ID:ppiedaderawnet,項目名稱:concrete5,代碼行數:41,代碼來源:Php.php


注:本文中的Gettext\Translations::fromPhpCodeFile方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。