本文整理汇总了PHP中Magento\Framework\Locale\ResolverInterface::getLocaleCode方法的典型用法代码示例。如果您正苦于以下问题:PHP ResolverInterface::getLocaleCode方法的具体用法?PHP ResolverInterface::getLocaleCode怎么用?PHP ResolverInterface::getLocaleCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Locale\ResolverInterface
的用法示例。
在下文中一共展示了ResolverInterface::getLocaleCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getLang
/**
* Get current language
*
* @return string
*/
public function getLang()
{
if (!$this->hasData('lang')) {
$this->setData('lang', substr($this->_localeResolver->getLocaleCode(), 0, 2));
}
return $this->getData('lang');
}
示例2: _initSelect
/**
* Initialize select object
*
* @return $this
*/
protected function _initSelect()
{
parent::_initSelect();
$locale = $this->_localeResolver->getLocaleCode();
$this->addBindParam(':region_locale', $locale);
$this->getSelect()->joinLeft(array('rname' => $this->_regionNameTable), 'main_table.region_id = rname.region_id AND rname.locale = :region_locale', array('name'));
return $this;
}
示例3: process
/**
* Process localized quantity to internal format
*
* @param float $qty
* @return array|string
*/
public function process($qty)
{
$this->localFilter->setOptions(array('locale' => $this->localeResolver->getLocaleCode()));
$qty = $this->localFilter->filter((double) $qty);
if ($qty < 0) {
$qty = null;
}
return $qty;
}
示例4: _toHtml
/**
* Disable block output if logo turned off
*M
* @return string
*/
protected function _toHtml()
{
$type = $this->getLogoType();
// assigned in layout etc.
$logoUrl = $this->_getConfig()->getAdditionalOptionsLogoUrl($this->_localeResolver->getLocaleCode(), $type);
if (!$logoUrl) {
return '';
}
$this->setLogoImageUrl($logoUrl);
return parent::_toHtml();
}
示例5: process
/**
* Process localized quantity to internal format
*
* @param float $qty
* @return array|string
*/
public function process($qty)
{
if (!$this->localFilter) {
$this->localFilter = new \Zend_Filter_LocalizedToNormalized(array('locale' => $this->localeResolver->getLocaleCode()));
}
$qty = $this->localFilter->filter((double) $qty);
if ($qty < 0) {
$qty = null;
}
return $qty;
}
示例6: saveTranslate
/**
* Save translation
*
* @param String $string
* @param String $translate
* @param String $locale
* @param int|null $storeId
* @return $this
*/
public function saveTranslate($string, $translate, $locale = null, $storeId = null)
{
$write = $this->_getWriteAdapter();
$table = $this->getMainTable();
if (is_null($locale)) {
$locale = $this->_localeResolver->getLocaleCode();
}
if (is_null($storeId)) {
$storeId = $this->getStoreId();
}
$select = $write->select()->from($table, array('key_id', 'translate'))->where('store_id = :store_id')->where('locale = :locale')->where('string = :string')->where('crc_string = :crc_string');
$bind = array('store_id' => $storeId, 'locale' => $locale, 'string' => $string, 'crc_string' => crc32($string));
if ($row = $write->fetchRow($select, $bind)) {
$original = $string;
if (strpos($original, '::') !== false) {
list(, $original) = explode('::', $original);
}
if ($original == $translate) {
$write->delete($table, array('key_id=?' => $row['key_id']));
} elseif ($row['translate'] != $translate) {
$write->update($table, array('translate' => $translate), array('key_id=?' => $row['key_id']));
}
} else {
$write->insert($table, array('store_id' => $storeId, 'locale' => $locale, 'string' => $string, 'translate' => $translate, 'crc_string' => crc32($string)));
}
return $this;
}
示例7: load
/**
* Load backup file info
*
* @param string $fileName
* @param string $filePath
* @return $this
*/
public function load($fileName, $filePath)
{
$backupData = $this->_helper->extractDataFromFilename($fileName);
$this->addData(array('id' => $filePath . '/' . $fileName, 'time' => (int) $backupData->getTime(), 'path' => $filePath, 'extension' => $this->_helper->getExtensionByType($backupData->getType()), 'display_name' => $this->_helper->nameToDisplayName($backupData->getName()), 'name' => $backupData->getName(), 'date_object' => new \Magento\Framework\Stdlib\DateTime\Date((int) $backupData->getTime(), $this->_localeResolver->getLocaleCode())));
$this->setType($backupData->getType());
return $this;
}
示例8: toOptionArray
/**
* Convert collection items to select options array
*
* @param string|boolean $emptyLabel
* @return array
*/
public function toOptionArray($emptyLabel = ' ')
{
$options = $this->_toOptionArray('country_id', 'name', array('title' => 'iso2_code'));
$sort = array();
foreach ($options as $data) {
$name = (string) $this->_localeLists->getCountryTranslation($data['value']);
if (!empty($name)) {
$sort[$name] = $data['value'];
}
}
$this->_arrayUtils->ksortMultibyte($sort, $this->_localeResolver->getLocaleCode());
foreach (array_reverse($this->_foregroundCountries) as $foregroundCountry) {
$name = array_search($foregroundCountry, $sort);
unset($sort[$name]);
$sort = array($name => $foregroundCountry) + $sort;
}
$options = array();
foreach ($sort as $label => $value) {
$options[] = array('value' => $value, 'label' => $label);
}
if (count($options) > 0 && $emptyLabel !== false) {
array_unshift($options, array('value' => '', 'label' => $emptyLabel));
}
return $options;
}
示例9: _emulateLocale
/**
* Apply locale of the specified store
*
* @param integer $storeId
* @param string $area
* @return string initial locale code
*/
protected function _emulateLocale($storeId, $area = \Magento\Framework\App\Area::AREA_FRONTEND)
{
$initialLocaleCode = $this->_localeResolver->getLocaleCode();
$newLocaleCode = $this->_scopeConfig->getValue($this->_localeResolver->getDefaultLocalePath(), \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId);
$this->_localeResolver->setLocaleCode($newLocaleCode);
$this->_translate->setLocale($newLocaleCode)->loadData($area, true);
return $initialLocaleCode;
}
示例10: getCacheKeyInfo
/**
* Get Key pieces for caching block content
*
* @return array
*/
public function getCacheKeyInfo()
{
$cacheKeyInfo = array('admin_top_nav', $this->getActive(), $this->_authSession->getUser()->getId(), $this->_localeResolver->getLocaleCode());
// Add additional key parameters if needed
$newCacheKeyInfo = $this->getAdditionalCacheKeyInfo();
if (is_array($newCacheKeyInfo) && !empty($newCacheKeyInfo)) {
$cacheKeyInfo = array_merge($cacheKeyInfo, $newCacheKeyInfo);
}
return $cacheKeyInfo;
}
示例11: _processLocaleSettings
/**
* Set session locale,
* process force locale set through url params
*
* @return $this
*/
protected function _processLocaleSettings()
{
$forceLocale = $this->getRequest()->getParam('locale', null);
if ($this->_objectManager->get('Magento\\Framework\\Locale\\Validator')->isValid($forceLocale)) {
$this->_getSession()->setSessionLocale($forceLocale);
}
if (is_null($this->_getSession()->getLocale())) {
$this->_getSession()->setLocale($this->_localeResolver->getLocaleCode());
}
return $this;
}
示例12: _loadByCountry
/**
* Load object by country id and code or default name
*
* @param \Magento\Framework\Model\AbstractModel $object
* @param int $countryId
* @param string $value
* @param string $field
* @return $this
*/
protected function _loadByCountry($object, $countryId, $value, $field)
{
$adapter = $this->_getReadAdapter();
$locale = $this->_localeResolver->getLocaleCode();
$joinCondition = $adapter->quoteInto('rname.region_id = region.region_id AND rname.locale = ?', $locale);
$select = $adapter->select()->from(array('region' => $this->getMainTable()))->joinLeft(array('rname' => $this->_regionNameTable), $joinCondition, array('name'))->where('region.country_id = ?', $countryId)->where("region.{$field} = ?", $value);
$data = $adapter->fetchRow($select);
if ($data) {
$object->setData($data);
}
$this->_afterLoad($object);
return $this;
}
示例13: _beforeSave
/**
* Prepare data for save
*
* @return $this
* @throws Exception
*/
protected function _beforeSave()
{
// prevent overriding product data
if (isset($this->_data['attribute_code']) && $this->reservedAttributeList->isReservedAttribute($this)) {
throw new Exception(__('The attribute code \'%1\' is reserved by system. Please try another attribute code', $this->_data['attribute_code']));
}
/**
* Check for maximum attribute_code length
*/
if (isset($this->_data['attribute_code']) && !\Zend_Validate::is($this->_data['attribute_code'], 'StringLength', array('max' => self::ATTRIBUTE_CODE_MAX_LENGTH))) {
throw new Exception(__('Maximum length of attribute code must be less than %1 symbols', self::ATTRIBUTE_CODE_MAX_LENGTH));
}
$defaultValue = $this->getDefaultValue();
$hasDefaultValue = (string) $defaultValue != '';
if ($this->getBackendType() == 'decimal' && $hasDefaultValue) {
if (!\Zend_Locale_Format::isNumber($defaultValue, array('locale' => $this->_localeResolver->getLocaleCode()))) {
throw new Exception(__('Invalid default decimal value'));
}
try {
$filter = new \Zend_Filter_LocalizedToNormalized(array('locale' => $this->_localeResolver->getLocaleCode()));
$this->setDefaultValue($filter->filter($defaultValue));
} catch (\Exception $e) {
throw new Exception(__('Invalid default decimal value'));
}
}
if ($this->getBackendType() == 'datetime') {
if (!$this->getBackendModel()) {
$this->setBackendModel('Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\Datetime');
}
if (!$this->getFrontendModel()) {
$this->setFrontendModel('Magento\\Eav\\Model\\Entity\\Attribute\\Frontend\\Datetime');
}
// save default date value as timestamp
if ($hasDefaultValue) {
$format = $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT);
try {
$defaultValue = $this->_localeDate->date($defaultValue, $format, null, false)->toValue();
$this->setDefaultValue($defaultValue);
} catch (\Exception $e) {
throw new Exception(__('Invalid default date'));
}
}
}
if ($this->getBackendType() == 'gallery') {
if (!$this->getBackendModel()) {
$this->setBackendModel('Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\DefaultBackend');
}
}
return parent::_beforeSave();
}
示例14: getHtml
/**
* @return string
*/
public function getHtml()
{
$htmlId = $this->mathRandom->getUniqueHash($this->_getHtmlId());
$format = $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT);
$html = '<div class="range" id="' . $htmlId . '_range"><div class="range-line date">' . '<input type="text" name="' . $this->_getHtmlName() . '[from]" id="' . $htmlId . '_from"' . ' value="' . $this->getEscapedValue('from') . '" class="input-text no-changes" placeholder="' . __('From') . '" ' . $this->getUiId('filter', $this->_getHtmlName(), 'from') . '/>' . '</div>';
$html .= '<div class="range-line date">' . '<input type="text" name="' . $this->_getHtmlName() . '[to]" id="' . $htmlId . '_to"' . ' value="' . $this->getEscapedValue('to') . '" class="input-text no-changes" placeholder="' . __('To') . '" ' . $this->getUiId('filter', $this->_getHtmlName(), 'to') . '/>' . '</div></div>';
$html .= '<input type="hidden" name="' . $this->_getHtmlName() . '[locale]"' . ' value="' . $this->_localeResolver->getLocaleCode() . '"/>';
$html .= '<script type="text/javascript">
require(["jquery", "mage/calendar"], function($){
$("#' . $htmlId . '_range").dateRange({
dateFormat: "' . $format . '",
buttonImage: "' . $this->getViewFileUrl('images/grid-cal.gif') . '",
buttonText: "' . $this->escapeHtml(__('Date selector')) . '",
from: {
id: "' . $htmlId . '_from"
},
to: {
id: "' . $htmlId . '_to"
}
})
});
</script>';
return $html;
}
示例15: setPageHelpUrl
/**
* @param string|null $url
* @return $this
*/
public function setPageHelpUrl($url = null)
{
if (is_null($url)) {
$request = $this->_request;
$frontModule = $request->getControllerModule();
if (!$frontModule) {
$frontModule = $this->_routeConfig->getModulesByFrontName($request->getModuleName());
if (empty($frontModule) === false) {
$frontModule = $frontModule[0];
} else {
$frontModule = null;
}
}
$url = 'http://www.magentocommerce.com/gethelp/';
$url .= $this->_locale->getLocaleCode() . '/';
$url .= $frontModule . '/';
$url .= $request->getControllerName() . '/';
$url .= $request->getActionName() . '/';
$this->_pageHelpUrl = $url;
}
$this->_pageHelpUrl = $url;
return $this;
}