Maybe because you are adding the param to the dd function?
dd(Lang::has('messages.test', 'en'))
dd(Lang::has('messages.test', 'de'))
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
How can I check if a translation exists for the specific locale?
I've tried to use the Lang::has($key, $locale) but it doesn't work as intended. No matter what $locale is passed as a second argument, if the translation doesn't exist, it always fallback to the default locale and always returns TRUE:
// /lang/en/messages.php
return [
'test' => 'ok'
]
// /lang/de/messages.php
return [
]
dd(Lang::has('messages.test'), 'en') // true
dd(Lang::has('messages.test'), 'de') // true !!! It should return FALSE
Try this one :
/**
* Determine if phrase exist.
*
* @param string $phrase
* @param string $lang
* @param string $default
* @return boolean
*/
function langHas($phrase, $lang, $default = 'en')
{
if(Lang::has($phrase, $lang) == false || Lang::get($phrase, $lang) == Lang::get($phrase, $default)){
return false;
}
return true;
}
Please or to participate in this conversation.