20 if ($translations === null) {
21 $translations =
new Translations();
24 $lines = explode(
"\n", $string);
27 $translation =
new Translation(
'',
'');
29 for (
$n = count($lines);
$i <
$n; ++
$i) {
30 $line = trim($lines[
$i]);
32 $line = self::fixMultiLines($line, $lines,
$i);
35 if ($translation->is(
'',
'')) {
36 self::parseHeaders($translation->getTranslation(), $translations);
37 } elseif ($translation->hasOriginal()) {
38 $translations[] = $translation;
41 $translation =
new Translation(
'',
'');
45 $splitLine = preg_split(
'/\s+/', $line, 2);
47 $data = isset($splitLine[1]) ? $splitLine[1] :
'';
51 $translation->addComment(
$data);
56 $translation->addExtractedComment(
$data);
61 foreach (array_map(
'trim', explode(
',', trim(
$data))) as $value) {
62 $translation->addFlag($value);
68 foreach (preg_split(
'/\s+/', trim(
$data)) as $value) {
69 if (preg_match(
'/^(.+)(:(\d*))?$/U', $value, $matches)) {
70 $translation->addReference($matches[1], isset($matches[3]) ? $matches[3] : null);
77 $translation = $translation->getClone(self::convertString(
$data));
82 $translation = $translation->getClone(null, self::convertString(
$data));
87 $translation->setPlural(self::convertString(
$data));
93 $translation->setTranslation(self::convertString(
$data));
94 $append =
'Translation';
98 $translation->setPluralTranslation(self::convertString(
$data), 0);
99 $append =
'PluralTranslation';
103 if (strpos(
$key,
'msgstr[') === 0) {
104 $translation->setPluralTranslation(self::convertString(
$data), intval(substr(
$key, 7, -1)) - 1);
105 $append =
'PluralTranslation';
109 if (isset($append)) {
110 if ($append ===
'Context') {
111 $translation = $translation->getClone($translation->getContext().
"\n".self::convertString(
$data));
115 if ($append ===
'Original') {
116 $translation = $translation->getClone(null, $translation->getOriginal().
"\n".self::convertString(
$data));
120 if ($append ===
'PluralTranslation') {
121 $key = count($translation->getPluralTranslation()) - 1;
122 $translation->setPluralTranslation($translation->getPluralTranslation(
$key).
"\n".self::convertString(
$data),
$key);
126 $getMethod =
'get'.$append;
127 $setMethod =
'set'.$append;
128 $translation->$setMethod($translation->$getMethod().
"\n".self::convertString(
$data));
134 if ($translation->hasOriginal() && !in_array($translation, iterator_to_array($translations))) {
135 $translations[] = $translation;
138 return $translations;