unikat
4 years ago
2469
20
Laravel

Determining if a translation in specific locale exists

Posted 4 years ago by unikat

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

Please sign in or create an account to participate in this conversation.