private function saveTranslationFile($contents, array &$tr)
{
$contents = Input::cleanPostedData($contents) . "\n";
// Before trying to save a yaml file, check if it's valid.
try {
Yaml::parse($contents);
} catch (ParseException $e) {
$msg = Trans::__('page.file-management.message.save-failed-colon', ['%s' => $tr['shortPath']]);
$this->flashes()->error($msg . ' ' . $e->getMessage());
return false;
}
// Clear any warning for file not found, we are creating it here
// we'll set an error if someone still submits the form and write is not allowed
$this->flashes()->clear();
try {
$fs = new Filesystem();
$fs->dumpFile($tr['path'], $contents);
} catch (IOException $e) {
$msg = Trans::__('general.phrase.file-not-writable', ['%s' => $tr['shortPath']]);
$this->flashes()->error($msg);
$tr['writeallowed'] = false;
return false;
}
$msg = Trans::__('page.file-management.message.save-success', ['%s' => $tr['shortPath']]);
$this->flashes()->info($msg);
return $this->redirectToRoute('translation', ['domain' => $tr['domain'], 'tr_locale' => $tr['locale']]);
}