Calcetines Extreme

Calcetines Extreme
Take care of you using the best socks

Sunday, March 23, 2014

#magento How to detect language from php code

Yo need to change some content at low level in a phtml file on a multi language site using Magento, when you use multilingual you have to create content in a each language that you need, so, how you can call content choosing the correct language ?

That's simple process using a sentence to read the loaded language on the site using the next sentence:


That sentence return that string for Spanish one:   en_EN

To load a Static Block you only need to use something like that:
$locale = Mage::app()->getLocale()->getLocaleCode();
$locale = substr($locale, 0, 2);
switch ($locale) {
case "es":
  echo $this->getLayout()->createBlock('cms/block')->setBlockId(CopyRight)->toHtml();
case "en":
  echo $this->getLayout()->createBlock('cms/block')->setBlockId(CopyRight_en)->toHtml();