14 $lines = array(
'msgid ""',
'msgstr ""');
17 $headers[
'PO-Revision-Date'] = date(
'c');
19 foreach ($headers as
$name => $value) {
20 $lines[] =
'"'.$name.
': '.$value.
'\\n"';
26 foreach ($translations as $translation) {
27 if ($translation->hasComments()) {
28 foreach ($translation->getComments() as
$comment) {
29 $lines[] =
'# '.$comment;
33 if ($translation->hasExtractedComments()) {
34 foreach ($translation->getExtractedComments() as
$comment) {
35 $lines[] =
'#. '.$comment;
39 if ($translation->hasReferences()) {
40 foreach ($translation->getReferences() as $reference) {
41 $lines[] =
'#: '.$reference[0].(!is_null($reference[1]) ?
':'.$reference[1] : null);
45 if ($translation->hasFlags()) {
46 $lines[] =
'#, '.implode(
',', $translation->getFlags());
49 if ($translation->hasContext()) {
50 $lines[] =
'msgctxt '.self::convertString($translation->getContext());
53 self::addLines($lines,
'msgid', $translation->getOriginal());
54 if ($translation->hasPlural()) {
55 self::addLines($lines,
'msgid_plural', $translation->getPlural());
56 self::addLines($lines,
'msgstr[0]', $translation->getTranslation());
58 foreach ($translation->getPluralTranslation() as $k => $v) {
59 self::addLines($lines,
'msgstr['.($k + 1).
']', $v);
62 self::addLines($lines,
'msgstr', $translation->getTranslation());
68 return implode(
"\n", $lines);
80 $lines = explode(
"\n", $string);
81 $last = count($lines) - 1;
83 foreach ($lines as $k => $line) {
85 $lines[$k] = self::convertString($line);
87 $lines[$k] = self::convertString($line.
"\n");
103 $newLines = self::multilineQuote($value);
105 if (count($newLines) === 1) {
106 $lines[] =
$name.
' '.$newLines[0];
108 $lines[] =
$name.
' ""';
110 foreach ($newLines as $line) {
static toString(Translations $translations)
{}.
static convertString($value)
Convert a string to its PO representation.
getHeaders()
Returns all header for this translations.
Class to manage a collection of translations.
static multilineQuote($string)
Escapes and adds double quotes to a string.
static addLines(array &$lines, $name, $value)
Add one or more lines depending whether the string is multiline or not.