2

I would like to modify a core component of Joomla by setting up a condition based on the language the website is displaying. My code changes don't seem to work and I'm not sure what I'm doing wrong.

<?php
defined('JPATH_BASE') or die;
$lang = JFactory::getLanguage();
?>

<div class="Home"> 
<?php if ($lang->language == 'en-US') : ?>Home:
<?php elseif ($lang->language = 'fr-fr') : ?>Accueil :
<?php endif; ?>
</div> 

1 Answer 1

4

You should try this:

<div class="Home"> 
<?php
  $lang = JFactory::getLanguage();
  $result = $lang->getTag();
  if ($result=="fr-FR") { 
      echo 'Accueil: ';
  } 
  else { 
      echo 'Home: ';
  }
?> 
</div> 
2
  • @Lodder this task should be done wholly through language constants and all-caps placeholders, right? I dont quite know the correct terminology. Might you provide a best-practice answer? Commented May 7, 2019 at 10:24
  • @mickmackusa This is what I personally use and can't think of another approach. If you know of one, please feel free to submit another answer
    – Lodder
    Commented May 7, 2019 at 11:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.