public static function createPHPLanguageFile($language, $messages) {
    $fileUtil = new FileUtil();

    // get locale directory
    $config = ObjectFactory::getInstance('configuration');
    $localeDir = $config->getDirectoryValue('localeDir', 'application');
    $fileUtil->mkdirRec($localeDir);
    $file = $localeDir.'messages_'.$language.'.php';

    // backup old file
    if (file_exists($file)) {
      rename($file, $file.".bak");
    }
    $fh = fopen($file, "w");

    // write header
    $header = <<<EOT
<?php
\$messages_{$language} = [];
\$messages_{$language}[''] = '';
EOT;
    fwrite($fh, $header."\n");

    // write messages
    foreach($messages as $message => $attributes) {
      $lines = '// file(s): '.$attributes['files']."\n";
      $lines .= "\$messages_".$language."['".str_replace("'", "\'", $message)."'] = '".str_replace("'", "\'", $attributes['translation'])."';"."\n";
      fwrite($fh, $lines);
    }

    // write footer
    $footer = <<<EOT
?>
EOT;
    fwrite($fh, $footer."\n");

    fclose($fh);
  }