Update Composer, update everything

This commit is contained in:
Oliver Davies 2018-11-23 12:29:20 +00:00
parent ea3e94409f
commit dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions

View file

@ -27,42 +27,42 @@ class PoHeader {
*
* @var string
*/
private $_langcode;
protected $langcode;
/**
* Formula for the plural form.
*
* @var string
*/
private $_pluralForms;
protected $pluralForms;
/**
* Author(s) of the file.
*
* @var string
*/
private $_authors;
protected $authors;
/**
* Date the po file got created.
*
* @var string
*/
private $_po_date;
protected $poDate;
/**
* Human readable language name.
*
* @var string
*/
private $_languageName;
protected $languageName;
/**
* Name of the project the translation belongs to.
*
* @var string
*/
private $_projectName;
protected $projectName;
/**
* Constructor, creates a PoHeader with default values.
@ -71,11 +71,11 @@ class PoHeader {
* Language code.
*/
public function __construct($langcode = NULL) {
$this->_langcode = $langcode;
$this->langcode = $langcode;
// Ignore errors when run during site installation before
// date_default_timezone_set() is called.
$this->_po_date = @date("Y-m-d H:iO");
$this->_pluralForms = 'nplurals=2; plural=(n > 1);';
$this->poDate = @date("Y-m-d H:iO");
$this->pluralForms = 'nplurals=2; plural=(n > 1);';
}
/**
@ -86,7 +86,7 @@ class PoHeader {
* 'nplurals=2; plural=(n > 1);'.
*/
public function getPluralForms() {
return $this->_pluralForms;
return $this->pluralForms;
}
/**
@ -96,7 +96,7 @@ class PoHeader {
* Human readable language name.
*/
public function setLanguageName($languageName) {
$this->_languageName = $languageName;
$this->languageName = $languageName;
}
/**
@ -106,7 +106,7 @@ class PoHeader {
* The human readable language name.
*/
public function getLanguageName() {
return $this->_languageName;
return $this->languageName;
}
/**
@ -116,7 +116,7 @@ class PoHeader {
* Human readable project name.
*/
public function setProjectName($projectName) {
$this->_projectName = $projectName;
$this->projectName = $projectName;
}
/**
@ -126,7 +126,7 @@ class PoHeader {
* The human readable project name.
*/
public function getProjectName() {
return $this->_projectName;
return $this->projectName;
}
/**
@ -142,7 +142,7 @@ class PoHeader {
// There is only one value relevant for our header implementation when
// reading, and that is the plural formula.
if (!empty($values['Plural-Forms'])) {
$this->_pluralForms = $values['Plural-Forms'];
$this->pluralForms = $values['Plural-Forms'];
}
}
@ -152,11 +152,11 @@ class PoHeader {
public function __toString() {
$output = '';
$isTemplate = empty($this->_languageName);
$isTemplate = empty($this->languageName);
$output .= '# ' . ($isTemplate ? 'LANGUAGE' : $this->_languageName) . ' translation of ' . ($isTemplate ? 'PROJECT' : $this->_projectName) . "\n";
if (!empty($this->_authors)) {
$output .= '# Generated by ' . implode("\n# ", $this->_authors) . "\n";
$output .= '# ' . ($isTemplate ? 'LANGUAGE' : $this->languageName) . ' translation of ' . ($isTemplate ? 'PROJECT' : $this->projectName) . "\n";
if (!empty($this->authors)) {
$output .= '# Generated by ' . implode("\n# ", $this->authors) . "\n";
}
$output .= "#\n";
@ -164,14 +164,14 @@ class PoHeader {
$output .= "msgid \"\"\n";
$output .= "msgstr \"\"\n";
$output .= "\"Project-Id-Version: PROJECT VERSION\\n\"\n";
$output .= "\"POT-Creation-Date: " . $this->_po_date . "\\n\"\n";
$output .= "\"PO-Revision-Date: " . $this->_po_date . "\\n\"\n";
$output .= "\"POT-Creation-Date: " . $this->poDate . "\\n\"\n";
$output .= "\"PO-Revision-Date: " . $this->poDate . "\\n\"\n";
$output .= "\"Last-Translator: NAME <EMAIL@ADDRESS>\\n\"\n";
$output .= "\"Language-Team: LANGUAGE <EMAIL@ADDRESS>\\n\"\n";
$output .= "\"MIME-Version: 1.0\\n\"\n";
$output .= "\"Content-Type: text/plain; charset=utf-8\\n\"\n";
$output .= "\"Content-Transfer-Encoding: 8bit\\n\"\n";
$output .= "\"Plural-Forms: " . $this->_pluralForms . "\\n\"\n";
$output .= "\"Plural-Forms: " . $this->pluralForms . "\\n\"\n";
$output .= "\n";
return $output;
@ -188,7 +188,7 @@ class PoHeader {
* - 'nplurals': The number of plural forms defined by the plural formula.
* - 'plurals': Array of plural positions keyed by plural value.
*
* @throws Exception
* @throws \Exception
*/
public function parsePluralForms($pluralforms) {
$plurals = [];
@ -473,7 +473,7 @@ class PoHeader {
* Number of the plural string to be used for the given plural value.
*
* @see parseArithmetic()
* @throws Exception
* @throws \Exception
*/
protected function evaluatePlural($element_stack, $n) {
$count = count($element_stack);

View file

@ -13,46 +13,47 @@ class PoItem {
/**
* The language code this translation is in.
*
* @car string
* @var string
*/
private $_langcode;
protected $langcode;
/**
* The context this translation belongs to.
*
* @var string
*/
private $_context = '';
protected $context = '';
/**
* The source string or array of strings if it has plurals.
*
* @var string or array
* @see $_plural
* @var string|array
*
* @see $plural
*/
private $_source;
protected $source;
/**
* Flag indicating if this translation has plurals.
*
* @var bool
*/
private $_plural;
protected $plural;
/**
* The comment of this translation.
*
* @var string
*/
private $_comment;
protected $comment;
/**
* The translation string or array of strings if it has plurals.
*
* @var string or array
* @see $_plural
* @var string|array
* @see $plural
*/
private $_translation;
protected $translation;
/**
* Gets the language code of the currently used language.
@ -60,7 +61,7 @@ class PoItem {
* @return string with langcode
*/
public function getLangcode() {
return $this->_langcode;
return $this->langcode;
}
/**
@ -69,7 +70,7 @@ class PoItem {
* @param string $langcode
*/
public function setLangcode($langcode) {
$this->_langcode = $langcode;
$this->langcode = $langcode;
}
/**
@ -78,7 +79,7 @@ class PoItem {
* @return string $context
*/
public function getContext() {
return $this->_context;
return $this->context;
}
/**
@ -87,7 +88,7 @@ class PoItem {
* @param string $context
*/
public function setContext($context) {
$this->_context = $context;
$this->context = $context;
}
/**
@ -97,17 +98,17 @@ class PoItem {
* @return string or array $translation
*/
public function getSource() {
return $this->_source;
return $this->source;
}
/**
* Set the source string or the array of strings if the translation has
* plurals.
*
* @param string or array $source
* @param string|array $source
*/
public function setSource($source) {
$this->_source = $source;
$this->source = $source;
}
/**
@ -117,17 +118,17 @@ class PoItem {
* @return string or array $translation
*/
public function getTranslation() {
return $this->_translation;
return $this->translation;
}
/**
* Set the translation string or the array of strings if the translation has
* plurals.
*
* @param string or array $translation
* @param string|array $translation
*/
public function setTranslation($translation) {
$this->_translation = $translation;
$this->translation = $translation;
}
/**
@ -136,7 +137,7 @@ class PoItem {
* @param bool $plural
*/
public function setPlural($plural) {
$this->_plural = $plural;
$this->plural = $plural;
}
/**
@ -145,7 +146,7 @@ class PoItem {
* @return bool
*/
public function isPlural() {
return $this->_plural;
return $this->plural;
}
/**
@ -154,7 +155,7 @@ class PoItem {
* @return String $comment
*/
public function getComment() {
return $this->_comment;
return $this->comment;
}
/**
@ -163,7 +164,7 @@ class PoItem {
* @param string $comment
*/
public function setComment($comment) {
$this->_comment = $comment;
$this->comment = $comment;
}
/**
@ -184,11 +185,11 @@ class PoItem {
if (isset($values['comment'])) {
$this->setComment($values['comment']);
}
if (isset($this->_source) &&
strpos($this->_source, LOCALE_PLURAL_DELIMITER) !== FALSE) {
$this->setSource(explode(LOCALE_PLURAL_DELIMITER, $this->_source));
$this->setTranslation(explode(LOCALE_PLURAL_DELIMITER, $this->_translation));
$this->setPlural(count($this->_source) > 1);
if (isset($this->source) &&
strpos($this->source, LOCALE_PLURAL_DELIMITER) !== FALSE) {
$this->setSource(explode(LOCALE_PLURAL_DELIMITER, $this->source));
$this->setTranslation(explode(LOCALE_PLURAL_DELIMITER, $this->translation));
$this->setPlural(count($this->source) > 1);
}
}
@ -206,12 +207,12 @@ class PoItem {
$output = '';
// Format string context.
if (!empty($this->_context)) {
$output .= 'msgctxt ' . $this->formatString($this->_context);
if (!empty($this->context)) {
$output .= 'msgctxt ' . $this->formatString($this->context);
}
// Format translation.
if ($this->_plural) {
if ($this->plural) {
$output .= $this->formatPlural();
}
else {
@ -231,11 +232,11 @@ class PoItem {
$output = '';
// Format source strings.
$output .= 'msgid ' . $this->formatString($this->_source[0]);
$output .= 'msgid_plural ' . $this->formatString($this->_source[1]);
$output .= 'msgid ' . $this->formatString($this->source[0]);
$output .= 'msgid_plural ' . $this->formatString($this->source[1]);
foreach ($this->_translation as $i => $trans) {
if (isset($this->_translation[$i])) {
foreach ($this->translation as $i => $trans) {
if (isset($this->translation[$i])) {
$output .= 'msgstr[' . $i . '] ' . $this->formatString($trans);
}
else {
@ -251,8 +252,8 @@ class PoItem {
*/
private function formatSingular() {
$output = '';
$output .= 'msgid ' . $this->formatString($this->_source);
$output .= 'msgstr ' . (isset($this->_translation) ? $this->formatString($this->_translation) : '""');
$output .= 'msgid ' . $this->formatString($this->source);
$output .= 'msgstr ' . (isset($this->translation) ? $this->formatString($this->translation) : '""');
return $output;
}

View file

@ -12,13 +12,13 @@ class PoMemoryWriter implements PoWriterInterface {
*
* @var array
*/
private $_items;
protected $items;
/**
* Constructor, initialize empty items.
*/
public function __construct() {
$this->_items = [];
$this->items = [];
}
/**
@ -30,7 +30,7 @@ class PoMemoryWriter implements PoWriterInterface {
$item->setTranslation(implode(LOCALE_PLURAL_DELIMITER, $item->getTranslation()));
}
$context = $item->getContext();
$this->_items[$context != NULL ? $context : ''][$item->getSource()] = $item->getTranslation();
$this->items[$context != NULL ? $context : ''][$item->getSource()] = $item->getTranslation();
}
/**
@ -49,7 +49,7 @@ class PoMemoryWriter implements PoWriterInterface {
* @return array PoItem
*/
public function getData() {
return $this->_items;
return $this->items;
}
/**

View file

@ -2,7 +2,7 @@
namespace Drupal\Component\Gettext;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Component\Render\FormattableMarkup;
/**
* Implements Gettext PO stream reader.
@ -17,7 +17,7 @@ class PoStreamReader implements PoStreamInterface, PoReaderInterface {
*
* @var int
*/
private $_line_number = 0;
protected $lineNumber = 0;
/**
* Parser context for the stream reader state machine.
@ -32,90 +32,90 @@ class PoStreamReader implements PoStreamInterface, PoReaderInterface {
*
* @var string
*/
private $_context = 'COMMENT';
protected $context = 'COMMENT';
/**
* Current entry being read. Incomplete.
*
* @var array
*/
private $_current_item = [];
protected $currentItem = [];
/**
* Current plural index for plural translations.
*
* @var int
*/
private $_current_plural_index = 0;
protected $currentPluralIndex = 0;
/**
* URI of the PO stream that is being read.
*
* @var string
*/
private $_uri = '';
protected $uri = '';
/**
* Language code for the PO stream being read.
*
* @var string
*/
private $_langcode = NULL;
protected $langcode = NULL;
/**
* File handle of the current PO stream.
*
* @var resource
*/
private $_fd;
protected $fd;
/**
* The PO stream header.
*
* @var \Drupal\Component\Gettext\PoHeader
*/
private $_header;
protected $header;
/**
* Object wrapper for the last read source/translation pair.
*
* @var \Drupal\Component\Gettext\PoItem
*/
private $_last_item;
protected $lastItem;
/**
* Indicator of whether the stream reading is finished.
*
* @var bool
*/
private $_finished;
protected $finished;
/**
* Array of translated error strings recorded on reading this stream so far.
*
* @var array
*/
private $_errors;
protected $errors;
/**
* {@inheritdoc}
*/
public function getLangcode() {
return $this->_langcode;
return $this->langcode;
}
/**
* {@inheritdoc}
*/
public function setLangcode($langcode) {
$this->_langcode = $langcode;
$this->langcode = $langcode;
}
/**
* {@inheritdoc}
*/
public function getHeader() {
return $this->_header;
return $this->header;
}
/**
@ -130,14 +130,14 @@ class PoStreamReader implements PoStreamInterface, PoReaderInterface {
* {@inheritdoc}
*/
public function getURI() {
return $this->_uri;
return $this->uri;
}
/**
* {@inheritdoc}
*/
public function setURI($uri) {
$this->_uri = $uri;
$this->uri = $uri;
}
/**
@ -146,12 +146,12 @@ class PoStreamReader implements PoStreamInterface, PoReaderInterface {
* Opens the stream and reads the header. The stream is ready for reading
* items after.
*
* @throws Exception
* @throws \Exception
* If the URI is not yet set.
*/
public function open() {
if (!empty($this->_uri)) {
$this->_fd = fopen($this->_uri, 'rb');
if (!empty($this->uri)) {
$this->fd = fopen($this->uri, 'rb');
$this->readHeader();
}
else {
@ -162,12 +162,12 @@ class PoStreamReader implements PoStreamInterface, PoReaderInterface {
/**
* Implements Drupal\Component\Gettext\PoStreamInterface::close().
*
* @throws Exception
* @throws \Exception
* If the stream is not open.
*/
public function close() {
if ($this->_fd) {
fclose($this->_fd);
if ($this->fd) {
fclose($this->fd);
}
else {
throw new \Exception('Cannot close stream that is not open.');
@ -179,14 +179,14 @@ class PoStreamReader implements PoStreamInterface, PoReaderInterface {
*/
public function readItem() {
// Clear out the last item.
$this->_last_item = NULL;
$this->lastItem = NULL;
// Read until finished with the stream or a complete item was identified.
while (!$this->_finished && is_null($this->_last_item)) {
while (!$this->finished && is_null($this->lastItem)) {
$this->readLine();
}
return $this->_last_item;
return $this->lastItem;
}
/**
@ -196,14 +196,14 @@ class PoStreamReader implements PoStreamInterface, PoReaderInterface {
* The new seek position to set.
*/
public function setSeek($seek) {
fseek($this->_fd, $seek);
fseek($this->fd, $seek);
}
/**
* Gets the pointer position of the current PO stream.
*/
public function getSeek() {
return ftell($this->_fd);
return ftell($this->fd);
}
/**
@ -221,18 +221,18 @@ class PoStreamReader implements PoStreamInterface, PoReaderInterface {
}
$header = new PoHeader();
$header->setFromString(trim($item->getTranslation()));
$this->_header = $header;
$this->header = $header;
}
/**
* Reads a line from the PO stream and stores data internally.
*
* Expands $this->_current_item based on new data for the current item. If
* Expands $this->current_item based on new data for the current item. If
* this line ends the current item, it is saved with setItemFromArray() with
* data from $this->_current_item.
* data from $this->current_item.
*
* An internal state machine is maintained in this reader using
* $this->_context as the reading state. PO items are in between COMMENT
* $this->context as the reading state. PO items are in between COMMENT
* states (when items have at least one line or comment in between them) or
* indicated by MSGSTR or MSGSTR_ARR followed immediately by an MSGID or
* MSGCTXT (when items closely follow each other).
@ -245,25 +245,25 @@ class PoStreamReader implements PoStreamInterface, PoReaderInterface {
private function readLine() {
// Read a line and set the stream finished indicator if it was not
// possible anymore.
$line = fgets($this->_fd);
$this->_finished = ($line === FALSE);
$line = fgets($this->fd);
$this->finished = ($line === FALSE);
if (!$this->_finished) {
if (!$this->finished) {
if ($this->_line_number == 0) {
if ($this->lineNumber == 0) {
// The first line might come with a UTF-8 BOM, which should be removed.
$line = str_replace("\xEF\xBB\xBF", '', $line);
// Current plurality for 'msgstr[]'.
$this->_current_plural_index = 0;
$this->currentPluralIndex = 0;
}
// Track the line number for error reporting.
$this->_line_number++;
$this->lineNumber++;
// Initialize common values for error logging.
$log_vars = [
'%uri' => $this->getURI(),
'%line' => $this->_line_number,
'%line' => $this->lineNumber,
];
// Trim away the linefeed. \\n might appear at the end of the string if
@ -273,24 +273,24 @@ class PoStreamReader implements PoStreamInterface, PoReaderInterface {
if (!strncmp('#', $line, 1)) {
// Lines starting with '#' are comments.
if ($this->_context == 'COMMENT') {
if ($this->context == 'COMMENT') {
// Already in comment context, add to current comment.
$this->_current_item['#'][] = substr($line, 1);
$this->currentItem['#'][] = substr($line, 1);
}
elseif (($this->_context == 'MSGSTR') || ($this->_context == 'MSGSTR_ARR')) {
elseif (($this->context == 'MSGSTR') || ($this->context == 'MSGSTR_ARR')) {
// We are currently in string context, save current item.
$this->setItemFromArray($this->_current_item);
$this->setItemFromArray($this->currentItem);
// Start a new entry for the comment.
$this->_current_item = [];
$this->_current_item['#'][] = substr($line, 1);
$this->currentItem = [];
$this->currentItem['#'][] = substr($line, 1);
$this->_context = 'COMMENT';
$this->context = 'COMMENT';
return;
}
else {
// A comment following any other context is a syntax error.
$this->_errors[] = SafeMarkup::format('The translation stream %uri contains an error: "msgstr" was expected but not found on line %line.', $log_vars);
$this->errors[] = new FormattableMarkup('The translation stream %uri contains an error: "msgstr" was expected but not found on line %line.', $log_vars);
return FALSE;
}
return;
@ -298,9 +298,9 @@ class PoStreamReader implements PoStreamInterface, PoReaderInterface {
elseif (!strncmp('msgid_plural', $line, 12)) {
// A plural form for the current source string.
if ($this->_context != 'MSGID') {
if ($this->context != 'MSGID') {
// A plural form can only be added to an msgid directly.
$this->_errors[] = SafeMarkup::format('The translation stream %uri contains an error: "msgid_plural" was expected but not found on line %line.', $log_vars);
$this->errors[] = new FormattableMarkup('The translation stream %uri contains an error: "msgid_plural" was expected but not found on line %line.', $log_vars);
return FALSE;
}
@ -311,34 +311,34 @@ class PoStreamReader implements PoStreamInterface, PoReaderInterface {
$quoted = $this->parseQuoted($line);
if ($quoted === FALSE) {
// The plural form must be wrapped in quotes.
$this->_errors[] = SafeMarkup::format('The translation stream %uri contains a syntax error on line %line.', $log_vars);
$this->errors[] = new FormattableMarkup('The translation stream %uri contains a syntax error on line %line.', $log_vars);
return FALSE;
}
// Append the plural source to the current entry.
if (is_string($this->_current_item['msgid'])) {
if (is_string($this->currentItem['msgid'])) {
// The first value was stored as string. Now we know the context is
// plural, it is converted to array.
$this->_current_item['msgid'] = [$this->_current_item['msgid']];
$this->currentItem['msgid'] = [$this->currentItem['msgid']];
}
$this->_current_item['msgid'][] = $quoted;
$this->currentItem['msgid'][] = $quoted;
$this->_context = 'MSGID_PLURAL';
$this->context = 'MSGID_PLURAL';
return;
}
elseif (!strncmp('msgid', $line, 5)) {
// Starting a new message.
if (($this->_context == 'MSGSTR') || ($this->_context == 'MSGSTR_ARR')) {
if (($this->context == 'MSGSTR') || ($this->context == 'MSGSTR_ARR')) {
// We are currently in string context, save current item.
$this->setItemFromArray($this->_current_item);
$this->setItemFromArray($this->currentItem);
// Start a new context for the msgid.
$this->_current_item = [];
$this->currentItem = [];
}
elseif ($this->_context == 'MSGID') {
elseif ($this->context == 'MSGID') {
// We are currently already in the context, meaning we passed an id with no data.
$this->_errors[] = SafeMarkup::format('The translation stream %uri contains an error: "msgid" is unexpected on line %line.', $log_vars);
$this->errors[] = new FormattableMarkup('The translation stream %uri contains an error: "msgid" is unexpected on line %line.', $log_vars);
return FALSE;
}
@ -349,25 +349,25 @@ class PoStreamReader implements PoStreamInterface, PoReaderInterface {
$quoted = $this->parseQuoted($line);
if ($quoted === FALSE) {
// The message id must be wrapped in quotes.
$this->_errors[] = SafeMarkup::format('The translation stream %uri contains an error: invalid format for "msgid" on line %line.', $log_vars, $log_vars);
$this->errors[] = new FormattableMarkup('The translation stream %uri contains an error: invalid format for "msgid" on line %line.', $log_vars, $log_vars);
return FALSE;
}
$this->_current_item['msgid'] = $quoted;
$this->_context = 'MSGID';
$this->currentItem['msgid'] = $quoted;
$this->context = 'MSGID';
return;
}
elseif (!strncmp('msgctxt', $line, 7)) {
// Starting a new context.
if (($this->_context == 'MSGSTR') || ($this->_context == 'MSGSTR_ARR')) {
if (($this->context == 'MSGSTR') || ($this->context == 'MSGSTR_ARR')) {
// We are currently in string context, save current item.
$this->setItemFromArray($this->_current_item);
$this->_current_item = [];
$this->setItemFromArray($this->currentItem);
$this->currentItem = [];
}
elseif (!empty($this->_current_item['msgctxt'])) {
elseif (!empty($this->currentItem['msgctxt'])) {
// A context cannot apply to another context.
$this->_errors[] = SafeMarkup::format('The translation stream %uri contains an error: "msgctxt" is unexpected on line %line.', $log_vars);
$this->errors[] = new FormattableMarkup('The translation stream %uri contains an error: "msgctxt" is unexpected on line %line.', $log_vars);
return FALSE;
}
@ -378,37 +378,37 @@ class PoStreamReader implements PoStreamInterface, PoReaderInterface {
$quoted = $this->parseQuoted($line);
if ($quoted === FALSE) {
// The context string must be quoted.
$this->_errors[] = SafeMarkup::format('The translation stream %uri contains an error: invalid format for "msgctxt" on line %line.', $log_vars);
$this->errors[] = new FormattableMarkup('The translation stream %uri contains an error: invalid format for "msgctxt" on line %line.', $log_vars);
return FALSE;
}
$this->_current_item['msgctxt'] = $quoted;
$this->currentItem['msgctxt'] = $quoted;
$this->_context = 'MSGCTXT';
$this->context = 'MSGCTXT';
return;
}
elseif (!strncmp('msgstr[', $line, 7)) {
// A message string for a specific plurality.
if (($this->_context != 'MSGID') &&
($this->_context != 'MSGCTXT') &&
($this->_context != 'MSGID_PLURAL') &&
($this->_context != 'MSGSTR_ARR')) {
// Plural message strings must come after msgid, msgxtxt,
if (($this->context != 'MSGID') &&
($this->context != 'MSGCTXT') &&
($this->context != 'MSGID_PLURAL') &&
($this->context != 'MSGSTR_ARR')) {
// Plural message strings must come after msgid, msgctxt,
// msgid_plural, or other msgstr[] entries.
$this->_errors[] = SafeMarkup::format('The translation stream %uri contains an error: "msgstr[]" is unexpected on line %line.', $log_vars);
$this->errors[] = new FormattableMarkup('The translation stream %uri contains an error: "msgstr[]" is unexpected on line %line.', $log_vars);
return FALSE;
}
// Ensure the plurality is terminated.
if (strpos($line, ']') === FALSE) {
$this->_errors[] = SafeMarkup::format('The translation stream %uri contains an error: invalid format for "msgstr[]" on line %line.', $log_vars);
$this->errors[] = new FormattableMarkup('The translation stream %uri contains an error: invalid format for "msgstr[]" on line %line.', $log_vars);
return FALSE;
}
// Extract the plurality.
$frombracket = strstr($line, '[');
$this->_current_plural_index = substr($frombracket, 1, strpos($frombracket, ']') - 1);
$this->currentPluralIndex = substr($frombracket, 1, strpos($frombracket, ']') - 1);
// Skip to the next whitespace and trim away any further whitespace,
// bringing $line to the message text only.
@ -417,24 +417,24 @@ class PoStreamReader implements PoStreamInterface, PoReaderInterface {
$quoted = $this->parseQuoted($line);
if ($quoted === FALSE) {
// The string must be quoted.
$this->_errors[] = SafeMarkup::format('The translation stream %uri contains an error: invalid format for "msgstr[]" on line %line.', $log_vars);
$this->errors[] = new FormattableMarkup('The translation stream %uri contains an error: invalid format for "msgstr[]" on line %line.', $log_vars);
return FALSE;
}
if (!isset($this->_current_item['msgstr']) || !is_array($this->_current_item['msgstr'])) {
$this->_current_item['msgstr'] = [];
if (!isset($this->currentItem['msgstr']) || !is_array($this->currentItem['msgstr'])) {
$this->currentItem['msgstr'] = [];
}
$this->_current_item['msgstr'][$this->_current_plural_index] = $quoted;
$this->currentItem['msgstr'][$this->currentPluralIndex] = $quoted;
$this->_context = 'MSGSTR_ARR';
$this->context = 'MSGSTR_ARR';
return;
}
elseif (!strncmp("msgstr", $line, 6)) {
// A string pair for an msgid (with optional context).
if (($this->_context != 'MSGID') && ($this->_context != 'MSGCTXT')) {
if (($this->context != 'MSGID') && ($this->context != 'MSGCTXT')) {
// Strings are only valid within an id or context scope.
$this->_errors[] = SafeMarkup::format('The translation stream %uri contains an error: "msgstr" is unexpected on line %line.', $log_vars);
$this->errors[] = new FormattableMarkup('The translation stream %uri contains an error: "msgstr" is unexpected on line %line.', $log_vars);
return FALSE;
}
@ -445,13 +445,13 @@ class PoStreamReader implements PoStreamInterface, PoReaderInterface {
$quoted = $this->parseQuoted($line);
if ($quoted === FALSE) {
// The string must be quoted.
$this->_errors[] = SafeMarkup::format('The translation stream %uri contains an error: invalid format for "msgstr" on line %line.', $log_vars);
$this->errors[] = new FormattableMarkup('The translation stream %uri contains an error: invalid format for "msgstr" on line %line.', $log_vars);
return FALSE;
}
$this->_current_item['msgstr'] = $quoted;
$this->currentItem['msgstr'] = $quoted;
$this->_context = 'MSGSTR';
$this->context = 'MSGSTR';
return;
}
elseif ($line != '') {
@ -460,37 +460,37 @@ class PoStreamReader implements PoStreamInterface, PoReaderInterface {
$quoted = $this->parseQuoted($line);
if ($quoted === FALSE) {
// This string must be quoted.
$this->_errors[] = SafeMarkup::format('The translation stream %uri contains an error: string continuation expected on line %line.', $log_vars);
$this->errors[] = new FormattableMarkup('The translation stream %uri contains an error: string continuation expected on line %line.', $log_vars);
return FALSE;
}
// Append the string to the current item.
if (($this->_context == 'MSGID') || ($this->_context == 'MSGID_PLURAL')) {
if (is_array($this->_current_item['msgid'])) {
if (($this->context == 'MSGID') || ($this->context == 'MSGID_PLURAL')) {
if (is_array($this->currentItem['msgid'])) {
// Add string to last array element for plural sources.
$last_index = count($this->_current_item['msgid']) - 1;
$this->_current_item['msgid'][$last_index] .= $quoted;
$last_index = count($this->currentItem['msgid']) - 1;
$this->currentItem['msgid'][$last_index] .= $quoted;
}
else {
// Singular source, just append the string.
$this->_current_item['msgid'] .= $quoted;
$this->currentItem['msgid'] .= $quoted;
}
}
elseif ($this->_context == 'MSGCTXT') {
elseif ($this->context == 'MSGCTXT') {
// Multiline context name.
$this->_current_item['msgctxt'] .= $quoted;
$this->currentItem['msgctxt'] .= $quoted;
}
elseif ($this->_context == 'MSGSTR') {
elseif ($this->context == 'MSGSTR') {
// Multiline translation string.
$this->_current_item['msgstr'] .= $quoted;
$this->currentItem['msgstr'] .= $quoted;
}
elseif ($this->_context == 'MSGSTR_ARR') {
elseif ($this->context == 'MSGSTR_ARR') {
// Multiline plural translation string.
$this->_current_item['msgstr'][$this->_current_plural_index] .= $quoted;
$this->currentItem['msgstr'][$this->currentPluralIndex] .= $quoted;
}
else {
// No valid context to append to.
$this->_errors[] = SafeMarkup::format('The translation stream %uri contains an error: unexpected string on line %line.', $log_vars);
$this->errors[] = new FormattableMarkup('The translation stream %uri contains an error: unexpected string on line %line.', $log_vars);
return FALSE;
}
return;
@ -498,14 +498,16 @@ class PoStreamReader implements PoStreamInterface, PoReaderInterface {
}
// Empty line read or EOF of PO stream, close out the last entry.
if (($this->_context == 'MSGSTR') || ($this->_context == 'MSGSTR_ARR')) {
$this->setItemFromArray($this->_current_item);
$this->_current_item = [];
if (($this->context == 'MSGSTR') || ($this->context == 'MSGSTR_ARR')) {
$this->setItemFromArray($this->currentItem);
$this->currentItem = [];
}
elseif ($this->_context != 'COMMENT') {
$this->_errors[] = SafeMarkup::format('The translation stream %uri ended unexpectedly at line %line.', $log_vars);
elseif ($this->context != 'COMMENT') {
$this->errors[] = new FormattableMarkup('The translation stream %uri ended unexpectedly at line %line.', $log_vars);
return FALSE;
}
return;
}
/**
@ -531,11 +533,11 @@ class PoStreamReader implements PoStreamInterface, PoReaderInterface {
$item->setTranslation($value['msgstr']);
$item->setPlural($plural);
$item->setComment($comments);
$item->setLangcode($this->_langcode);
$item->setLangcode($this->langcode);
$this->_last_item = $item;
$this->lastItem = $item;
$this->_context = 'COMMENT';
$this->context = 'COMMENT';
}
/**

View file

@ -12,21 +12,28 @@ class PoStreamWriter implements PoWriterInterface, PoStreamInterface {
*
* @var string
*/
private $_uri;
protected $uri;
/**
* The Gettext PO header.
*
* @var \Drupal\Component\Gettext\PoHeader
*/
private $_header;
protected $header;
/**
* File handle of the current PO stream.
*
* @var resource
*/
private $_fd;
protected $fd;
/**
* The language code of this writer.
*
* @var string
*/
protected $langcode;
/**
* Gets the PO header of the current stream.
@ -35,7 +42,7 @@ class PoStreamWriter implements PoWriterInterface, PoStreamInterface {
* The Gettext PO header.
*/
public function getHeader() {
return $this->_header;
return $this->header;
}
/**
@ -45,7 +52,7 @@ class PoStreamWriter implements PoWriterInterface, PoStreamInterface {
* The Gettext PO header to set.
*/
public function setHeader(PoHeader $header) {
$this->_header = $header;
$this->header = $header;
}
/**
@ -55,7 +62,7 @@ class PoStreamWriter implements PoWriterInterface, PoStreamInterface {
* The language code.
*/
public function getLangcode() {
return $this->_langcode;
return $this->langcode;
}
/**
@ -65,7 +72,7 @@ class PoStreamWriter implements PoWriterInterface, PoStreamInterface {
* The language code.
*/
public function setLangcode($langcode) {
$this->_langcode = $langcode;
$this->langcode = $langcode;
}
/**
@ -73,7 +80,7 @@ class PoStreamWriter implements PoWriterInterface, PoStreamInterface {
*/
public function open() {
// Open in write mode. Will overwrite the stream if it already exists.
$this->_fd = fopen($this->getURI(), 'w');
$this->fd = fopen($this->getURI(), 'w');
// Write the header at the start.
$this->writeHeader();
}
@ -81,15 +88,15 @@ class PoStreamWriter implements PoWriterInterface, PoStreamInterface {
/**
* Implements Drupal\Component\Gettext\PoStreamInterface::close().
*
* @throws Exception
* @throws \Exception
* If the stream is not open.
*/
public function close() {
if ($this->_fd) {
fclose($this->_fd);
if ($this->fd) {
fclose($this->fd);
}
else {
throw new Exception('Cannot close stream that is not open.');
throw new \Exception('Cannot close stream that is not open.');
}
}
@ -100,13 +107,13 @@ class PoStreamWriter implements PoWriterInterface, PoStreamInterface {
* Piece of string to write to the stream. If the value is not directly a
* string, casting will happen in writing.
*
* @throws Exception
* @throws \Exception
* If writing the data is not possible.
*/
private function write($data) {
$result = fputs($this->_fd, $data);
if ($result === FALSE) {
throw new Exception('Unable to write data: ' . substr($data, 0, 20));
$result = fwrite($this->fd, $data);
if ($result === FALSE || $result != strlen($data)) {
throw new \Exception('Unable to write data: ' . substr($data, 0, 20));
}
}
@ -114,7 +121,7 @@ class PoStreamWriter implements PoWriterInterface, PoStreamInterface {
* Write the PO header to the stream.
*/
private function writeHeader() {
$this->write($this->_header);
$this->write($this->header);
}
/**
@ -137,21 +144,21 @@ class PoStreamWriter implements PoWriterInterface, PoStreamInterface {
/**
* Implements Drupal\Component\Gettext\PoStreamInterface::getURI().
*
* @throws Exception
* @throws \Exception
* If the URI is not set.
*/
public function getURI() {
if (empty($this->_uri)) {
throw new Exception('No URI set.');
if (empty($this->uri)) {
throw new \Exception('No URI set.');
}
return $this->_uri;
return $this->uri;
}
/**
* {@inheritdoc}
*/
public function setURI($uri) {
$this->_uri = $uri;
$this->uri = $uri;
}
}

View file

@ -2,7 +2,7 @@
"name": "drupal/core-gettext",
"description": "PHP library for reading PO files.",
"type": "library",
"license": "GPL-2.0+",
"license": "GPL-2.0-or-later",
"support": {
"issues": "https://www.drupal.org/project/issues/drupal",
"irc": "irc://irc.freenode.net/drupal-contribute",
@ -10,7 +10,7 @@
},
"require": {
"php": ">=5.5.9",
"drupal/core-utility": "~8.2"
"drupal/core-utility": "^8.2"
},
"autoload": {
"psr-4": {