comparison core/lib/Drupal/Component/Gettext/PoMemoryWriter.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 129ea1e6d783
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\Component\Gettext;
4
5 /**
6 * Defines a Gettext PO memory writer, to be used by the installer.
7 */
8 class PoMemoryWriter implements PoWriterInterface {
9
10 /**
11 * Array to hold all PoItem elements.
12 *
13 * @var array
14 */
15 private $_items;
16
17 /**
18 * Constructor, initialize empty items.
19 */
20 public function __construct() {
21 $this->_items = [];
22 }
23
24 /**
25 * {@inheritdoc}
26 */
27 public function writeItem(PoItem $item) {
28 if (is_array($item->getSource())) {
29 $item->setSource(implode(LOCALE_PLURAL_DELIMITER, $item->getSource()));
30 $item->setTranslation(implode(LOCALE_PLURAL_DELIMITER, $item->getTranslation()));
31 }
32 $context = $item->getContext();
33 $this->_items[$context != NULL ? $context : ''][$item->getSource()] = $item->getTranslation();
34 }
35
36 /**
37 * {@inheritdoc}
38 */
39 public function writeItems(PoReaderInterface $reader, $count = -1) {
40 $forever = $count == -1;
41 while (($count-- > 0 || $forever) && ($item = $reader->readItem())) {
42 $this->writeItem($item);
43 }
44 }
45
46 /**
47 * Get all stored PoItem's.
48 *
49 * @return array PoItem
50 */
51 public function getData() {
52 return $this->_items;
53 }
54
55 /**
56 * Implements Drupal\Component\Gettext\PoMetadataInterface:setLangcode().
57 *
58 * Not implemented. Not relevant for the MemoryWriter.
59 */
60 public function setLangcode($langcode) {
61 }
62
63 /**
64 * Implements Drupal\Component\Gettext\PoMetadataInterface:getLangcode().
65 *
66 * Not implemented. Not relevant for the MemoryWriter.
67 */
68 public function getLangcode() {
69 }
70
71 /**
72 * Implements Drupal\Component\Gettext\PoMetadataInterface:getHeader().
73 *
74 * Not implemented. Not relevant for the MemoryWriter.
75 */
76 public function getHeader() {
77 }
78
79 /**
80 * Implements Drupal\Component\Gettext\PoMetadataInterface:setHeader().
81 *
82 * Not implemented. Not relevant for the MemoryWriter.
83 */
84 public function setHeader(PoHeader $header) {
85 }
86
87 }