3

The locale I need is not included in the standard Magento language extensions, so I need to create my own.

It will be es-us - Spanish language for the US.

I found this article: http://kb.magenting.com/content/14/50/en/translate-magento-interface-magento-localization-tips.html

It says:

"If there are no localization package for your locale you can create it by simply copying localization directory from English or any other translation."

Can someone walk me through how I get from that quote to having Spanish (USA) in the locale drop-down?

Thank you so much for your help!

2 Answers2

12

I came upon this answer whilst investigating Mage_Core_Model_Locale_Config and I was able to come up with a solution that didn't require any code changes at all.

Mage_Core_Model_Locale_Config does indeed contain a hardcoded list of locales, but the getAllowedLocales() method combines this with the output of

Mage::getConfig()->getNode(Mage_Core_Model_Locale::XML_PATH_ALLOW_CODES);

in 1.4.2 the value of Mage_Core_Model_Locale::XML_PATH_ALLOW_CODES is

'global/locale/allow/codes'

So all you need to do is add the following xml to your app/etc/local.xml within your 'global' tags:

         <locale>
        <allow>
            <codes>
                <en_IE/>
              </codes>
        </allow>
    </locale>

And the English(Ireland) locale will appear in your locale dropdown. The only limitation is that the locale code must be one of the ones defined in the Zend Framework documentation here: http://framework.zend.com/manual/1.12/en/zend.locale.appendix.html

'es_US' is one of these supported codes. I hope that helps someone.

_Pez

underscorePez
  • 897
  • 9
  • 19
2

Unfortunately, it looks as if the locale names are hardcoded in Mage_Core_Model_Locale_Config. Not only that, but language codes are installed in the database during install.

What I would recommend doing instead of rewriting that class to define your own custom language is to "piggyback" on another locale and use their code for your custom language pack. For example, in app/locale, you could place the folder gl_ES, copy over a Spanish language pack, and make the modifications you need for that language. Then for your store's locale in the dropdown (System > Configuration > General > Locale) you can choose Galician (Galician)

The custom solution that you're requesting I think would involve rewriting Mage_Core_Model_Locale_Config to add your new locale to the $_allowedLocales variable. I thought you may need to add the language to the core_language table but it looks as if that table's been deprecated.

1000Nettles
  • 2,314
  • 3
  • 22
  • 31
  • Thank you!! Do you know if this affects the store code at all? I need the URL to say es-us for targeting/SEO purposes. Also, can you give me a general sense of the amount of development work that would be required for your solution, versus doing it "right" and creating custom? Thanks again! I really appreciate your insight! – Laura Grimes Alter Jan 16 '13 at 02:18
  • Store code is completely custom - you can adjust it in System > Manage Stores > [your store] and it's the field 'Code'. My solution is basically no work at all as it's just implementing default Magento behaviour. The custom solution isn't that much more work, but I usually steer clear of things like this if default behaviour works just as well (why introduce another potential point of failure?) I've added additional instructions above for the custom solution. – 1000Nettles Jan 16 '13 at 03:14