2

how to remove all language from magento admin panel from footer left drop down. (interface locale). i want to set only two language in this

5

The problem here is that the dropdown is generated dynamically based on hardcoded locales.

Basically Mage_Adminhtml_Block_Page_Footer generates the select with the following code:

public function getLanguageSelect()
{
    $locale  = Mage::app()->getLocale();
    $cacheId = self::LOCALE_CACHE_KEY . $locale->getLocaleCode();
    $html    = Mage::app()->loadCache($cacheId);

    if (!$html) {
        $html = $this->getLayout()->createBlock('adminhtml/html_select')
            ->setName('locale')
            ->setId('interface_locale')
            ->setTitle(Mage::helper('page')->__('Interface Language'))
            ->setExtraParams('style="width:200px"')
            ->setValue($locale->getLocaleCode())
            ->setOptions($locale->getTranslatedOptionLocales())
            ->getHtml();
        Mage::app()->saveCache($html, $cacheId, array(self::LOCALE_CACHE_TAG), self::LOCALE_CACHE_LIFETIME);
    }

    return $html;
}

You can notice the $locale->getTranslatedOptionLocales() is used to generate the options.

And the allowed locales are hardcoded directly under Mage_Core_Model_Locale_Config :

protected $_allowedLocales      = array(
    'af_ZA' /*Afrikaans (South Africa)*/,   'ar_DZ' /*Arabic (Algeria)*/,       'ar_EG' /*Arabic (Egypt)*/,
    'ar_KW' /*Arabic (Kuwait)*/,            'ar_MA' /*Arabic (Morocco)*/,       'ar_SA' /*Arabic (Saudi Arabia)*/,
    'az_AZ' /*Azerbaijani (Azerbaijan)*/,   'be_BY' /*Belarusian (Belarus)*/,   'bg_BG' /*Bulgarian (Bulgaria)*/,
    'bn_BD' /*Bengali (Bangladesh)*/,       'bs_BA' /*Bosnian (Bosnia)*/,       'ca_ES' /*Catalan (Catalonia)*/,
    'cs_CZ' /*Czech (Czech Republic)*/,     'cy_GB' /*Welsh (United Kingdom)*/, 'da_DK' /*Danish (Denmark)*/,
    'de_AT' /*German (Austria)*/,           'de_CH' /*German (Switzerland)*/,   'de_DE' /*German (Germany)*/,
    'el_GR' /*Greek (Greece)*/,             'en_AU' /*English (Australian)*/,   'en_CA' /*English (Canadian)*/,
    'en_GB' /*English (United Kingdom)*/,   'en_NZ' /*English (New Zealand)*/,  'en_US' /*English (United States)*/,
    'es_AR' /*Spanish (Argentina)*/,        'es_CO' /*Spanish (Colombia)*/,     'es_PA' /*Spanish (Panama)*/,
    'gl_ES' /*Galician (Galician)*/,        'es_CR' /*Spanish (Costa Rica)*/,   'es_ES' /*Spanish (Spain)*/,
    'es_MX' /*Spanish (Mexico)*/,           'es_EU' /*Basque (Basque)*/,        'es_PE' /*Spanish (Peru)*/,
    'et_EE' /*Estonian (Estonia)*/,         'fa_IR' /*Persian (Iran)*/,         'fi_FI' /*Finnish (Finland)*/,
    'fil_PH' /*Filipino (Philippines)*/,    'fr_CA' /*French (Canada)*/,        'fr_FR' /*French (France)*/,
    'gu_IN' /*Gujarati (India)*/,           'he_IL' /*Hebrew (Israel)*/,        'hi_IN' /*Hindi (India)*/,
    'hr_HR' /*Croatian (Croatia)*/,         'hu_HU' /*Hungarian (Hungary)*/,    'id_ID' /*Indonesian (Indonesia)*/,
    'is_IS' /*Icelandic (Iceland)*/,        'it_CH' /*Italian (Switzerland)*/,  'it_IT' /*Italian (Italy)*/,
    'ja_JP' /*Japanese (Japan)*/,           'ka_GE' /*Georgian (Georgia)*/,     'km_KH' /*Khmer (Cambodia)*/,
    'ko_KR' /*Korean (South Korea)*/,       'lo_LA' /*Lao (Laos)*/,             'lt_LT' /*Lithuanian (Lithuania)*/,
    'lv_LV' /*Latvian (Latvia)*/,           'mk_MK' /*Macedonian (Macedonia)*/, 'mn_MN' /*Mongolian (Mongolia)*/,
    'ms_MY' /*Malaysian (Malaysia)*/,       'nl_NL' /*Dutch (Netherlands)*/,    'nb_NO' /*Norwegian BokmГ_l (Norway)*/,
    'nn_NO' /*Norwegian Nynorsk (Norway)*/, 'pl_PL' /*Polish (Poland)*/,        'pt_BR' /*Portuguese (Brazil)*/,
    'pt_PT' /*Portuguese (Portugal)*/,      'ro_RO' /*Romanian (Romania)*/,     'ru_RU' /*Russian (Russia)*/,
    'sk_SK' /*Slovak (Slovakia)*/,          'sl_SI' /*Slovenian (Slovenia)*/,   'sq_AL' /*Albanian (Albania)*/,
    'sr_RS' /*Serbian (Serbia)*/,           'sv_SE' /*Swedish (Sweden)*/,       'sw_KE' /*Swahili (Kenya)*/,
    'th_TH' /*Thai (Thailand)*/,            'tr_TR' /*Turkish (Turkey)*/,       'uk_UA' /*Ukrainian (Ukraine)*/,
    'vi_VN' /*Vietnamese (Vietnam)*/,       'zh_CN' /*Chinese (China)*/,        'zh_HK' /*Chinese (Hong Kong SAR)*/,
    'zh_TW' /*Chinese (Taiwan)*/,           'es_CL' /*Spanich (Chile)*/,        'lo_LA' /*Laotian*/,
    'es_VE' /*Spanish (Venezuela)*/,        'en_IE' /*English (Ireland)*/,
);

So to me the easiest way of doing it would be to create a module to rewrite the footer block as I'm pretty sure the Mage_Core_Model_Locale_Config is used in several other places in the software.

So create app/etc/modules/Vendor_Module.xml

<config>
  <modules>
    <Vendor_Module>
      <active>true</active>
      <codePool>local</codePool>
    </Vendor_Module>
  </modules>
</config>

Then you can create app/code/local/Vendor/Module/etc/config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Vendor_Module>
      <version>0.0.1</version>
    </Vendor_Module>
  </modules>
  <global>
        <blocks>  
            <adminhtml>
                <rewrite>
                    <page_footer>Vendor_Module_Block_Adminhtml_Page_Footer</page_footer>
                </rewrite>
            </adminhtml>
        </blocks>
    </global> 
</config> 

Then you can create app/code/local/Vendor/Module/Block/Adminhtml/Page/Footer.php

<?php

class Vendor_Module_Block_Adminhtml_Page_Footer extends Mage_Adminhtml_Block_Page_Footer 
{
    public function getLanguageSelect()
    {
        $locale  = Mage::app()->getLocale();
        $cacheId = self::LOCALE_CACHE_KEY . $locale->getLocaleCode();
        $html    = Mage::app()->loadCache($cacheId);

        // Generate your own options
        $options = $this->_getCustomLocale();

        if (!$html) {
            $html = $this->getLayout()->createBlock('adminhtml/html_select')
                ->setName('locale')
                ->setId('interface_locale')
                ->setTitle(Mage::helper('page')->__('Interface Language'))
                ->setExtraParams('style="width:200px"')
                ->setValue($locale->getLocaleCode())
                ->setOptions($options)
                ->getHtml();
            Mage::app()->saveCache($html, $cacheId, array(self::LOCALE_CACHE_TAG), self::LOCALE_CACHE_LIFETIME);
        }

        return $html;
    }

    protected function _getCustomLocale()
    {
         $languages = Mage:getModel('core/locale')->getLocale()->getTranslationList('language', Mage:getModel('core/locale')->getLocale());
         $countries = Mage:getModel('core/locale')->getCountryTranslationList();
         $customLocales = array('en_US', 'fr_FR');
         $customOptions = array();
         foreach($customLocales as $customLocale) {
             $data = explode('_', $customLocale);
             $label = ucwords(Mage:getModel('core/locale')->getLocale()->getTranslation($data[0], 'language', $customLocale))
                        . ' (' . Mage:getModel('core/locale')->getLocale()->getTranslation($data[1], 'country', $customLocale) . ') / '
                        . $languages[$data[0]] . ' (' . $countries[$data[1]] . ')';
             $customOptions[] = array(
                    'value' => $customLocale,
                    'label' => $label
                );
         }
         return $this->_sortOptionArray($customOptions);
    }

    protected function _sortOptionArray($option)
    {
        $data = array();
        foreach ($option as $item) {
            $data[$item['value']] = $item['label'];
        }
        asort($data);
        $option = array();
        foreach ($data as $key => $label) {
            $option[] = array(
               'value' => $key,
               'label' => $label
            );
        }
        return $option;
    }
}

Don't forget to replace my example array array('en_US', 'fr_FR'); with the array containing your locale codes.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.