I need some help to modify my custom error.php to show a 404 depending on the language in my bi-lingual development site (NL and FR).
In a monolingual site (f.i. NL) I always use this error.php together with a hidden menu with a menu-item "niet-gevonden" set to NL, linked to the 404-article set to NL, and this works like expected.
<?php
defined('_JEXEC') or die;
if (($this->error->getCode()) == '404') {
header("HTTP/1.0 404 Not Found");
echo file_get_contents(JURI::root().'/niet-gevonden');
exit;}
?>
Now with 2 languages (NL and FR) I have created two menu-items linked to each appropriate article in the hidden menu and this error.php:
<?php
defined('_JEXEC') or die;
if (($this->error->getCode()) == '404') {
header("HTTP/1.0 404 Not Found");
$lang = JFactory::getLanguage();
$result = $lang->getTag();
if ($result=="nl-NL") {
echo file_get_contents(JURI::root().'/niet-gevonden');
exit;}
if ($result=="fr-FR") {
echo file_get_contents(JURI::root().'/non-trouve');
exit;}
}
?>
But now only the NL-404 is shown and the expected FR-404 shows an empty page.
My PHP-knowledge is very poor, in fact zero, so I was inspired to this older topic: https://joomla.stackexchange.com/questions/15141/how-to-create-a-custom-404-error-page-for-every-language but obviously I missed something.
Any suggestions ?
Joomla 4.3.4 – PHP 8.1.21
Thanks