protected function LocaleUpdateBase::makePoFile in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/locale/src/Tests/LocaleUpdateBase.php \Drupal\locale\Tests\LocaleUpdateBase::makePoFile()
Creates a translation file and tests its timestamp.
Parameters
string $path: Path of the file relative to the public file path.
string $filename: Name of the file to create.
int $timestamp: (optional) Timestamp to set the file to. Defaults to current time.
array $translations: (optional) Array of source/target value translation strings. Only singular strings are supported, no plurals. No double quotes are allowed in source and translations strings.
1 call to LocaleUpdateBase::makePoFile()
- LocaleUpdateBase::setTranslationFiles in core/
modules/ locale/ src/ Tests/ LocaleUpdateBase.php - Setup the environment containing local and remote translation files.
File
- core/
modules/ locale/ src/ Tests/ LocaleUpdateBase.php, line 112 - Contains \Drupal\locale\Tests\LocaleUpdateBase.
Class
- LocaleUpdateBase
- Base class for testing updates to string translations.
Namespace
Drupal\locale\TestsCode
protected function makePoFile($path, $filename, $timestamp = NULL, array $translations = array()) {
$timestamp = $timestamp ? $timestamp : REQUEST_TIME;
$path = 'public://' . $path;
$text = '';
$po_header = <<<EOF
msgid ""
msgstr ""
"Project-Id-Version: Drupal 8\\n"
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=UTF-8\\n"
"Content-Transfer-Encoding: 8bit\\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\\n"
EOF;
// Convert array of translations to Gettext source and translation strings.
if ($translations) {
foreach ($translations as $source => $target) {
$text .= 'msgid "' . $source . '"' . "\n";
$text .= 'msgstr "' . $target . '"' . "\n";
}
}
file_prepare_directory($path, FILE_CREATE_DIRECTORY);
$file = entity_create('file', array(
'uid' => 1,
'filename' => $filename,
'uri' => $path . '/' . $filename,
'filemime' => 'text/x-gettext-translation',
'timestamp' => $timestamp,
'status' => FILE_STATUS_PERMANENT,
));
file_put_contents($file
->getFileUri(), $po_header . $text);
touch(drupal_realpath($file
->getFileUri()), $timestamp);
$file
->save();
}