I have a question about the Joomla language switcher module. I would like to hide the option to switch to English language on the website. I can't unpublish the English language because then it says the English site doesn't exist anymore. But I need it to exist because its accessed from different link.
-
thinking ... hmmm, then what is the point to have a link for the current language on the website... I mean that from your description people will already seeing the Hrvatski version of the website, why to have a language selection for the same language?– FFrewinNov 26, 2014 at 9:40
-
Default language is Slovenian-SI, but i also need option for Hrvatski-HR. I cant unpublish English-UK because the entire English site stops working. So basicly SI/HR are accessed from same link, EN version is accessed from entierly diffrent link. www.aeq.si <- SI/HR somatics.si <- EN only– MatthewNov 27, 2014 at 17:17
-
i know this thread is very old but... i can't find that line on the default.php file. Any idea?– 94a94Jul 1, 2020 at 11:09
-
@94a94 - If you have the same or similar problem and none of the answers here is able to solve it, then I would suggest you to create a new question add all relevant information and references to this question in order to get an answer. Also - and this is very important - before you do anything familiarise with how JSE works, how to ask questions, post answers, etc following: help center and tour– FFrewinJul 1, 2020 at 12:15
3 Answers
- Copy the file
modules\mod_languages\tmpl\default.php
totemplates\YOURTEMPLATE\html\mod_languages\default.php
to create a template override for the language module. Locate the following line in your template override (aprox. line 32 in Joomla 3.3):
<li class="<?php echo $language->active ? 'lang-active' : '';?>" dir="<?php echo JLanguage::getInstance($language->lang_code)->isRTL() ? 'rtl' : 'ltr' ?>">
Replace with this (adding
echo $language->title_native;
):<li class="<?php echo $language->active ? 'lang-active' : ''; echo ' ' . $language->lang_code; ?>" dir="<?php echo JLanguage::getInstance($language->lang_code)->isRTL() ? 'rtl' : 'ltr' ?>">
This will add the language code to the
<li>
tags, giving you<li class="active en-GB"...
and allow you to target any language using CSS.Finally, add this code to your template's CSS stylesheet (replace
en-GB
with the language you want to hide):.en-GB { display: none!important; }
-
-
Yes @FFrewin, using CSS in this case is a "quick-and-dirty" solution, yours is a bit more advanced.– johanpwNov 25, 2014 at 20:17
-
in what folder do i create css file and what filename do i give it ? Im am new to joomla– MatthewNov 25, 2014 at 22:18
-
-
Ok i did all those things, now how do i override the template, do i have to check something in CMS ?– MatthewNov 25, 2014 at 22:50
Following Anibal's answer and the link on how to create a module template override or alternative layout... here is a piece of code you could use inside the template file of the languages module.
The template of the module is checking for the settings you have defined in the module manager, about how to display the languages.
Part of code is like this:
<?php if ($params->get('show_active', 0) || !$language->active):?>
<li class="<?php echo $language->active ? 'lang-active' : '';?>" dir="<?php echo JLanguage::getInstance($language->lang_code)->isRTL() ? 'rtl' : 'ltr' ?>">
<a href="<?php echo $language->link;?>">
<?php if ($params->get('image', 1)):?>
<?php echo JHtml::_('image', 'mod_languages/' . $language->image . '.gif', $language->title_native, array('title' => $language->title_native), true);?>
<?php else : ?>
<?php echo $params->get('full_name', 1) ? $language->title_native : strtoupper($language->sef);?>
<?php endif; ?>
</a>
</li>
<?php endif;?>
<?php endforeach;?>
It uses foreach loop, to loop through the available content languages and will display them. Inside the foreach loop and right after its beginning and before its end, you can wrap the executed code with a conditional check like below:
This goes after the beginning of the foreach loop:
<?php if ($language->lang_code != 'en-GB') {?>
This will make the code that renders the language menus, only if the language of the menu is not english.
This closes and wrap your if statement, just before the closing of the foreach loop.
<?php } ?>
So you should end up with something like this:
<?php foreach ($list as $language) : ?>
<?php if ($language->lang_code != 'en-GB') {?> // Don't run if it's english.
<?php if ($params->get('show_active', 0) || !$language->active):?>
<li class="<?php echo $language->active ? 'lang-active' : '';?>" dir="<?php echo JLanguage::getInstance($language->lang_code)->isRTL() ? 'rtl' : 'ltr' ?>">
<a href="<?php echo $language->link;?>">
<?php if ($params->get('image', 1)):?>
<?php echo JHtml::_('image', 'mod_languages/' . $language->image . '.gif', $language->title_native, array('title' => $language->title_native), true);?>
<?php else : ?>
<?php echo $params->get('full_name', 1) ? $language->title_native : strtoupper($language->sef);?>
<?php endif; ?>
</a>
</li>
<?php endif;?>
<?php } ?>
<?php endforeach;?>
You can create a new module layout, showing only the languages you need.
Module Alternative Layouts http://docs.joomla.org/Layout_Overrides_in_Joomla#Module_Alternative_Layouts