Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions
Zend_Translate_Adapter_Gettext Class Reference
Inheritance diagram for Zend_Translate_Adapter_Gettext:
Zend_Translate_Adapter

Public Member Functions

 getAdapterInfo ()
 
 toString ()
 
- Public Member Functions inherited from Zend_Translate_Adapter
 __construct ($options=array())
 
 addTranslation ($options=array())
 
 setOptions (array $options=array())
 
 getOptions ($optionKey=null)
 
 getLocale ()
 
 setLocale ($locale)
 
 getList ()
 
 getMessageId ($message, $locale=null)
 
 getMessageIds ($locale=null)
 
 getMessages ($locale=null)
 
 isAvailable ($locale)
 
 translate ($messageId, $locale=null)
 
 plural ($singular, $plural, $number, $locale=null)
 
 _ ($messageId, $locale=null)
 
 isTranslated ($messageId, $original=false, $locale=null)
 
 toString ()
 

Protected Member Functions

 _loadTranslationData ($filename, $locale, array $options=array())
 
- Protected Member Functions inherited from Zend_Translate_Adapter
 _loadTranslationData ($data, $locale, array $options=array())
 
 _log ($message, $locale)
 

Additional Inherited Members

- Static Public Member Functions inherited from Zend_Translate_Adapter
static getCache ()
 
static setCache (Zend_Cache_Core $cache)
 
static hasCache ()
 
static removeCache ()
 
static clearCache ($tag=null)
 
- Data Fields inherited from Zend_Translate_Adapter
const LOCALE_DIRECTORY = 'directory'
 
const LOCALE_FILENAME = 'filename'
 
- Protected Attributes inherited from Zend_Translate_Adapter
 $_options
 
 $_translate = array()
 
- Static Protected Attributes inherited from Zend_Translate_Adapter
static $_cache = null
 

Detailed Description

Definition at line 34 of file Gettext.php.

Member Function Documentation

◆ _loadTranslationData()

_loadTranslationData (   $filename,
  $locale,
array  $options = array() 
)
protected

Load translation data (MO file reader)

Parameters
string$filenameMO file to add, full path must be given for access
string$localeNew Locale/Language to set, identical with locale identifier, see Zend_Locale for more information
array$optionOPTIONAL Options to use
Exceptions
Zend_Translation_Exception
Returns
array

Definition at line 65 of file Gettext.php.

66  {
67  $this->_data = array();
68  $this->_bigEndian = false;
69  $this->_file = @fopen($filename, 'rb');
70  if (!$this->_file) {
71  #require_once 'Zend/Translate/Exception.php';
72  throw new Zend_Translate_Exception('Error opening translation file \'' . $filename . '\'.');
73  }
74  if (@filesize($filename) < 10) {
75  @fclose($this->_file);
76  #require_once 'Zend/Translate/Exception.php';
77  throw new Zend_Translate_Exception('\'' . $filename . '\' is not a gettext file');
78  }
79 
80  // get Endian
81  $input = $this->_readMOData(1);
82  if (strtolower(substr(dechex($input[1]), -8)) == "950412de") {
83  $this->_bigEndian = false;
84  } else if (strtolower(substr(dechex($input[1]), -8)) == "de120495") {
85  $this->_bigEndian = true;
86  } else {
87  @fclose($this->_file);
88  #require_once 'Zend/Translate/Exception.php';
89  throw new Zend_Translate_Exception('\'' . $filename . '\' is not a gettext file');
90  }
91  // read revision - not supported for now
92  $input = $this->_readMOData(1);
93 
94  // number of bytes
95  $input = $this->_readMOData(1);
96  $total = $input[1];
97 
98  // number of original strings
99  $input = $this->_readMOData(1);
100  $OOffset = $input[1];
101 
102  // number of translation strings
103  $input = $this->_readMOData(1);
104  $TOffset = $input[1];
105 
106  // fill the original table
107  fseek($this->_file, $OOffset);
108  $origtemp = $this->_readMOData(2 * $total);
109  fseek($this->_file, $TOffset);
110  $transtemp = $this->_readMOData(2 * $total);
111 
112  for($count = 0; $count < $total; ++$count) {
113  if ($origtemp[$count * 2 + 1] != 0) {
114  fseek($this->_file, $origtemp[$count * 2 + 2]);
115  $original = @fread($this->_file, $origtemp[$count * 2 + 1]);
116  $original = explode("\0", $original);
117  } else {
118  $original[0] = '';
119  }
120 
121  if ($transtemp[$count * 2 + 1] != 0) {
122  fseek($this->_file, $transtemp[$count * 2 + 2]);
123  $translate = fread($this->_file, $transtemp[$count * 2 + 1]);
124  $translate = explode("\0", $translate);
125  if ((count($original) > 1)) {
126  $this->_data[$locale][$original[0]] = $translate;
127  array_shift($original);
128  foreach ($original as $orig) {
129  $this->_data[$locale][$orig] = '';
130  }
131  } else {
132  $this->_data[$locale][$original[0]] = $translate[0];
133  }
134  }
135  }
136 
137  @fclose($this->_file);
138 
139  $this->_data[$locale][''] = trim($this->_data[$locale]['']);
140  if (empty($this->_data[$locale][''])) {
141  $this->_adapterInfo[$filename] = 'No adapter information available';
142  } else {
143  $this->_adapterInfo[$filename] = $this->_data[$locale][''];
144  }
145 
146  unset($this->_data[$locale]['']);
147  return $this->_data;
148  }

◆ getAdapterInfo()

getAdapterInfo ( )

Returns the adapter informations

Returns
array Each loaded adapter information as array value

Definition at line 155 of file Gettext.php.

156  {
157  return $this->_adapterInfo;
158  }

◆ toString()

toString ( )

Returns the adapter name

Returns
string

Definition at line 165 of file Gettext.php.

166  {
167  return "Gettext";
168  }

The documentation for this class was generated from the following file: