-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPoMemoryWriter.php
88 lines (76 loc) · 1.94 KB
/
PoMemoryWriter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
namespace Drupal\Component\Gettext;
/**
* Defines a Gettext PO memory writer, to be used by the installer.
*/
class PoMemoryWriter implements PoWriterInterface {
/**
* Array to hold all PoItem elements.
*
* @var array
*/
protected $items;
/**
* Constructor, initialize empty items.
*/
public function __construct() {
$this->items = [];
}
/**
* {@inheritdoc}
*/
public function writeItem(PoItem $item) {
if (is_array($item->getSource())) {
$item->setSource(implode(PoItem::DELIMITER, $item->getSource()));
$item->setTranslation(implode(PoItem::DELIMITER, $item->getTranslation()));
}
$context = $item->getContext();
$this->items[$context != NULL ? $context : ''][$item->getSource()] = $item->getTranslation();
}
/**
* {@inheritdoc}
*/
public function writeItems(PoReaderInterface $reader, $count = -1) {
$forever = $count == -1;
while (($count-- > 0 || $forever) && ($item = $reader->readItem())) {
$this->writeItem($item);
}
}
/**
* Get all stored PoItem's.
*
* @return array
* Array of all PoItem elements.
*/
public function getData() {
return $this->items;
}
/**
* Implements Drupal\Component\Gettext\PoMetadataInterface:setLangcode().
*
* Not implemented. Not relevant for the MemoryWriter.
*/
public function setLangcode($langcode) {
}
/**
* Implements Drupal\Component\Gettext\PoMetadataInterface:getLangcode().
*
* Not implemented. Not relevant for the MemoryWriter.
*/
public function getLangcode() {
}
/**
* Implements Drupal\Component\Gettext\PoMetadataInterface:getHeader().
*
* Not implemented. Not relevant for the MemoryWriter.
*/
public function getHeader() {
}
/**
* Implements Drupal\Component\Gettext\PoMetadataInterface:setHeader().
*
* Not implemented. Not relevant for the MemoryWriter.
*/
public function setHeader(PoHeader $header) {
}
}