What best practices should be followed when including language translations in PHP scripts?

When including language translations in PHP scripts, it is best practice to use a localization library like Gettext to manage translations efficiently. This allows for easy maintenance and updating of translations without cluttering the code with multiple language strings. Additionally, it is important to properly sanitize and escape translated strings to prevent any security vulnerabilities.

// Example of using Gettext for language translations
$locale = 'fr_FR'; // Set the desired locale
putenv("LC_ALL=$locale");
setlocale(LC_ALL, $locale);

$domain = 'messages';
bindtextdomain($domain, "path/to/translations");
bind_textdomain_codeset($domain, 'UTF-8');
textdomain($domain);

echo gettext("Hello, world!"); // Output the translated string