Hi all!
I’ve write a package class for translations which creates the file if it’s not exists. I just share you
I hope it will be good for everyone.
Edit: auto creates files AND create labels
<?php
class T
{
public static function trans()
{
$args=func_get_args();
$language_file='protected/messages/en/'.$args[0].'.php';
if(!is_file($language_file))
{
file_put_contents($language_file,"<?php\nreturn array\n()\n?>\n");
chmod($language_file,0664);
}
$dictionary=include($language_file);
$args[1]=str_replace("'",'’',$args[1]);
if(!in_array($args[1],array_keys($dictionary)))
{
$file=file_get_contents($language_file);
$file=str_replace(")\n?>",'',$file);
$file.="\t'".$args[1]."'=>'',\n)\n?>";
file_put_contents($language_file,$file);
}
return call_user_func_array('Yii::t',$args);
}
}
?>