How do I handle multi-language support

multi-language support, localization, internationalization, i18n, l10n
This example demonstrates how to implement multi-language support in web applications using PHP.
<?php // Set the default language $lang = 'en'; // Check if the user has selected a different language if (isset($_GET['lang'])) { $lang = $_GET['lang']; } // Load the appropriate language file based on user selection $messages = []; if ($lang === 'fr') { $messages = [ 'greeting' => 'Bonjour', 'farewell' => 'Au revoir' ]; } else { $messages = [ 'greeting' => 'Hello', 'farewell' => 'Goodbye' ]; } // Display messages to the user echo $messages['greeting']; // To switch language, use ?lang=fr for French or ?lang=en for English ?>

multi-language support localization internationalization i18n l10n