Mercurial > hg > isophonics-drupal-site
comparison core/lib/Drupal/Component/Gettext/PoHeader.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 1fec387a4317 |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
25 /** | 25 /** |
26 * Language code. | 26 * Language code. |
27 * | 27 * |
28 * @var string | 28 * @var string |
29 */ | 29 */ |
30 private $_langcode; | 30 protected $langcode; |
31 | 31 |
32 /** | 32 /** |
33 * Formula for the plural form. | 33 * Formula for the plural form. |
34 * | 34 * |
35 * @var string | 35 * @var string |
36 */ | 36 */ |
37 private $_pluralForms; | 37 protected $pluralForms; |
38 | 38 |
39 /** | 39 /** |
40 * Author(s) of the file. | 40 * Author(s) of the file. |
41 * | 41 * |
42 * @var string | 42 * @var string |
43 */ | 43 */ |
44 private $_authors; | 44 protected $authors; |
45 | 45 |
46 /** | 46 /** |
47 * Date the po file got created. | 47 * Date the po file got created. |
48 * | 48 * |
49 * @var string | 49 * @var string |
50 */ | 50 */ |
51 private $_po_date; | 51 protected $poDate; |
52 | 52 |
53 /** | 53 /** |
54 * Human readable language name. | 54 * Human readable language name. |
55 * | 55 * |
56 * @var string | 56 * @var string |
57 */ | 57 */ |
58 private $_languageName; | 58 protected $languageName; |
59 | 59 |
60 /** | 60 /** |
61 * Name of the project the translation belongs to. | 61 * Name of the project the translation belongs to. |
62 * | 62 * |
63 * @var string | 63 * @var string |
64 */ | 64 */ |
65 private $_projectName; | 65 protected $projectName; |
66 | 66 |
67 /** | 67 /** |
68 * Constructor, creates a PoHeader with default values. | 68 * Constructor, creates a PoHeader with default values. |
69 * | 69 * |
70 * @param string $langcode | 70 * @param string $langcode |
71 * Language code. | 71 * Language code. |
72 */ | 72 */ |
73 public function __construct($langcode = NULL) { | 73 public function __construct($langcode = NULL) { |
74 $this->_langcode = $langcode; | 74 $this->langcode = $langcode; |
75 // Ignore errors when run during site installation before | 75 // Ignore errors when run during site installation before |
76 // date_default_timezone_set() is called. | 76 // date_default_timezone_set() is called. |
77 $this->_po_date = @date("Y-m-d H:iO"); | 77 $this->poDate = @date("Y-m-d H:iO"); |
78 $this->_pluralForms = 'nplurals=2; plural=(n > 1);'; | 78 $this->pluralForms = 'nplurals=2; plural=(n > 1);'; |
79 } | 79 } |
80 | 80 |
81 /** | 81 /** |
82 * Gets the plural form. | 82 * Gets the plural form. |
83 * | 83 * |
84 * @return string | 84 * @return string |
85 * Plural form component from the header, for example: | 85 * Plural form component from the header, for example: |
86 * 'nplurals=2; plural=(n > 1);'. | 86 * 'nplurals=2; plural=(n > 1);'. |
87 */ | 87 */ |
88 public function getPluralForms() { | 88 public function getPluralForms() { |
89 return $this->_pluralForms; | 89 return $this->pluralForms; |
90 } | 90 } |
91 | 91 |
92 /** | 92 /** |
93 * Set the human readable language name. | 93 * Set the human readable language name. |
94 * | 94 * |
95 * @param string $languageName | 95 * @param string $languageName |
96 * Human readable language name. | 96 * Human readable language name. |
97 */ | 97 */ |
98 public function setLanguageName($languageName) { | 98 public function setLanguageName($languageName) { |
99 $this->_languageName = $languageName; | 99 $this->languageName = $languageName; |
100 } | 100 } |
101 | 101 |
102 /** | 102 /** |
103 * Gets the human readable language name. | 103 * Gets the human readable language name. |
104 * | 104 * |
105 * @return string | 105 * @return string |
106 * The human readable language name. | 106 * The human readable language name. |
107 */ | 107 */ |
108 public function getLanguageName() { | 108 public function getLanguageName() { |
109 return $this->_languageName; | 109 return $this->languageName; |
110 } | 110 } |
111 | 111 |
112 /** | 112 /** |
113 * Set the project name. | 113 * Set the project name. |
114 * | 114 * |
115 * @param string $projectName | 115 * @param string $projectName |
116 * Human readable project name. | 116 * Human readable project name. |
117 */ | 117 */ |
118 public function setProjectName($projectName) { | 118 public function setProjectName($projectName) { |
119 $this->_projectName = $projectName; | 119 $this->projectName = $projectName; |
120 } | 120 } |
121 | 121 |
122 /** | 122 /** |
123 * Gets the project name. | 123 * Gets the project name. |
124 * | 124 * |
125 * @return string | 125 * @return string |
126 * The human readable project name. | 126 * The human readable project name. |
127 */ | 127 */ |
128 public function getProjectName() { | 128 public function getProjectName() { |
129 return $this->_projectName; | 129 return $this->projectName; |
130 } | 130 } |
131 | 131 |
132 /** | 132 /** |
133 * Populate internal values from a string. | 133 * Populate internal values from a string. |
134 * | 134 * |
140 $values = $this->parseHeader($header); | 140 $values = $this->parseHeader($header); |
141 | 141 |
142 // There is only one value relevant for our header implementation when | 142 // There is only one value relevant for our header implementation when |
143 // reading, and that is the plural formula. | 143 // reading, and that is the plural formula. |
144 if (!empty($values['Plural-Forms'])) { | 144 if (!empty($values['Plural-Forms'])) { |
145 $this->_pluralForms = $values['Plural-Forms']; | 145 $this->pluralForms = $values['Plural-Forms']; |
146 } | 146 } |
147 } | 147 } |
148 | 148 |
149 /** | 149 /** |
150 * Generate a Gettext PO formatted header string based on data set earlier. | 150 * Generate a Gettext PO formatted header string based on data set earlier. |
151 */ | 151 */ |
152 public function __toString() { | 152 public function __toString() { |
153 $output = ''; | 153 $output = ''; |
154 | 154 |
155 $isTemplate = empty($this->_languageName); | 155 $isTemplate = empty($this->languageName); |
156 | 156 |
157 $output .= '# ' . ($isTemplate ? 'LANGUAGE' : $this->_languageName) . ' translation of ' . ($isTemplate ? 'PROJECT' : $this->_projectName) . "\n"; | 157 $output .= '# ' . ($isTemplate ? 'LANGUAGE' : $this->languageName) . ' translation of ' . ($isTemplate ? 'PROJECT' : $this->projectName) . "\n"; |
158 if (!empty($this->_authors)) { | 158 if (!empty($this->authors)) { |
159 $output .= '# Generated by ' . implode("\n# ", $this->_authors) . "\n"; | 159 $output .= '# Generated by ' . implode("\n# ", $this->authors) . "\n"; |
160 } | 160 } |
161 $output .= "#\n"; | 161 $output .= "#\n"; |
162 | 162 |
163 // Add the actual header information. | 163 // Add the actual header information. |
164 $output .= "msgid \"\"\n"; | 164 $output .= "msgid \"\"\n"; |
165 $output .= "msgstr \"\"\n"; | 165 $output .= "msgstr \"\"\n"; |
166 $output .= "\"Project-Id-Version: PROJECT VERSION\\n\"\n"; | 166 $output .= "\"Project-Id-Version: PROJECT VERSION\\n\"\n"; |
167 $output .= "\"POT-Creation-Date: " . $this->_po_date . "\\n\"\n"; | 167 $output .= "\"POT-Creation-Date: " . $this->poDate . "\\n\"\n"; |
168 $output .= "\"PO-Revision-Date: " . $this->_po_date . "\\n\"\n"; | 168 $output .= "\"PO-Revision-Date: " . $this->poDate . "\\n\"\n"; |
169 $output .= "\"Last-Translator: NAME <EMAIL@ADDRESS>\\n\"\n"; | 169 $output .= "\"Last-Translator: NAME <EMAIL@ADDRESS>\\n\"\n"; |
170 $output .= "\"Language-Team: LANGUAGE <EMAIL@ADDRESS>\\n\"\n"; | 170 $output .= "\"Language-Team: LANGUAGE <EMAIL@ADDRESS>\\n\"\n"; |
171 $output .= "\"MIME-Version: 1.0\\n\"\n"; | 171 $output .= "\"MIME-Version: 1.0\\n\"\n"; |
172 $output .= "\"Content-Type: text/plain; charset=utf-8\\n\"\n"; | 172 $output .= "\"Content-Type: text/plain; charset=utf-8\\n\"\n"; |
173 $output .= "\"Content-Transfer-Encoding: 8bit\\n\"\n"; | 173 $output .= "\"Content-Transfer-Encoding: 8bit\\n\"\n"; |
174 $output .= "\"Plural-Forms: " . $this->_pluralForms . "\\n\"\n"; | 174 $output .= "\"Plural-Forms: " . $this->pluralForms . "\\n\"\n"; |
175 $output .= "\n"; | 175 $output .= "\n"; |
176 | 176 |
177 return $output; | 177 return $output; |
178 } | 178 } |
179 | 179 |