开发者

Magento get language code in template file

开发者 https://www.devze.com 2023-03-18 13:04 出处:网络
I need a helper function to get the current language code. I want to use it in a templete file, like /products/view.phtml, only for testing purposes.

I need a helper function to get the current language code. I want to use it in a templete file, like /products/view.phtml, only for testing purposes.

D开发者_运维技巧oes it already exist?

I have something in mind like the URL-helper

$url = $this->helper('core/url')->getCurrentUrl();


You can get the current locale code this way :

$locale = Mage::app()->getLocale()->getLocaleCode();


Result for answers given in this topic for "Belgium:French" (Be_Fr):

  • strtolower(Mage::getStoreConfig('general/country/default')); = be
  • substr(Mage::getStoreConfig('general/locale/code'),0,2); = fr
  • Mage::app()->getLocale()->getLocaleCode(); = fr_BE

Note that

Mage::app()->getLocale()->getLocaleCode() == Mage::getStoreConfig('general/locale/code')

but with the second one, you can specify an other store than default one (Mage::getStoreConfig('general/locale/code', $storeId)), so I would recommand it.


Afaik there is no such helper function, but you could of course build your own using:

Mage::getStoreConfig('general/locale/code', Mage::app()->getStore()->getId());


Try

$_language_code = substr(Mage::getStoreConfig('general/locale/code', $_store->getId()),0,2);

where $_store is current store object


You can also use :

$languageCode = Mage::app()->getStore()->getLanguageCode();

Don't forget to configure your store locales in your admin. Go to menu :

System -> Configuration -> General -> Locale Options

And set the correct Locale for each Websites or stores


For use in the html elements lang attribute etc.

echo strtolower(Mage::getStoreConfig('general/country/default')); // "en"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号