Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Translate Class Reference
Inheritance diagram for Translate:
AbstractDb ResourceInterface AbstractResource Translate

Public Member Functions

 __construct (\Magento\Framework\Model\ResourceModel\Db\Context $context, \Magento\Framework\App\ScopeResolverInterface $scopeResolver, $connectionName=null, $scope=null)
 
 getTranslationArray ($storeId=null, $locale=null)
 
 getTranslationArrayByStrings (array $strings, $storeId=null)
 
 getMainChecksum ()
 
 getConnection ()
 
- Public Member Functions inherited from AbstractDb
 __construct (\Magento\Framework\Model\ResourceModel\Db\Context $context, $connectionName=null)
 
 __sleep ()
 
 __wakeup ()
 
 getIdFieldName ()
 
 getMainTable ()
 
 getTable ($tableName)
 
 getConnection ()
 
 load (\Magento\Framework\Model\AbstractModel $object, $value, $field=null)
 
 save (\Magento\Framework\Model\AbstractModel $object)
 
 delete (\Magento\Framework\Model\AbstractModel $object)
 
 addUniqueField ($field)
 
 resetUniqueField ()
 
 unserializeFields (\Magento\Framework\Model\AbstractModel $object)
 
 getUniqueFields ()
 
 hasDataChanged ($object)
 
 getChecksum ($table)
 
 afterLoad (\Magento\Framework\DataObject $object)
 
 beforeSave (\Magento\Framework\DataObject $object)
 
 afterSave (\Magento\Framework\DataObject $object)
 
 beforeDelete (\Magento\Framework\DataObject $object)
 
 afterDelete (\Magento\Framework\DataObject $object)
 
 serializeFields (\Magento\Framework\Model\AbstractModel $object)
 
- Public Member Functions inherited from AbstractResource
 __construct ()
 
 getConnection ()
 
 beginTransaction ()
 
 addCommitCallback ($callback)
 
 commit ()
 
 rollBack ()
 
 getValidationRulesBeforeSave ()
 

Protected Member Functions

 _construct ()
 
 getStoreId ()
 
- Protected Member Functions inherited from AbstractDb
 _init ($mainTable, $idFieldName)
 
 _setResource ($connections, $tables=null)
 
 _setMainTable ($mainTable, $idFieldName=null)
 
 _getConnection ($resourceName)
 
 _getLoadSelect ($field, $value, $object)
 
 _initUniqueFields ()
 
 _prepareDataForSave (\Magento\Framework\Model\AbstractModel $object)
 
 _prepareValueForSave ($value, $type)
 
 _checkUnique (\Magento\Framework\Model\AbstractModel $object)
 
 _afterLoad (\Magento\Framework\Model\AbstractModel $object)
 
 _beforeSave (\Magento\Framework\Model\AbstractModel $object)
 
 _afterSave (\Magento\Framework\Model\AbstractModel $object)
 
 _beforeDelete (\Magento\Framework\Model\AbstractModel $object)
 
 _afterDelete (\Magento\Framework\Model\AbstractModel $object)
 
 _serializeFields (\Magento\Framework\Model\AbstractModel $object)
 
 prepareDataForUpdate ($object)
 
 isObjectNotNew (\Magento\Framework\Model\AbstractModel $object)
 
 saveNewObject (\Magento\Framework\Model\AbstractModel $object)
 
 updateObject (\Magento\Framework\Model\AbstractModel $object)
 
 processAfterSaves (\Magento\Framework\Model\AbstractModel $object)
 
 isModified (\Magento\Framework\Model\AbstractModel $object)
 
 processNotModifiedSave (\Magento\Framework\Model\AbstractModel $object)
 
- Protected Member Functions inherited from AbstractResource
 _construct ()
 
 _serializeField (DataObject $object, $field, $defaultValue=null, $unsetEmpty=false)
 
 _unserializeField (DataObject $object, $field, $defaultValue=null)
 
 _prepareDataForTable (DataObject $object, $table)
 
 _prepareTableValueForSave ($value, $type)
 
 _getColumnsForEntityLoad (\Magento\Framework\Model\AbstractModel $object, $tableName)
 
 getSerializer ()
 

Protected Attributes

 $scopeResolver
 
 $scope
 
- Protected Attributes inherited from AbstractDb
 $_resources
 
 $connectionName = \Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION
 
 $_connections = []
 
 $_resourceModel
 
 $_tables = []
 
 $_mainTable
 
 $_idFieldName
 
 $_isPkAutoIncrement = true
 
 $_useIsObjectNew = false
 
 $_mainTableFields
 
 $_uniqueFields = null
 
 $_serializableFields = []
 
 $transactionManager
 
 $objectRelationProcessor
 
- Protected Attributes inherited from AbstractResource
 $serializer
 
 $_logger
 

Detailed Description

Definition at line 13 of file Translate.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\Model\ResourceModel\Db\Context  $context,
\Magento\Framework\App\ScopeResolverInterface  $scopeResolver,
  $connectionName = null,
  $scope = null 
)
Parameters
\Magento\Framework\Model\ResourceModel\Db\Context$context
\Magento\Framework\App\ScopeResolverInterface$scopeResolver
string$connectionName
null | string$scope

Definition at line 42 of file Translate.php.

Member Function Documentation

◆ _construct()

_construct ( )
protected

Define main table

Returns
void

Definition at line 58 of file Translate.php.

59  {
60  $this->_init('translation', 'key_id');
61  }

◆ getConnection()

getConnection ( )

Get connection

Returns
\Magento\Framework\DB\Adapter\AdapterInterface|false

Definition at line 142 of file Translate.php.

143  {
144  if (!$this->getDeployedConfig()->isDbAvailable()) {
145  return false;
146  }
147  return parent::getConnection();
148  }

◆ getMainChecksum()

getMainChecksum ( )

Retrieve table checksum

Returns
int

Definition at line 132 of file Translate.php.

◆ getStoreId()

getStoreId ( )
protected

Retrieve current store identifier

Returns
int

Definition at line 155 of file Translate.php.

156  {
157  return $this->scopeResolver->getScope($this->scope)->getId();
158  }

◆ getTranslationArray()

getTranslationArray (   $storeId = null,
  $locale = null 
)

Retrieve translation array for store / locale code

Parameters
int$storeId
string$locale
Returns
array

Implements ResourceInterface.

Definition at line 70 of file Translate.php.

71  {
72  if ($storeId === null) {
73  $storeId = $this->getStoreId();
74  }
75  $locale = (string) $locale;
76 
77  $data = $this->getAppConfig()->get(
79  $locale . '/' . $this->getStoreCode($storeId),
80  []
81  );
82  $connection = $this->getConnection();
83  if ($connection) {
84  $select = $connection->select()
85  ->from($this->getMainTable(), ['string', 'translate'])
86  ->where('store_id IN (0 , :store_id)')
87  ->where('locale = :locale')
88  ->order('store_id');
89  $bind = [':locale' => $locale, ':store_id' => $storeId];
90  $dbData = $connection->fetchPairs($select, $bind);
91  $data = array_replace($data, $dbData);
92  }
93  return $data;
94  }
$connection
Definition: bulk.php:13

◆ getTranslationArrayByStrings()

getTranslationArrayByStrings ( array  $strings,
  $storeId = null 
)

Retrieve translations array by strings

Parameters
array$strings
int | null$storeId
Returns
array

Definition at line 103 of file Translate.php.

104  {
105  if ($storeId === null) {
106  $storeId = $this->getStoreId();
107  }
108 
109  $connection = $this->getConnection();
110  if (!$connection) {
111  return [];
112  }
113 
114  if (empty($strings)) {
115  return [];
116  }
117 
118  $bind = [':store_id' => $storeId];
119  $select = $connection->select()
120  ->from($this->getMainTable(), ['string', 'translate'])
121  ->where('string IN (?)', $strings)
122  ->where('store_id = :store_id');
123 
124  return $connection->fetchPairs($select, $bind);
125  }
$connection
Definition: bulk.php:13

Field Documentation

◆ $scope

$scope
protected

Definition at line 24 of file Translate.php.

◆ $scopeResolver

$scopeResolver
protected

Definition at line 19 of file Translate.php.


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