Before I use one website and mutli language view:
then this language.phtml switcher work and display in heder:
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile
?>
<?php
/**
* Language switcher template
*/
?>
<?php if (count($block->getStores())>1): ?>
<?php $id = $block->getIdModifier() ? '-' . $block->getIdModifier() : ''?>
<div class="dropdown dropdown-switcher language switcher-language" id="switcher-language<?php /* @escapeNotVerified */ echo $id?>">
<?php foreach ($block->getStores() as $_lang): ?>
<?php if ($_lang->getId() == $block->getCurrentStoreId()): ?>
<button class="switcher-toggle dropdown-toggle" type="button" data-toggle="dropdown">
<?php echo $block->escapeHtml($_lang->getName()) ?>
<i class="fa fa-angle-down" aria-hidden="true"></i>
</button>
<?php endif; ?>
<?php endforeach; ?>
<ul class="dropdown-menu">
<?php foreach ($block->getStores() as $_lang): ?>
<?php if ($_lang->getId() != $block->getCurrentStoreId()): ?>
<li class="view-<?php echo $block->escapeHtml($_lang->getCode()); ?> switcher-option">
<a href="#" data-post='<?php /* @escapeNotVerified */ echo $block->getTargetStorePostData($_lang); ?>'>
<img alt="<?php echo $_lang->getCode(); ?>" src="<?php /* @escapeNotVerified */ echo $block->getViewFileUrl('images/flags/' . $_lang->getCode() . '.png') ?>" /><?php echo $block->escapeHtml($_lang->getName()) ?>
</a>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
But now I changed and add mutli website for multi language (separate domains):
and now the language switcher has stopped displaying. Does anyone know how I can change it?
@Update3
I found file default.xml:
I changed this block from:
<block class="Magento\Theme\Block\Html\Header" name="header" as="header" after="-">
<arguments>
<argument name="show_part" xsi:type="string">welcome</argument>
</arguments>
<block class="Magento\Store\Block\Switcher" name="store_language" as="store_language" template="switch/languages.phtml"/>
<block class="Magento\Directory\Block\Currency" name="currency" before="store_language" template="currency.phtml"/>
<block class="Magento\Framework\View\Element\Html\Links" name="top.links">
<arguments>
<argument name="css_class" xsi:type="string">links</argument>
</arguments>
</block>
<block class="Magento\Theme\Block\Html\Header\Logo" name="logo">
<arguments>
<argument name="logo_img_width" xsi:type="number">189</argument>
<argument name="logo_img_height" xsi:type="number">64</argument>
</arguments>
</block>
TO:
<block class="Magento\Theme\Block\Html\Header" name="header" as="header" after="-">
<arguments>
<argument name="show_part" xsi:type="string">welcome</argument>
</arguments>
<block class="Your\Custom\Block\Class" name="store_language" as="store_language" template="Magento_Store::switch/languages.phtml"/>
<block class="Magento\Directory\Block\Currency" name="currency" before="store_language" template="currency.phtml"/>
<block class="Magento\Framework\View\Element\Html\Links" name="top.links">
<arguments>
<argument name="css_class" xsi:type="string">links</argument>
</arguments>
</block>
<block class="Magento\Theme\Block\Html\Header\Logo" name="logo">
<arguments>
<argument name="logo_img_width" xsi:type="number">189</argument>
<argument name="logo_img_height" xsi:type="number">64</argument>
</arguments>
</block>
But still this issues on line 19:
<?php foreach ($websites as $website): ?>
Best Answer
Language switcher shows for multiple languages per website. It does not show if each website has only one language.
In this case, if you want to show switcher, you can show the website switcher.
Please try with the following code:
Update: As you are using the existing language.phtml file, you also need to create a custom block file and use it in the XML layout file for calling the PHTML file.
The code block file should be like below:
Now while calling the PHTML file from the layout XML, use the new block class.
Update 2: Location of layout XML file should be under
app/design/frontend/{current-theme-package}/{{current-theme}}/Magento_Theme/layout/default.xml
In this file you should see something like:
If yes, you need to change it to: