What are best practices for organizing language files in PHP for multi-language support?

When organizing language files in PHP for multi-language support, it is best practice to store each language in separate files to maintain clarity and organization. One common approach is to create a directory for each language, with individual files for each language containing key-value pairs for translations. This allows for easy maintenance and updates to language files without affecting other languages.

$lang = [];

// Load English language file
include 'languages/en.php';

// Load Spanish language file
include 'languages/es.php';

// Function to retrieve translation
function translate($key, $lang){
    global $lang;
    return isset($lang[$key]) ? $lang[$key] : $key;
}

// Example usage
echo translate('greeting', $lang);