/**
* Creates a configured .po file on $path
* If PHP are not able to create the file the content will be returned instead
*
* @param string $path
* @param string $locale
* @param string $domain
* @param bool|true $write
* @return int|string
*/
public function createPOFile($path, $locale, $domain, $write = true)
{
$project = $this->configuration->getProject();
$timestamp = date("Y-m-d H:iO");
$translator = $this->configuration->getTranslator();
$encoding = $this->configuration->getEncoding();
$relativePath = $this->configuration->getRelativePath();
$keywords = implode(';', $this->configuration->getKeywordsList());
$template = 'msgid ""' . "\n";
$template .= 'msgstr ""' . "\n";
$template .= '"Project-Id-Version: ' . $project . '\\n' . "\"\n";
$template .= '"POT-Creation-Date: ' . $timestamp . '\\n' . "\"\n";
$template .= '"PO-Revision-Date: ' . $timestamp . '\\n' . "\"\n";
$template .= '"Last-Translator: ' . $translator . '\\n' . "\"\n";
$template .= '"Language-Team: ' . $translator . '\\n' . "\"\n";
$template .= '"Language: ' . $locale . '\\n' . "\"\n";
$template .= '"MIME-Version: 1.0' . '\\n' . "\"\n";
$template .= '"Content-Type: text/plain; charset=' . $encoding . '\\n' . "\"\n";
$template .= '"Content-Transfer-Encoding: 8bit' . '\\n' . "\"\n";
$template .= '"X-Generator: Poedit 1.5.4' . '\\n' . "\"\n";
$template .= '"X-Poedit-KeywordsList: ' . $keywords . '\\n' . "\"\n";
$template .= '"X-Poedit-Basepath: ' . $relativePath . '\\n' . "\"\n";
$template .= '"X-Poedit-SourceCharset: ' . $encoding . '\\n' . "\"\n";
// Source paths
$sourcePaths = $this->configuration->getSourcesFromDomain($domain);
// Compiled views on paths
if (count($sourcePaths)) {
// View compilation
$this->compileViews($sourcePaths, $domain);
array_push($sourcePaths, $this->getStorageForDomain($domain));
$i = 0;
foreach ($sourcePaths as $sourcePath) {
$template .= '"X-Poedit-SearchPath-' . $i . ': ' . $sourcePath . '\\n' . "\"\n";
$i++;
}
}
if (!$write) {
return $template . "\n";
}
// File creation
$file = fopen($path, "w");
$result = fwrite($file, $template);
fclose($file);
return $result;
}