After switch to new language we need to redirect to apply new language for front-end. $this->storeCookieManager->setStoreCookie($store) $store = $this->storeRepository->getActiveStoreB圜ode($language) $currentStoreCode = $this->storeCookieManager->getStoreCodeFromCookie() Open the Base URLs section and type in your new URL, for this example: /german/.Deselect the use website checkbox, so that you. If they are different that mean other system changed language so I need to update store language for magento. That code I check current language and cookie language(which I get from cookie of browser). For it, from Magento 2 Admin go to Stores > All Stores > Create Store View. $this->_cookieManager->setPublicCookie($ke圜ookie, $lang, $cookieMetadata) $cookieMetadata = $this->cookieMetadataFactory->createPublicCookieMetadata() $domainCookie = $this->_api->getDomainCookie() $lang = $currentLanguage->getGetCurrentlyLanguageCode() $currentLanguage = $objectManager->get('Acommerce\Coreapi\Helper\Data') Plugins will help enhance the functions and create a multi-language store.Consider using these recommended Magento 2 extensions: Language Switcher Automatically switches the store language based on the user's location. $objectManager = \Magento\Framework\App\ObjectManager::getInstance() Recommended Magento 2 Extensions for Multi-Language Websites. Go to Stores > Configuration > Magefan Extensions > Auto Language Switcher. Public function beforeLaunch(Http $subject) The following steps to configure Magento 2 Auto Language Switcher: 1. In magento 2 sytem to switch language I create plugin with beforeLaunch function.First I have to use a cookie name language to set language code for all systems so when system A change language to ex: en(English) the cookie will store new value(en) and then when I visit magento site I can get new language.All system A, B, magento have to have same domain and use sub domain for each system ex: a.The request is if I’m at system A and I change from language X to Y then when I open Magento site ( in the same browser with the same tab or new tab), Magento has to switch to language Y. shop/storemyshopview for mainlanguage /shop/storemyshopviewfr for french That works fine and how it should work. The language switcher works with set a different store view in the url. My site have multi system A, B,
0 Comments
Leave a Reply. |