2

How do I programmatically set the locale information of a store view?

enter image description here

I don't know how to set this value, although I can get it using:

echo Mage::getStoreConfig('general/locale/code', $store_view->getId()) ;

Here it follows the code I use to programmatically create the store view:

$store_view = Mage::getModel('core/store');
$store_view->setCode($english_store_code)
                    ->setWebsiteId($storeGroup->getWebsiteId())
                    ->setGroupId($storeGroup->getId())
                    ->setName('English')
                    ->setIsActive(1)
                    ->save(); 
2
+50

Try this

Mage::getModel('core/config')->saveConfig('general/locale/code', $value, $scope, $scopeId);

See function definition of saveConfig() at \app\code\core\Mage\Core\Model\Config.php

| improve this answer | |
  • 1
    Thank you so much, this is the code I used: Mage::getModel('core/config')->saveConfig('general/locale/code', "en_US", "stores", $english_store->getId()); – Niko Zarzani Aug 1 '16 at 10:53
2

Please use below code to set locale value. and write second line for clear cache.

Mage::getConfig()->saveConfig('general/locale/code','en_US');
Mage::app()->getCacheInstance()->cleanType('config');

Please specify store ID if you have multi store.

Mage::getConfig()->saveConfig('general/locale/code','en_US','stores',$store_view->getId());
| improve this answer | |
1

You can set Direct Language code

$locale = 'nl_NL';
Mage::getSingleton('core/session')->setMyLang($langCode);
$locale = Mage::getSingleton('core/session')->getMyLang();


Mage::getSingleton('core/translate')->setLocale($locale)->init('frontend', true);

$defaultStore = Mage::app()->getStore()->getCode();
Mage::app()->setCurrentStore($defaultStore);
Mage::app()->getLocale()->setLocale($locale);
Mage::app()->getTranslator()->init('frontend', true);

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

now Site translate in Your set Language.

you can pass $locale value dynamically on dropdown change event using js.

| improve this answer | |
0

Try this one,

$config = new Mage_Core_Model_Config();
$config -> saveConfig('general/locale/code', $value , 'default', $storeId);
| improve this answer | |
  • 1
    $config = new Mage_Core_Model_Config(); .. this is not the best way of coding .. you should use Mage::getModel('core/config') instead.. – Reena Parekh Jul 29 '16 at 11:57
  • Oh thanx for the information... But this is also working for me. – Dhrumin Jul 29 '16 at 11:58

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.