如何使用Laravel在PHP代码中使用本地化字符串?

I use Laravel Framework, and found this issue:

$var = ($userdata->age > 18 ? 'OK' : '@lang("basics.no_access")');

Of course I want to get the nice text from resources/lang/en/basics.php and not echo the '@lang("basics.no_access")' text.

How can I do this?

@lang works only within blade templates.

Use lang::get() which is the correct way to look up a language key outside a template:

When you pass Lang::get() a key, it looks up the key in the translation tables for the current locale. If no match is found, the original key is returned.