Commit d9f93782 authored by alexpott's avatar alexpott

Issue #2935190 by mohit1604, aryashreep, Lan Anh, Sutharsan, longwave,...

Issue #2935190 by mohit1604, aryashreep, Lan Anh, Sutharsan, longwave, alexpott, mikispeed, webflo, John Cook: Fix variable names in Gettext component
parent b8704f83
......@@ -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 @@ public function __construct($langcode = NULL) {
* 'nplurals=2; plural=(n > 1);'.
*/
public function getPluralForms() {
return $this->_pluralForms;
return $this->pluralForms;
}
/**
......@@ -96,7 +96,7 @@ public function getPluralForms() {
* Human readable language name.
*/
public function setLanguageName($languageName) {
$this->_languageName = $languageName;
$this->languageName = $languageName;
}
/**
......@@ -106,7 +106,7 @@ public function setLanguageName($languageName) {
* The human readable language name.
*/
public function getLanguageName() {
return $this->_languageName;
return $this->languageName;
}
/**
......@@ -116,7 +116,7 @@ public function getLanguageName() {
* Human readable project name.
*/
public function setProjectName($projectName) {
$this->_projectName = $projectName;
$this->projectName = $projectName;
}
/**
......@@ -126,7 +126,7 @@ public function setProjectName($projectName) {
* The human readable project name.
*/
public function getProjectName() {
return $this->_projectName;
return $this->projectName;
}
/**
......@@ -142,7 +142,7 @@ public function setFromString($header) {
// 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 @@ public function setFromString($header) {
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 @@ public function __toString() {
$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;
......
......@@ -15,45 +15,45 @@ class PoItem {
*
* @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|array
*
* @see $_plural
* @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|array
* @see $_plural
* @see $plural
*/
private $_translation;
protected $translation;
/**
* Gets the language code of the currently used language.
......@@ -61,7 +61,7 @@ class PoItem {
* @return string with langcode
*/
public function getLangcode() {
return $this->_langcode;
return $this->langcode;
}
/**
......@@ -70,7 +70,7 @@ public function getLangcode() {
* @param string $langcode
*/
public function setLangcode($langcode) {
$this->_langcode = $langcode;
$this->langcode = $langcode;
}
/**
......@@ -79,7 +79,7 @@ public function setLangcode($langcode) {
* @return string $context
*/
public function getContext() {
return $this->_context;
return $this->context;
}
/**
......@@ -88,7 +88,7 @@ public function getContext() {
* @param string $context
*/
public function setContext($context) {
$this->_context = $context;
$this->context = $context;
}
/**
......@@ -98,7 +98,7 @@ public function setContext($context) {
* @return string or array $translation
*/
public function getSource() {
return $this->_source;
return $this->source;
}
/**
......@@ -108,7 +108,7 @@ public function getSource() {
* @param string|array $source
*/
public function setSource($source) {
$this->_source = $source;
$this->source = $source;
}
/**
......@@ -118,7 +118,7 @@ public function setSource($source) {
* @return string or array $translation
*/
public function getTranslation() {
return $this->_translation;
return $this->translation;
}
/**
......@@ -128,7 +128,7 @@ public function getTranslation() {
* @param string|array $translation
*/
public function setTranslation($translation) {
$this->_translation = $translation;
$this->translation = $translation;
}
/**
......@@ -137,7 +137,7 @@ public function setTranslation($translation) {
* @param bool $plural
*/
public function setPlural($plural) {
$this->_plural = $plural;
$this->plural = $plural;
}
/**
......@@ -146,7 +146,7 @@ public function setPlural($plural) {
* @return bool
*/
public function isPlural() {
return $this->_plural;
return $this->plural;
}
/**
......@@ -155,7 +155,7 @@ public function isPlural() {
* @return String $comment
*/
public function getComment() {
return $this->_comment;
return $this->comment;
}
/**
......@@ -164,7 +164,7 @@ public function getComment() {
* @param string $comment
*/
public function setComment($comment) {
$this->_comment = $comment;
$this->comment = $comment;
}
/**
......@@ -185,11 +185,11 @@ public function setFromArray(array $values = []) {
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);
}
}
......@@ -207,12 +207,12 @@ private function formatItem() {
$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 {
......@@ -232,11 +232,11 @@ private function formatPlural() {
$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 {
......@@ -252,8 +252,8 @@ private function formatPlural() {
*/
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;
}
......
......@@ -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 @@ public function writeItem(PoItem $item) {
$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 @@ public function writeItems(PoReaderInterface $reader, $count = -1) {
* @return array PoItem
*/
public function getData() {
return $this->_items;
return $this->items;
}
/**
......
......@@ -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 @@ public function getHeader() {
* The Gettext PO header to set.
*/
public function setHeader(PoHeader $header) {
$this->_header = $header;
$this->header = $header;
}
/**
......@@ -55,7 +62,7 @@ public function setHeader(PoHeader $header) {
* The language code.
*/
public function getLangcode() {
return $this->_langcode;
return $this->langcode;
}
/**
......@@ -65,7 +72,7 @@ public function getLangcode() {
* The language code.
*/
public function setLangcode($langcode) {
$this->_langcode = $langcode;
$this->langcode = $langcode;
}
/**
......@@ -73,7 +80,7 @@ public function setLangcode($langcode) {
*/
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();
}
......@@ -85,8 +92,8 @@ public function open() {
* 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.');
......@@ -104,7 +111,7 @@ public function close() {
* If writing the data is not possible.
*/
private function write($data) {
$result = fwrite($this->_fd, $data);
$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 @@ private function write($data) {
* Write the PO header to the stream.
*/
private function writeHeader() {
$this->write($this->_header);
$this->write($this->header);
}
/**
......@@ -141,17 +148,17 @@ public function writeItems(PoReaderInterface $reader, $count = -1) {
* If the URI is not set.
*/
public function getURI() {
if (empty($this->_uri)) {
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;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment