2008-05-30 11:40:08 +00:00
< ? php
/**
2009-09-15 03:43:59 +00:00
* Language string extractor
2008-05-30 11:40:08 +00:00
*
2010-10-03 16:38:58 +00:00
* PHP 5
2008-05-30 11:40:08 +00:00
*
2009-11-06 06:46:59 +00:00
* CakePHP ( tm ) : Rapid Development Framework ( http :// cakephp . org )
2010-01-26 19:18:20 +00:00
* Copyright 2005 - 2010 , Cake Software Foundation , Inc . ( http :// cakefoundation . org )
2008-05-30 11:40:08 +00:00
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice .
*
2010-01-26 19:18:20 +00:00
* @ copyright Copyright 2005 - 2010 , Cake Software Foundation , Inc . ( http :// cakefoundation . org )
2009-11-06 06:00:11 +00:00
* @ link http :// cakephp . org CakePHP ( tm ) Project
2008-10-30 17:30:26 +00:00
* @ package cake
* @ subpackage cake . cake . console . libs
* @ since CakePHP ( tm ) v 1.2 . 0.5012
2009-11-06 06:51:51 +00:00
* @ license MIT License ( http :// www . opensource . org / licenses / mit - license . php )
2008-05-30 11:40:08 +00:00
*/
2010-06-21 03:23:56 +00:00
App :: import ( 'Core' , 'File' );
2008-05-30 11:40:08 +00:00
/**
* Language string extractor
*
2008-10-30 17:30:26 +00:00
* @ package cake
2009-09-15 03:43:59 +00:00
* @ subpackage cake . cake . console . libs . tasks
2008-05-30 11:40:08 +00:00
*/
2009-09-15 03:43:59 +00:00
class ExtractTask extends Shell {
2009-07-24 19:18:37 +00:00
2008-05-30 11:40:08 +00:00
/**
2009-09-15 03:43:59 +00:00
* Paths to use when looking for strings
2008-05-30 11:40:08 +00:00
*
* @ var string
2009-09-15 03:43:59 +00:00
* @ access private
2008-05-30 11:40:08 +00:00
*/
2010-04-04 06:33:39 +00:00
private $__paths = array ();
2009-07-24 19:18:37 +00:00
2008-05-30 11:40:08 +00:00
/**
* Files from where to extract
*
* @ var array
* @ access private
*/
2010-04-04 06:33:39 +00:00
private $__files = array ();
2009-07-24 19:18:37 +00:00
2009-10-29 23:26:59 +00:00
/**
* Merge all domains string into the default . pot file
*
* @ var boolean
2009-11-02 23:54:03 +00:00
* @ access private
2009-10-29 23:26:59 +00:00
*/
2010-04-04 06:33:39 +00:00
private $__merge = false ;
2009-10-29 23:26:59 +00:00
2008-05-30 11:40:08 +00:00
/**
2009-09-15 03:43:59 +00:00
* Current file being processed
2008-05-30 11:40:08 +00:00
*
2009-09-15 03:43:59 +00:00
* @ var string
2008-05-30 11:40:08 +00:00
* @ access private
*/
2010-04-04 06:33:39 +00:00
private $__file = null ;
2009-07-24 19:18:37 +00:00
2008-05-30 11:40:08 +00:00
/**
2009-09-15 03:43:59 +00:00
* Contains all content waiting to be write
2008-05-30 11:40:08 +00:00
*
* @ var string
* @ access private
*/
2010-04-04 06:33:39 +00:00
private $__storage = array ();
2009-07-24 19:18:37 +00:00
2008-05-30 11:40:08 +00:00
/**
* Extracted tokens
*
* @ var array
* @ access private
*/
2010-04-04 06:33:39 +00:00
private $__tokens = array ();
2009-07-24 19:18:37 +00:00
2008-05-30 11:40:08 +00:00
/**
* Extracted strings
*
* @ var array
* @ access private
*/
2010-04-04 06:33:39 +00:00
private $__strings = array ();
2009-07-24 19:18:37 +00:00
2008-05-30 11:40:08 +00:00
/**
* Destination path
*
* @ var string
* @ access private
*/
2010-04-04 06:33:39 +00:00
private $__output = null ;
2009-07-24 19:18:37 +00:00
2010-10-29 04:40:04 +00:00
/**
* An array of directories to exclude .
*
* @ var array
*/
protected $_exclude = array ();
2008-05-30 11:40:08 +00:00
/**
* Execution method always used for tasks
*
2009-09-15 03:43:59 +00:00
* @ return void
* @ access private
2008-05-30 11:40:08 +00:00
*/
function execute () {
2010-10-29 04:40:04 +00:00
if ( ! empty ( $this -> params [ 'exclude' ])) {
$this -> _exclude = explode ( ',' , $this -> params [ 'exclude' ]);
}
2008-05-30 11:40:08 +00:00
if ( isset ( $this -> params [ 'files' ]) && ! is_array ( $this -> params [ 'files' ])) {
2009-09-15 03:43:59 +00:00
$this -> __files = explode ( ',' , $this -> params [ 'files' ]);
2008-05-30 11:40:08 +00:00
}
2009-09-15 03:43:59 +00:00
if ( isset ( $this -> params [ 'paths' ])) {
$this -> __paths = explode ( ',' , $this -> params [ 'paths' ]);
2008-05-30 11:40:08 +00:00
} else {
2010-10-23 04:11:31 +00:00
$defaultPath = APP_PATH ;
2010-10-10 05:02:23 +00:00
$message = sprintf ( __ ( " What is the full path you would like to extract? \n Example: %s \n [Q]uit [D]one " ), $this -> Dispatch -> params [ 'root' ] . DS . 'myapp' );
2009-09-15 03:43:59 +00:00
while ( true ) {
$response = $this -> in ( $message , null , $defaultPath );
2008-05-30 11:40:08 +00:00
if ( strtoupper ( $response ) === 'Q' ) {
2010-04-15 15:43:39 +00:00
$this -> out ( __ ( 'Extract Aborted' ));
2008-06-04 19:04:58 +00:00
$this -> _stop ();
2009-09-15 03:43:59 +00:00
} elseif ( strtoupper ( $response ) === 'D' ) {
2009-09-26 21:08:37 +00:00
$this -> out ();
2009-09-15 03:43:59 +00:00
break ;
} elseif ( is_dir ( $response )) {
$this -> __paths [] = $response ;
$defaultPath = 'D' ;
} else {
2010-04-15 15:43:39 +00:00
$this -> err ( __ ( 'The directory path you supplied was not found. Please try again.' ));
2008-05-30 11:40:08 +00:00
}
2009-09-26 21:08:37 +00:00
$this -> out ();
2008-05-30 11:40:08 +00:00
}
}
if ( isset ( $this -> params [ 'output' ])) {
$this -> __output = $this -> params [ 'output' ];
} else {
2010-04-15 15:43:39 +00:00
$message = sprintf ( __ ( " What is the full path you would like to output? \n Example: %s \n [Q]uit " ), $this -> __paths [ 0 ] . DS . 'locale' );
2009-09-15 03:43:59 +00:00
while ( true ) {
$response = $this -> in ( $message , null , $this -> __paths [ 0 ] . DS . 'locale' );
2008-05-30 11:40:08 +00:00
if ( strtoupper ( $response ) === 'Q' ) {
2010-04-15 15:43:39 +00:00
$this -> out ( __ ( 'Extract Aborted' ));
2008-06-04 19:04:58 +00:00
$this -> _stop ();
2009-09-15 03:43:59 +00:00
} elseif ( is_dir ( $response )) {
$this -> __output = $response . DS ;
break ;
} else {
2010-04-15 15:43:39 +00:00
$this -> err ( __ ( 'The directory path you supplied was not found. Please try again.' ));
2008-05-30 11:40:08 +00:00
}
2009-09-26 21:08:37 +00:00
$this -> out ();
2008-05-30 11:40:08 +00:00
}
}
2009-10-29 23:26:59 +00:00
if ( isset ( $this -> params [ 'merge' ])) {
$this -> __merge = ! ( strtolower ( $this -> params [ 'merge' ]) === 'no' );
} else {
$this -> out ();
2010-04-15 15:43:39 +00:00
$response = $this -> in ( sprintf ( __ ( 'Would you like to merge all domains strings into the default.pot file?' )), array ( 'y' , 'n' ), 'n' );
2009-10-29 23:26:59 +00:00
$this -> __merge = strtolower ( $response ) === 'y' ;
}
2009-09-15 03:43:59 +00:00
if ( empty ( $this -> __files )) {
$this -> __searchFiles ();
2008-05-30 11:40:08 +00:00
}
$this -> __extract ();
}
2009-07-24 19:18:37 +00:00
2008-05-30 11:40:08 +00:00
/**
* Extract text
*
2009-09-15 03:43:59 +00:00
* @ return void
2008-05-30 11:40:08 +00:00
* @ access private
*/
function __extract () {
2009-09-26 21:08:37 +00:00
$this -> out ();
$this -> out ();
2010-04-15 15:43:39 +00:00
$this -> out ( __ ( 'Extracting...' ));
2008-05-30 11:40:08 +00:00
$this -> hr ();
2010-04-15 15:43:39 +00:00
$this -> out ( __ ( 'Paths:' ));
2009-09-15 03:43:59 +00:00
foreach ( $this -> __paths as $path ) {
$this -> out ( ' ' . $path );
}
2010-04-15 15:43:39 +00:00
$this -> out ( __ ( 'Output Directory: ' ) . $this -> __output );
2008-05-30 11:40:08 +00:00
$this -> hr ();
$this -> __extractTokens ();
2010-02-12 13:20:43 +00:00
$this -> __buildFiles ();
$this -> __writeFiles ();
$this -> __paths = $this -> __files = $this -> __storage = array ();
$this -> __strings = $this -> __tokens = array ();
$this -> out ();
2010-04-15 15:43:39 +00:00
$this -> out ( __ ( 'Done.' ));
2008-05-30 11:40:08 +00:00
}
2009-07-24 19:18:37 +00:00
2010-10-10 05:56:23 +00:00
/**
* Get & configure the option parser
*
* @ return void
*/
public function getOptionParser () {
$parser = parent :: getOptionParser ();
return $parser -> description ( __ ( 'CakePHP Language String Extraction:' ))
2010-10-29 04:40:04 +00:00
-> addOption ( 'app' , array ( 'help' => __ ( 'Directory where your application is located.' )))
-> addOption ( 'paths' , array ( 'help' => __ ( 'Comma separted list of paths, full paths are needed.' )))
2010-10-24 19:27:44 +00:00
-> addOption ( 'merge' , array (
2010-10-29 04:40:04 +00:00
'help' => __ ( 'Merge all domain strings into the default.po file.' ),
2010-10-24 19:27:44 +00:00
'choices' => array ( 'yes' , 'no' )
))
2010-10-10 05:56:23 +00:00
-> addOption ( 'output' , array ( 'help' => __ ( 'Full path to output directory.' )))
2010-10-29 04:40:04 +00:00
-> addOption ( 'files' , array ( 'help' => __ ( 'Comma separated list of files, full paths are needed.' )))
-> addOption ( 'exclude' , array (
'help' => __ ( 'Comma separated list of directories to exclude. Any path containing a path segment with the provided values will be skipped. E.g. test,vendors' )
));
2010-10-10 05:56:23 +00:00
}
2008-05-30 11:40:08 +00:00
/**
* Show help options
*
2009-09-15 03:43:59 +00:00
* @ return void
2008-05-30 11:40:08 +00:00
*/
2010-04-05 03:19:38 +00:00
public function help () {
2010-04-15 15:43:39 +00:00
$this -> out ( __ ( 'CakePHP Language String Extraction:' ));
2008-05-30 11:40:08 +00:00
$this -> hr ();
2010-04-15 15:43:39 +00:00
$this -> out ( __ ( 'The Extract script generates .pot file(s) with translations' ));
$this -> out ( __ ( 'By default the .pot file(s) will be place in the locale directory of -app' ));
$this -> out ( __ ( 'By default -app is ROOT/app' ));
2008-05-30 11:40:08 +00:00
$this -> hr ();
2010-04-15 15:43:39 +00:00
$this -> out ( __ ( 'Usage: cake i18n extract <command> <param1> <param2>...' ));
2009-09-26 21:08:37 +00:00
$this -> out ();
2010-04-15 15:43:39 +00:00
$this -> out ( __ ( 'Params:' ));
$this -> out ( __ ( ' -app [path...]: directory where your application is located' ));
$this -> out ( __ ( ' -root [path...]: path to install' ));
$this -> out ( __ ( ' -core [path...]: path to cake directory' ));
$this -> out ( __ ( ' -paths [comma separated list of paths, full path is needed]' ));
$this -> out ( __ ( ' -merge [yes|no]: Merge all domains strings into the default.pot file' ));
$this -> out ( __ ( ' -output [path...]: Full path to output directory' ));
$this -> out ( __ ( ' -files: [comma separated list of files, full path to file is needed]' ));
2009-10-29 23:26:59 +00:00
$this -> out ();
2010-04-15 15:43:39 +00:00
$this -> out ( __ ( 'Commands:' ));
$this -> out ( __ ( ' cake i18n extract help: Shows this help message.' ));
2009-09-26 21:08:37 +00:00
$this -> out ();
2008-05-30 11:40:08 +00:00
}
2009-07-24 19:18:37 +00:00
2008-05-30 11:40:08 +00:00
/**
* Extract tokens out of all files to be processed
*
2009-09-15 03:43:59 +00:00
* @ return void
2008-05-30 11:40:08 +00:00
* @ access private
*/
function __extractTokens () {
2009-09-15 03:43:59 +00:00
foreach ( $this -> __files as $file ) {
2008-05-30 11:40:08 +00:00
$this -> __file = $file ;
2010-04-15 15:43:39 +00:00
$this -> out ( sprintf ( __ ( 'Processing %s...' ), $file ));
2008-05-30 11:40:08 +00:00
$code = file_get_contents ( $file );
$allTokens = token_get_all ( $code );
$this -> __tokens = array ();
$lineNumber = 1 ;
foreach ( $allTokens as $token ) {
if (( ! is_array ( $token )) || (( $token [ 0 ] != T_WHITESPACE ) && ( $token [ 0 ] != T_INLINE_HTML ))) {
if ( is_array ( $token )) {
$token [] = $lineNumber ;
}
$this -> __tokens [] = $token ;
}
if ( is_array ( $token )) {
2009-11-19 22:17:47 +00:00
$lineNumber += count ( explode ( " \n " , $token [ 1 ])) - 1 ;
2008-05-30 11:40:08 +00:00
} else {
2009-11-19 22:17:47 +00:00
$lineNumber += count ( explode ( " \n " , $token )) - 1 ;
2008-05-30 11:40:08 +00:00
}
}
unset ( $allTokens );
2009-08-06 21:14:25 +00:00
$this -> __parse ( '__' , array ( 'singular' ));
$this -> __parse ( '__n' , array ( 'singular' , 'plural' ));
$this -> __parse ( '__d' , array ( 'domain' , 'singular' ));
$this -> __parse ( '__c' , array ( 'singular' ));
$this -> __parse ( '__dc' , array ( 'domain' , 'singular' ));
$this -> __parse ( '__dn' , array ( 'domain' , 'singular' , 'plural' ));
$this -> __parse ( '__dcn' , array ( 'domain' , 'singular' , 'plural' ));
2008-05-30 11:40:08 +00:00
}
}
2009-07-24 19:18:37 +00:00
2008-05-30 11:40:08 +00:00
/**
2009-08-06 21:14:25 +00:00
* Parse tokens
2008-05-30 11:40:08 +00:00
*
* @ param string $functionName Function name that indicates translatable string ( e . g : '__' )
2009-08-06 21:14:25 +00:00
* @ param array $map Array containing what variables it will find ( e . g : domain , singular , plural )
2009-09-15 03:43:59 +00:00
* @ return void
* @ access private
2008-05-30 11:40:08 +00:00
*/
2009-08-06 21:14:25 +00:00
function __parse ( $functionName , $map ) {
2008-05-30 11:40:08 +00:00
$count = 0 ;
$tokenCount = count ( $this -> __tokens );
2010-02-12 13:52:58 +00:00
while (( $tokenCount - $count ) > 1 ) {
2008-05-30 11:40:08 +00:00
list ( $countToken , $firstParenthesis ) = array ( $this -> __tokens [ $count ], $this -> __tokens [ $count + 1 ]);
if ( ! is_array ( $countToken )) {
$count ++ ;
continue ;
}
list ( $type , $string , $line ) = $countToken ;
if (( $type == T_STRING ) && ( $string == $functionName ) && ( $firstParenthesis == '(' )) {
$position = $count ;
$depth = 0 ;
while ( $depth == 0 ) {
if ( $this -> __tokens [ $position ] == '(' ) {
$depth ++ ;
} elseif ( $this -> __tokens [ $position ] == ')' ) {
$depth -- ;
}
$position ++ ;
}
2009-08-06 21:14:25 +00:00
$mapCount = count ( $map );
$strings = array ();
while ( count ( $strings ) < $mapCount && ( $this -> __tokens [ $position ] == ',' || $this -> __tokens [ $position ][ 0 ] == T_CONSTANT_ENCAPSED_STRING )) {
if ( $this -> __tokens [ $position ][ 0 ] == T_CONSTANT_ENCAPSED_STRING ) {
$strings [] = $this -> __tokens [ $position ][ 1 ];
2008-05-30 11:40:08 +00:00
}
2009-08-06 21:14:25 +00:00
$position ++ ;
2008-05-30 11:40:08 +00:00
}
2009-08-06 21:14:25 +00:00
if ( $mapCount == count ( $strings )) {
extract ( array_combine ( $map , $strings ));
2009-09-15 03:43:59 +00:00
if ( ! isset ( $domain )) {
$domain = '\'default\'' ;
2008-05-30 11:40:08 +00:00
}
2009-09-15 03:43:59 +00:00
$string = $this -> __formatString ( $singular );
if ( isset ( $plural )) {
$string .= " \0 " . $this -> __formatString ( $plural );
}
$this -> __strings [ $this -> __formatString ( $domain )][ $string ][ $this -> __file ][] = $line ;
2008-05-30 11:40:08 +00:00
} else {
$this -> __markerError ( $this -> __file , $line , $functionName , $count );
}
}
$count ++ ;
}
}
2009-07-24 19:18:37 +00:00
2008-05-30 11:40:08 +00:00
/**
* Build the translate template file contents out of obtained strings
*
2009-09-15 03:43:59 +00:00
* @ return void
2008-05-30 11:40:08 +00:00
* @ access private
*/
function __buildFiles () {
2009-09-15 03:43:59 +00:00
foreach ( $this -> __strings as $domain => $strings ) {
foreach ( $strings as $string => $files ) {
2010-02-18 00:41:15 +00:00
$occurrences = array ();
2009-09-15 03:43:59 +00:00
foreach ( $files as $file => $lines ) {
2010-02-18 00:41:15 +00:00
$occurrences [] = $file . ':' . implode ( ';' , $lines );
2008-05-30 11:40:08 +00:00
}
2010-02-18 00:41:15 +00:00
$occurrences = implode ( " \n #: " , $occurrences );
$header = '#: ' . str_replace ( $this -> __paths , '' , $occurrences ) . " \n " ;
2009-09-15 03:43:59 +00:00
if ( strpos ( $string , " \0 " ) === false ) {
$sentence = " msgid \" { $string } \" \n " ;
$sentence .= " msgstr \" \" \n \n " ;
2008-05-30 11:40:08 +00:00
} else {
2009-09-15 03:43:59 +00:00
list ( $singular , $plural ) = explode ( " \0 " , $string );
$sentence = " msgid \" { $singular } \" \n " ;
$sentence .= " msgid_plural \" { $plural } \" \n " ;
$sentence .= " msgstr[0] \" \" \n " ;
$sentence .= " msgstr[1] \" \" \n \n " ;
2008-05-30 11:40:08 +00:00
}
2009-09-15 03:43:59 +00:00
$this -> __store ( $domain , $header , $sentence );
2009-10-29 23:26:59 +00:00
if ( $domain != 'default' && $this -> __merge ) {
2009-09-15 03:43:59 +00:00
$this -> __store ( 'default' , $header , $sentence );
2008-05-30 11:40:08 +00:00
}
}
}
}
2009-07-24 19:18:37 +00:00
2008-05-30 11:40:08 +00:00
/**
* Prepare a file to be stored
*
2009-09-15 03:43:59 +00:00
* @ return void
2008-05-30 11:40:08 +00:00
* @ access private
*/
2009-09-15 03:43:59 +00:00
function __store ( $domain , $header , $sentence ) {
if ( ! isset ( $this -> __storage [ $domain ])) {
$this -> __storage [ $domain ] = array ();
}
if ( ! isset ( $this -> __storage [ $domain ][ $sentence ])) {
$this -> __storage [ $domain ][ $sentence ] = $header ;
2008-05-30 11:40:08 +00:00
} else {
2009-09-15 03:43:59 +00:00
$this -> __storage [ $domain ][ $sentence ] .= $header ;
2008-05-30 11:40:08 +00:00
}
}
2009-07-24 19:18:37 +00:00
2008-05-30 11:40:08 +00:00
/**
* Write the files that need to be stored
*
2009-09-15 03:43:59 +00:00
* @ return void
2008-05-30 11:40:08 +00:00
* @ access private
*/
function __writeFiles () {
2010-02-18 00:41:15 +00:00
$overwriteAll = false ;
2009-09-15 03:43:59 +00:00
foreach ( $this -> __storage as $domain => $sentences ) {
$output = $this -> __writeHeader ();
foreach ( $sentences as $sentence => $header ) {
$output .= $header . $sentence ;
2008-05-30 11:40:08 +00:00
}
2009-09-15 03:43:59 +00:00
$filename = $domain . '.pot' ;
$File = new File ( $this -> __output . $filename );
2010-02-18 00:41:15 +00:00
$response = '' ;
while ( $overwriteAll === false && $File -> exists () && strtoupper ( $response ) !== 'Y' ) {
$this -> out ();
2010-04-15 15:43:39 +00:00
$response = $this -> in ( sprintf ( __ ( 'Error: %s already exists in this location. Overwrite? [Y]es, [N]o, [A]ll' ), $filename ), array ( 'y' , 'n' , 'a' ), 'y' );
2010-02-18 00:41:15 +00:00
if ( strtoupper ( $response ) === 'N' ) {
$response = '' ;
while ( $response == '' ) {
2010-04-15 15:43:39 +00:00
$response = $this -> in ( sprintf ( __ ( " What would you like to name this file? \n Example: %s " ), 'new_' . $filename ), null , 'new_' . $filename );
2010-02-18 00:41:15 +00:00
$File = new File ( $this -> __output . $response );
$filename = $response ;
2008-05-30 11:40:08 +00:00
}
2010-02-18 00:41:15 +00:00
} elseif ( strtoupper ( $response ) === 'A' ) {
$overwriteAll = true ;
2008-05-30 11:40:08 +00:00
}
}
2009-09-15 03:43:59 +00:00
$File -> write ( $output );
$File -> close ();
2008-05-30 11:40:08 +00:00
}
}
2009-07-24 19:18:37 +00:00
2008-05-30 11:40:08 +00:00
/**
* Build the translation template header
*
* @ return string Translation template header
* @ access private
*/
function __writeHeader () {
$output = " # LANGUAGE translation of CakePHP Application \n " ;
$output .= " # Copyright YEAR NAME <EMAIL@ADDRESS> \n " ;
$output .= " # \n " ;
$output .= " #, fuzzy \n " ;
$output .= " msgid \" \" \n " ;
$output .= " msgstr \" \" \n " ;
$output .= " \" Project-Id-Version: PROJECT VERSION \\ n \" \n " ;
$output .= " \" POT-Creation-Date: " . date ( " Y-m-d H:iO " ) . " \\ n \" \n " ;
$output .= " \" PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ \\ n \" \n " ;
$output .= " \" Last-Translator: NAME <EMAIL@ADDRESS> \\ n \" \n " ;
$output .= " \" Language-Team: LANGUAGE <EMAIL@ADDRESS> \\ n \" \n " ;
$output .= " \" MIME-Version: 1.0 \\ n \" \n " ;
$output .= " \" Content-Type: text/plain; charset=utf-8 \\ n \" \n " ;
$output .= " \" Content-Transfer-Encoding: 8bit \\ n \" \n " ;
$output .= " \" Plural-Forms: nplurals=INTEGER; plural=EXPRESSION; \\ n \" \n \n " ;
return $output ;
}
2009-07-24 19:18:37 +00:00
2008-05-30 11:40:08 +00:00
/**
* Format a string to be added as a translateable string
*
* @ param string $string String to format
* @ return string Formatted string
* @ access private
*/
function __formatString ( $string ) {
$quote = substr ( $string , 0 , 1 );
$string = substr ( $string , 1 , - 1 );
if ( $quote == '"' ) {
$string = stripcslashes ( $string );
} else {
$string = strtr ( $string , array ( " \\ ' " => " ' " , " \\ \\ " => " \\ " ));
}
2008-11-06 22:57:50 +00:00
$string = str_replace ( " \r \n " , " \n " , $string );
2008-05-30 11:40:08 +00:00
return addcslashes ( $string , " \0 .. \37 \\ \" " );
}
2009-07-24 19:18:37 +00:00
2008-05-30 11:40:08 +00:00
/**
* Indicate an invalid marker on a processed file
*
* @ param string $file File where invalid marker resides
* @ param integer $line Line number
* @ param string $marker Marker found
* @ param integer $count Count
2009-09-15 03:43:59 +00:00
* @ return void
2008-05-30 11:40:08 +00:00
* @ access private
*/
function __markerError ( $file , $line , $marker , $count ) {
2010-04-15 15:43:39 +00:00
$this -> out ( sprintf ( __ ( " Invalid marker content in %s:%s \n * %s( " ), $file , $line , $marker ), true );
2008-05-30 11:40:08 +00:00
$count += 2 ;
$tokenCount = count ( $this -> __tokens );
$parenthesis = 1 ;
while ((( $tokenCount - $count ) > 0 ) && $parenthesis ) {
if ( is_array ( $this -> __tokens [ $count ])) {
$this -> out ( $this -> __tokens [ $count ][ 1 ], false );
} else {
$this -> out ( $this -> __tokens [ $count ], false );
if ( $this -> __tokens [ $count ] == '(' ) {
$parenthesis ++ ;
}
if ( $this -> __tokens [ $count ] == ')' ) {
$parenthesis -- ;
}
}
$count ++ ;
}
$this -> out ( " \n " , true );
}
2009-07-24 19:18:37 +00:00
2008-05-30 11:40:08 +00:00
/**
2009-09-15 03:43:59 +00:00
* Search files that may contain translateable strings
2008-05-30 11:40:08 +00:00
*
2009-09-15 03:43:59 +00:00
* @ return void
2008-05-30 11:40:08 +00:00
* @ access private
*/
2009-09-15 03:43:59 +00:00
function __searchFiles () {
2010-10-29 04:40:04 +00:00
$pattern = false ;
if ( ! empty ( $this -> _exclude )) {
$pattern = '/[\/\\\\]' . implode ( '|' , $this -> _exclude ) . '[\/\\\\]/' ;
}
2009-09-15 03:43:59 +00:00
foreach ( $this -> __paths as $path ) {
$Folder = new Folder ( $path );
$files = $Folder -> findRecursive ( '.*\.(php|ctp|thtml|inc|tpl)' , true );
2010-10-29 04:40:04 +00:00
if ( ! empty ( $pattern )) {
foreach ( $files as $i => $file ) {
if ( preg_match ( $pattern , $file )) {
unset ( $files [ $i ]);
}
}
$files = array_values ( $files );
}
2010-06-07 02:39:04 +00:00
$this -> __files = array_merge ( $this -> __files , $files );
2008-05-30 11:40:08 +00:00
}
}
}