Multilanguage alerts form php form script

i’m looking for way to translate alerts from php script

I have a validatior in script:

$errors = [];    
if (empty($_POST["name"])) {
    $errors[] = l::get('name');
    } else { 
    	$name = implode(', ' ,$_POST['name']);

in language/de file i have this
l::set('name', 'gib den Nachnamen an');

in language/fr file i have this
l::set('name', 'donne le nom de famille');

But i have a error

Fatal error: Uncaught Error: Class ‘l’ not found in

Problem is with this, but i don’t know how can i translate allerts diferent way.
$errors[] = l::get('name');

Where do you use this script? In a template/controller/plugin? Is this a multilang site?

I have a footer snipet with ajax to assets/php/script.php

Yes this is a multilangsite

Then your scripts works outside of the Kirby context and won’t know anything about the language class.

Try to include the language files in your script:

include_once(kirby()->roots()->languages() . DS . str::lower($lang) . '.php');

Or, instead of the. external script, call a route (but then you would still have to include the language files)