| 
						
						
							
								
							
						
						
					 | 
					 | 
					@ -8,6 +8,7 @@ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					namespace yii\console\controllers; | 
					 | 
					 | 
					 | 
					namespace yii\console\controllers; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					use Yii; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					use yii\console\Controller; | 
					 | 
					 | 
					 | 
					use yii\console\Controller; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					use yii\console\Exception; | 
					 | 
					 | 
					 | 
					use yii\console\Exception; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					use yii\helpers\FileHelper; | 
					 | 
					 | 
					 | 
					use yii\helpers\FileHelper; | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -18,10 +19,10 @@ use yii\helpers\FileHelper; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 * under the specified directory. | 
					 | 
					 | 
					 | 
					 * under the specified directory. | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 * | 
					 | 
					 | 
					 | 
					 * | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 * Usage: | 
					 | 
					 | 
					 | 
					 * Usage: | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 * 1. Create a configuration file using 'template' action: | 
					 | 
					 | 
					 | 
					 * 1. Create a configuration file using the 'message/config' command: | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 *    yii message/template /path/to/myapp/messages/config.php | 
					 | 
					 | 
					 | 
					 *    yii message/config /path/to/myapp/messages/config.php | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 * 2. Edit the created config file, adjusting it for your web application needs. | 
					 | 
					 | 
					 | 
					 * 2. Edit the created config file, adjusting it for your web application needs. | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 * 3. Run the 'generate' action, using created config: | 
					 | 
					 | 
					 | 
					 * 3. Run the 'message/extract' extract, using created config: | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 *    yii message /path/to/myapp/messages/config.php | 
					 | 
					 | 
					 | 
					 *    yii message /path/to/myapp/messages/config.php | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 * | 
					 | 
					 | 
					 | 
					 * | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 * @author Qiang Xue <qiang.xue@gmail.com> | 
					 | 
					 | 
					 | 
					 * @author Qiang Xue <qiang.xue@gmail.com> | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -32,100 +33,85 @@ class MessageController extends Controller | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						/** | 
					 | 
					 | 
					 | 
						/** | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * @var string controller default action ID. | 
					 | 
					 | 
					 | 
						 * @var string controller default action ID. | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 */ | 
					 | 
					 | 
					 | 
						 */ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						public $defaultAction = 'generate'; | 
					 | 
					 | 
					 | 
						public $defaultAction = 'extract'; | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						/** | 
					 | 
					 | 
					 | 
						/** | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * Searches for messages to be translated in the specified | 
					 | 
					 | 
					 | 
						 * Creates a configuration file for the "extract" command. | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * source files and compiles them into PHP arrays as message source. | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * | 
					 | 
					 | 
					 | 
						 * | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * @param string $config the path of the configuration file. You can find | 
					 | 
					 | 
					 | 
						 * The generated configuration file contains detailed instructions on | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * an example in framework/messages/config.php. | 
					 | 
					 | 
					 | 
						 * how to customize it to fit for your needs. After customization, | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * @throws \yii\console\Exception on failure. | 
					 | 
					 | 
					 | 
						 * you may use this configuration file with the "extract" command. | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * | 
					 | 
					 | 
					 | 
						 * | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * The file can be placed anywhere and must be a valid PHP script which | 
					 | 
					 | 
					 | 
						 * @param string $filePath output file name. | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * returns an array of name-value pairs. Each name-value pair represents | 
					 | 
					 | 
					 | 
						 * @throws Exception on failure. | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * a configuration option. | 
					 | 
					 | 
					 | 
						 */ | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						public function actionConfig($filePath) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						{ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
							if (file_exists($filePath)) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
								if (!$this->confirm("File '{$filePath}' already exists. Do you wish to overwrite it?")) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
									return; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
								} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
							} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
							copy(Yii::getAlias('@yii/views/messageConfig.php'), $filePath); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
							echo "Configuration file template created at '{$filePath}'.\n\n"; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						/** | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						 * Extracts messages to be translated from source code. | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * | 
					 | 
					 | 
					 | 
						 * | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * The following options are available: | 
					 | 
					 | 
					 | 
						 * This command will search through source code files and extract | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						 * messages that need to be translated in different languages. | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * | 
					 | 
					 | 
					 | 
						 * | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 *  - sourcePath: string, root directory of all source files. | 
					 | 
					 | 
					 | 
						 * @param string $configFile the path of the configuration file. | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 *  - messagePath: string, root directory containing message translations. | 
					 | 
					 | 
					 | 
						 * You may use the "yii message/config" command to generate | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 *  - languages: array, list of language codes that the extracted messages | 
					 | 
					 | 
					 | 
						 * this file and then customize it for your needs. | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 *    should be translated to. For example, array('zh_cn', 'en_au'). | 
					 | 
					 | 
					 | 
						 * @throws Exception on failure. | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 *  - fileTypes: array, a list of file extensions (e.g. 'php', 'xml'). | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 *    Only the files whose extension name can be found in this list | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 *    will be processed. If empty, all files will be processed. | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 *  - exclude: array, a list of directory and file exclusions. Each | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 *    exclusion can be either a name or a path. If a file or directory name | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 *    or path matches the exclusion, it will not be copied. For example, | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 *    an exclusion of '.svn' will exclude all files and directories whose | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 *    name is '.svn'. And an exclusion of '/a/b' will exclude file or | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 *    directory 'sourcePath/a/b'. | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 *  - translator: the name of the function for translating messages. | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 *    Defaults to 'Yii::t'. This is used as a mark to find messages to be | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 *    translated. Accepts both string for single function name or array for | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 *    multiple function names. | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 *  - overwrite: if message file must be overwritten with the merged messages. | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 *  - removeOld: if message no longer needs translation it will be removed, | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 *    instead of being enclosed between a pair of '@@' marks. | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 *  - sort: sort messages by key when merging, regardless of their translation | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 *    state (new, obsolete, translated.) | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 */ | 
					 | 
					 | 
					 | 
						 */ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						public function actionGenerate($config) | 
					 | 
					 | 
					 | 
						public function actionExtract($configFile) | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						{ | 
					 | 
					 | 
					 | 
						{ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							if (!is_file($config)) { | 
					 | 
					 | 
					 | 
							if (!is_file($configFile)) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								throw new Exception("the configuration file {$config} does not exist."); | 
					 | 
					 | 
					 | 
								throw new Exception("the configuration file {$configFile} does not exist."); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							} | 
					 | 
					 | 
					 | 
							} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							$config = require($config); | 
					 | 
					 | 
					 | 
							$config = array_merge(array( | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
								'translator' => 'Yii::t', | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
								'overwrite' => false, | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
								'removeUnused' => false, | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
								'sort' => false, | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
							), require($configFile)); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							$translator = 'Yii::t'; | 
					 | 
					 | 
					 | 
							if (!isset($config['sourcePath'], $config['messagePath'], $config['languages'])) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							extract($config); | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							if (!isset($sourcePath, $messagePath, $languages)) { | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								throw new Exception('The configuration file must specify "sourcePath", "messagePath" and "languages".'); | 
					 | 
					 | 
					 | 
								throw new Exception('The configuration file must specify "sourcePath", "messagePath" and "languages".'); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							} | 
					 | 
					 | 
					 | 
							} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							if (!is_dir($sourcePath)) { | 
					 | 
					 | 
					 | 
							if (!is_dir($config['sourcePath'])) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								throw new Exception("The source path {$sourcePath} is not a valid directory."); | 
					 | 
					 | 
					 | 
								throw new Exception("The source path {$config['sourcePath']} is not a valid directory."); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							} | 
					 | 
					 | 
					 | 
							} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							if (!is_dir($messagePath)) { | 
					 | 
					 | 
					 | 
							if (!is_dir($config['messagePath'])) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								throw new Exception("The message path {$messagePath} is not a valid directory."); | 
					 | 
					 | 
					 | 
								throw new Exception("The message path {$config['messagePath']} is not a valid directory."); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							} | 
					 | 
					 | 
					 | 
							} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							if (empty($languages)) { | 
					 | 
					 | 
					 | 
							if (empty($config['languages'])) { | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								throw new Exception("Languages cannot be empty."); | 
					 | 
					 | 
					 | 
								throw new Exception("Languages cannot be empty."); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							} | 
					 | 
					 | 
					 | 
							} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							if (!isset($overwrite)) { | 
					 | 
					 | 
					 | 
							$files = FileHelper::findFiles(realpath($config['sourcePath']), $config); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								$overwrite = false; | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							} | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							if (!isset($removeOld)) { | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								$removeOld = false; | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							} | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							if (!isset($sort)) { | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								$sort = false; | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							} | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							$options = array(); | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							if (isset($fileTypes)) { | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								$options['fileTypes'] = $fileTypes; | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							} | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							if (isset($exclude)) { | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								$options['exclude'] = $exclude; | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							} | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							$files = FileHelper::findFiles(realpath($sourcePath), $options); | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							$messages = array(); | 
					 | 
					 | 
					 | 
							$messages = array(); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							foreach ($files as $file) { | 
					 | 
					 | 
					 | 
							foreach ($files as $file) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								$messages = array_merge_recursive($messages, $this->extractMessages($file, $translator)); | 
					 | 
					 | 
					 | 
								$messages = array_merge($messages, $this->extractMessages($file, $config['translator'])); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							} | 
					 | 
					 | 
					 | 
							} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							foreach ($languages as $language) { | 
					 | 
					 | 
					 | 
							foreach ($config['languages'] as $language) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								$dir = $messagePath . DIRECTORY_SEPARATOR . $language; | 
					 | 
					 | 
					 | 
								$dir = $config['messagePath'] . DIRECTORY_SEPARATOR . $language; | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								if (!is_dir($dir)) { | 
					 | 
					 | 
					 | 
								if (!is_dir($dir)) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
									@mkdir($dir); | 
					 | 
					 | 
					 | 
									@mkdir($dir); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								} | 
					 | 
					 | 
					 | 
								} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								foreach ($messages as $category => $msgs) { | 
					 | 
					 | 
					 | 
								foreach ($messages as $category => $msgs) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
									$msgs = array_values(array_unique($msgs)); | 
					 | 
					 | 
					 | 
									$msgs = array_values(array_unique($msgs)); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
									$this->generateMessageFile($msgs, $dir . DIRECTORY_SEPARATOR . $category . '.php', $overwrite, $removeOld, $sort); | 
					 | 
					 | 
					 | 
									$this->generateMessageFile($msgs, $dir . DIRECTORY_SEPARATOR . $category . '.php', | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
										$config['overwrite'], | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
										$config['removeUnused'], | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
										$config['sort']); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								} | 
					 | 
					 | 
					 | 
								} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							} | 
					 | 
					 | 
					 | 
							} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						} | 
					 | 
					 | 
					 | 
						} | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -168,10 +154,10 @@ class MessageController extends Controller | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * @param array $messages | 
					 | 
					 | 
					 | 
						 * @param array $messages | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * @param string $fileName name of the file to write to | 
					 | 
					 | 
					 | 
						 * @param string $fileName name of the file to write to | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * @param boolean $overwrite if existing file should be overwritten without backup | 
					 | 
					 | 
					 | 
						 * @param boolean $overwrite if existing file should be overwritten without backup | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * @param boolean $removeOld if obsolete translations should be removed | 
					 | 
					 | 
					 | 
						 * @param boolean $removeUnused if obsolete translations should be removed | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * @param boolean $sort if translations should be sorted | 
					 | 
					 | 
					 | 
						 * @param boolean $sort if translations should be sorted | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 */ | 
					 | 
					 | 
					 | 
						 */ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						protected function generateMessageFile($messages, $fileName, $overwrite, $removeOld, $sort) | 
					 | 
					 | 
					 | 
						protected function generateMessageFile($messages, $fileName, $overwrite, $removeUnused, $sort) | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						{ | 
					 | 
					 | 
					 | 
						{ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							echo "Saving messages to $fileName..."; | 
					 | 
					 | 
					 | 
							echo "Saving messages to $fileName..."; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							if (is_file($fileName)) { | 
					 | 
					 | 
					 | 
							if (is_file($fileName)) { | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -199,7 +185,7 @@ class MessageController extends Controller | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								} | 
					 | 
					 | 
					 | 
								} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								ksort($translated); | 
					 | 
					 | 
					 | 
								ksort($translated); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								foreach ($translated as $message => $translation) { | 
					 | 
					 | 
					 | 
								foreach ($translated as $message => $translation) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
									if (!isset($merged[$message]) && !isset($todo[$message]) && !$removeOld) { | 
					 | 
					 | 
					 | 
									if (!isset($merged[$message]) && !isset($todo[$message]) && !$removeUnused) { | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
										if (substr($translation, 0, 2) === '@@' && substr($translation, -2) === '@@') { | 
					 | 
					 | 
					 | 
										if (substr($translation, 0, 2) === '@@' && substr($translation, -2) === '@@') { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
											$todo[$message] = $translation; | 
					 | 
					 | 
					 | 
											$todo[$message] = $translation; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
										} else { | 
					 | 
					 | 
					 | 
										} else { | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -248,44 +234,4 @@ return $array; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					EOD; | 
					 | 
					 | 
					 | 
					EOD; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							file_put_contents($fileName, $content); | 
					 | 
					 | 
					 | 
							file_put_contents($fileName, $content); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						} | 
					 | 
					 | 
					 | 
						} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						/** | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * Creates template of configuration file for [[actionGenerate]]. | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * @param string $configFile output file name. | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * @throws \yii\console\Exception on failure. | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 */ | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						public function actionTemplate($configFile) | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						{ | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							$template = <<<EOD | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					<?php | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					/** | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 * Configuration file for the "yii {$this->id}" console command. | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 */ | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					return array( | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						'sourcePath' => __DIR__, | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						'messagePath' => __DIR__ . DIRECTORY_SEPARATOR . 'messages', | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						'languages' => array(), | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						'fileTypes' => array('php'), | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						'overwrite' => true, | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						'exclude' => array( | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							'.svn', | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							'.gitignore', | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							'.gitkeep', | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							'.hgignore', | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							'.hgkeep', | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							'/messages', | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						), | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					); | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					EOD; | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							if (file_exists($configFile)) { | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								if (!$this->confirm("File '{$configFile}' already exists. Do you wish to overwrite it?")) { | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
									return; | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								} | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							} | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							if (!file_put_contents($configFile, $template)) { | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								throw new Exception("Unable to write template file '{$configFile}'."); | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							} else { | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								echo "Configuration file template created at '{$configFile}'.\n\n"; | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							} | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						} | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					} | 
					 | 
					 | 
					 | 
					} | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
					 | 
					 | 
					
  |