本文整理汇总了PHP中Magento\Framework\Locale\ResolverInterface::getLocale方法的典型用法代码示例。如果您正苦于以下问题:PHP ResolverInterface::getLocale方法的具体用法?PHP ResolverInterface::getLocale怎么用?PHP ResolverInterface::getLocale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Locale\ResolverInterface
的用法示例。
在下文中一共展示了ResolverInterface::getLocale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateAndGetTranslations
/**
* Clears cache and updates translations file
*
* @return array
*/
public function updateAndGetTranslations()
{
$this->eventManager->dispatch('adminhtml_cache_flush_system');
$translations = $this->translateResource->getTranslationArray(null, $this->localeResolver->getLocale());
$this->fileManager->updateTranslationFileContent(json_encode($translations));
return $translations;
}
示例2: getLang
/**
* Get current language
*
* @return string
*/
public function getLang()
{
if (!$this->hasData('lang')) {
$this->setData('lang', substr($this->_localeResolver->getLocale(), 0, 2));
}
return $this->getData('lang');
}
示例3: _toHtml
/**
* Render block HTML
*
* @return string
*/
protected function _toHtml()
{
$localeData = (new DataBundle())->get($this->_localeResolver->getLocale());
// get days names
$daysData = $localeData['calendar']['gregorian']['dayNames'];
$this->assign('days', ['wide' => $this->encoder->encode(array_values(iterator_to_array($daysData['format']['wide']))), 'abbreviated' => $this->encoder->encode(array_values(iterator_to_array($daysData['format']['abbreviated'])))]);
// get months names
$monthsData = $localeData['calendar']['gregorian']['monthNames'];
$this->assign('months', ['wide' => $this->encoder->encode(array_values(iterator_to_array($monthsData['format']['wide']))), 'abbreviated' => $this->encoder->encode(array_values(iterator_to_array($monthsData['format']['abbreviated'])))]);
// get "today" and "week" words
$this->assign('today', $this->encoder->encode($localeData['fields']['day']['relative']['0']));
$this->assign('week', $this->encoder->encode($localeData['fields']['week']['dn']));
// get "am" & "pm" words
$this->assign('am', $this->encoder->encode($localeData['calendar']['gregorian']['AmPmMarkers']['0']));
$this->assign('pm', $this->encoder->encode($localeData['calendar']['gregorian']['AmPmMarkers']['1']));
// get first day of week and weekend days
$this->assign('firstDay', (int) $this->_scopeConfig->getValue('general/locale/firstday', \Magento\Store\Model\ScopeInterface::SCOPE_STORE));
$this->assign('weekendDays', $this->encoder->encode((string) $this->_scopeConfig->getValue('general/locale/weekend', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)));
// define default format and tooltip format
$this->assign('defaultFormat', $this->encoder->encode($this->_localeDate->getDateFormat(\IntlDateFormatter::MEDIUM)));
$this->assign('toolTipFormat', $this->encoder->encode($this->_localeDate->getDateFormat(\IntlDateFormatter::LONG)));
// get days and months for en_US locale - calendar will parse exactly in this locale
$englishMonths = (new DataBundle())->get('en_US')['calendar']['gregorian']['monthNames'];
$enUS = new \stdClass();
$enUS->m = new \stdClass();
$enUS->m->wide = array_values(iterator_to_array($englishMonths['format']['wide']));
$enUS->m->abbr = array_values(iterator_to_array($englishMonths['format']['abbreviated']));
$this->assign('enUS', $this->encoder->encode($enUS));
return parent::_toHtml();
}
示例4: getPriceFormat
/**
* Functions returns array with price formatting info
*
* @return array
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function getPriceFormat()
{
$localeData = (new DataBundle())->get($this->_localeResolver->getLocale());
$format = $localeData['NumberElements']['latn']['patterns']['currencyFormat'] ?: explode(';', $localeData['NumberPatterns'][1])[0];
$decimalSymbol = $localeData['NumberElements']['latn']['symbols']['decimal'] ?: $localeData['NumberElements'][0];
$groupSymbol = $localeData['NumberElements']['latn']['symbols']['group'] ?: $localeData['NumberElements'][1];
$pos = strpos($format, ';');
if ($pos !== false) {
$format = substr($format, 0, $pos);
}
$format = preg_replace("/[^0\\#\\.,]/", "", $format);
$totalPrecision = 0;
$decimalPoint = strpos($format, '.');
if ($decimalPoint !== false) {
$totalPrecision = strlen($format) - (strrpos($format, '.') + 1);
} else {
$decimalPoint = strlen($format);
}
$requiredPrecision = $totalPrecision;
$t = substr($format, $decimalPoint);
$pos = strpos($t, '#');
if ($pos !== false) {
$requiredPrecision = strlen($t) - $pos - $totalPrecision;
}
if (strrpos($format, ',') !== false) {
$group = $decimalPoint - strrpos($format, ',') - 1;
} else {
$group = strrpos($format, '.');
}
$integerRequired = strpos($format, '.') - strpos($format, '0');
$result = ['pattern' => $this->_scopeResolver->getScope()->getCurrentCurrency()->getOutputFormat(), 'precision' => $totalPrecision, 'requiredPrecision' => $requiredPrecision, 'decimalSymbol' => $decimalSymbol, 'groupSymbol' => $groupSymbol, 'groupLength' => $group, 'integerRequired' => $integerRequired];
return $result;
}
示例5: getCurrentLocale
/**
* return current locale code
*/
public function getCurrentLocale()
{
if ($this->_localeResolver->getLocale() == 'ja_JP') {
return 'ja';
}
return 'en';
}
示例6: aroundAddNameToSelect
/**
* @param \Magento\Customer\Model\ResourceModel\Customer\Collection $subject
* @param \Closure $proceed
* @return \Magento\Customer\Model\ResourceModel\Customer\Collection
*/
public function aroundAddNameToSelect(Collection $subject, \Closure $proceed)
{
$fields = [];
$customerAccount = $this->fieldsetConfig->getFieldset('customer_account');
foreach ($customerAccount as $code => $field) {
if (isset($field['name'])) {
$fields[$code] = $code;
}
}
$connection = $subject->getConnection();
$concatenate = [];
if (isset($fields['prefix'])) {
$concatenate[] = $connection->getCheckSql('{{prefix}} IS NOT NULL AND {{prefix}} != \'\'', $connection->getConcatSql(['LTRIM(RTRIM({{prefix}}))', '\' \'']), '\'\'');
}
if ($this->localeResolver->getLocale() != 'ja_JP') {
$concatenate[] = 'LTRIM(RTRIM({{firstname}}))';
} else {
$concatenate[] = 'LTRIM(RTRIM({{lastname}}))';
}
$concatenate[] = '\' \'';
if (isset($fields['middlename'])) {
$concatenate[] = $connection->getCheckSql('{{middlename}} IS NOT NULL AND {{middlename}} != \'\'', $connection->getConcatSql(['LTRIM(RTRIM({{middlename}}))', '\' \'']), '\'\'');
}
if ($this->localeResolver->getLocale() != 'ja_JP') {
$concatenate[] = 'LTRIM(RTRIM({{lastname}}))';
} else {
$concatenate[] = 'LTRIM(RTRIM({{firstname}}))';
}
if (isset($fields['suffix'])) {
$concatenate[] = $connection->getCheckSql('{{suffix}} IS NOT NULL AND {{suffix}} != \'\'', $connection->getConcatSql(['\' \'', 'LTRIM(RTRIM({{suffix}}))']), '\'\'');
}
$nameExpr = $connection->getConcatSql($concatenate);
$subject->addExpressionAttributeToSelect('name', $nameExpr, $fields);
return $subject;
}
示例7: outputFilter
/**
* Returns the result of filtering $value
*
* @param string $value
* @return string
*/
public function outputFilter($value)
{
$filterInput = new \Zend_Filter_LocalizedToNormalized(['date_format' => DateTime::DATE_INTERNAL_FORMAT, 'locale' => $this->localeResolver->getLocale()]);
$filterInternal = new \Zend_Filter_NormalizedToLocalized(['date_format' => $this->_dateFormat, 'locale' => $this->localeResolver->getLocale()]);
$value = $filterInput->filter($value);
$value = $filterInternal->filter($value);
return $value;
}
示例8: _initSelect
/**
* Initialize select object
*
* @return $this
*/
protected function _initSelect()
{
parent::_initSelect();
$locale = $this->_localeResolver->getLocale();
$this->addBindParam(':region_locale', $locale);
$this->getSelect()->joinLeft(['rname' => $this->_regionNameTable], 'main_table.region_id = rname.region_id AND rname.locale = :region_locale', ['name']);
return $this;
}
示例9: getConfig
/**
* @return array|void
*/
public function getConfig()
{
if (!$this->config->isActive()) {
return [];
}
$clientToken = $this->config->getClientToken();
$config = ['payment' => ['braintree_paypal' => ['clientToken' => $clientToken, 'locale' => $this->localeResolver->getLocale(), 'merchantDisplayName' => $this->config->getMerchantNameOverride()]]];
return $config;
}
示例10: process
/**
* Process localized quantity to internal format
*
* @param float $qty
* @return array|string
*/
public function process($qty)
{
$this->localFilter->setOptions(['locale' => $this->localeResolver->getLocale()]);
$qty = $this->localFilter->filter((double) $qty);
if ($qty < 0) {
$qty = null;
}
return $qty;
}
示例11: install
/**
* {@inheritdoc}
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$days = (new DataBundle())->get($this->localeResolver->getLocale())['calendar']['gregorian']['dayNames']['format']['abbreviated'];
$select = $setup->getConnection()->select()->from($setup->getTable('core_config_data'), ['config_id', 'value'])->where('path = ?', 'carriers/dhl/shipment_days');
foreach ($setup->getConnection()->fetchAll($select) as $configRow) {
$row = ['value' => implode(',', array_intersect_key(iterator_to_array($days), array_flip(explode(',', $configRow['value']))))];
$setup->getConnection()->update($setup->getTable('core_config_data'), $row, ['config_id = ?' => $configRow['config_id']]);
}
}
示例12: _construct
/**
* Set template and redirect message
*
* @return null
*/
protected function _construct()
{
$this->_config = $this->_paypalConfigFactory->create()->setMethod($this->getMethodCode());
$mark = $this->_getMarkTemplate();
$mark->setPaymentAcceptanceMarkHref($this->_config->getPaymentMarkWhatIsPaypalUrl($this->_localeResolver))->setPaymentAcceptanceMarkSrc($this->_config->getPaymentMarkImageUrl($this->_localeResolver->getLocale()));
// known issue: code above will render only static mark image
$this->_initializeRedirectTemplateWithMark($mark);
parent::_construct();
$this->setRedirectMessage(__('You will be redirected to the PayPal website.'));
}
示例13: getConfig
/**
* {@inheritdoc}
*/
public function getConfig()
{
$config = ['payment' => ['paypalExpress' => ['paymentAcceptanceMarkHref' => $this->config->getPaymentMarkWhatIsPaypalUrl($this->localeResolver), 'paymentAcceptanceMarkSrc' => $this->config->getPaymentMarkImageUrl($this->localeResolver->getLocale())]]];
foreach ($this->methodCodes as $code) {
if ($this->methods[$code]->isAvailable()) {
$config['payment']['paypalExpress']['redirectUrl'][$code] = $this->getMethodRedirectUrl($code);
$config['payment']['paypalExpress']['billingAgreementCode'][$code] = $this->getBillingAgreementCode($code);
}
}
return $config;
}
示例14: _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->getLocale(), $type);
if (!$logoUrl) {
return '';
}
$this->setLogoImageUrl($logoUrl);
return parent::_toHtml();
}
示例15: _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)
{
$connection = $this->getConnection();
$locale = $this->_localeResolver->getLocale();
$joinCondition = $connection->quoteInto('rname.region_id = region.region_id AND rname.locale = ?', $locale);
$select = $connection->select()->from(['region' => $this->getMainTable()])->joinLeft(['rname' => $this->_regionNameTable], $joinCondition, ['name'])->where('region.country_id = ?', $countryId)->where("region.{$field} = ?", $value);
$data = $connection->fetchRow($select);
if ($data) {
$object->setData($data);
}
$this->_afterLoad($object);
return $this;
}