show/hide a link based on language of interface

General questions regarding the use of languages in Joomla! 3.x.

Moderators: infograf768, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Post Reply
Lxg
Joomla! Intern
Joomla! Intern
Posts: 94
Joined: Sun Dec 02, 2012 8:48 pm

show/hide a link based on language of interface

Post by Lxg » Fri Jan 12, 2018 10:31 pm

I have a bilingual site (english and french). Some of our pages are only served as language=all and are not translated (served in english only because the programs offered are in english only). However, those pages do link to other pages - some english only some served in both languages. I would like to be able to somehow determine which interface the visitor is using and give them an english link or a french link as appropriate. This means 2 copies of the otherwise identical article - maintenance problem or perhaps some kind of .css 'trick'. I have put

Code: Select all

.french { display : none ;}
.english {display: none ;}
into my .css and it hides both links in the article with:

Code: Select all

 <span class="english"><a href="index.php/events/spring-series">Spring Series Events</a></span> 
<span class="french"> <a href="index.php/fr/activites/la-serie-du-printemps" >La series du printemps</a></span>
Is there a way to identify the language of the interface and hide the appropriate link? I am happy to explore any ideas.

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 24743
Joined: Mon Oct 27, 2008 9:27 pm
Location: Akershus, Norway

Re: show/hide a link based on language of interface

Post by Per Yngve Berg » Sat Jan 13, 2018 12:14 am

Code: Select all

<?php echo $this->language; ?>
It will output "en-gb" or "fr-fr".

User avatar
infograf768
Joomla! Master
Joomla! Master
Posts: 18649
Joined: Fri Aug 12, 2005 3:47 pm
Location: **Translation Matters**

Re: show/hide a link based on language of interface

Post by infograf768 » Sat Jan 13, 2018 6:01 pm

The exact code to use anywhere in Joomla, i.e. not only in the index.php of the template, is:

Code: Select all

$tag = JFactory::getLanguage()->getTag();
If you have both French and English

Then $tag value will be en-GB or fr-FR
Jean-Marie Simonet / infograf · http://www.info-graf.fr
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group


Post Reply

Return to “Language - Joomla! 3.x”