Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento get language code in template file

Tags:

php

magento

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.

Does it already exist?

I have something in mind like the URL-helper

$url = $this->helper('core/url')->getCurrentUrl();
like image 394
chmoelders Avatar asked Jul 05 '11 07:07

chmoelders


4 Answers

You can get the current locale code this way :

$locale = Mage::app()->getLocale()->getLocaleCode();
like image 138
FbnFgc Avatar answered Sep 22 '22 13:09

FbnFgc


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.

like image 27
Jordan VALNET Avatar answered Sep 23 '22 13:09

Jordan VALNET


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());
like image 33
Jürgen Thelen Avatar answered Sep 20 '22 13:09

Jürgen Thelen


Try

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

where $_store is current store object

like image 24
snh_nl Avatar answered Sep 23 '22 13:09

snh_nl