// Set the language to German $locale = 'de_DE'; putenv("LC_ALL=$locale"); setlocale(LC_ALL, $locale); // Load the translation file bindtextdomain('messages', 'path/to/translations'); // Translate a message echo _("Hello, world!");
// Set the language to French $locale = 'fr_FR'; putenv("LC_ALL=$locale"); setlocale(LC_ALL, $locale); // Format a date $date = new DateTime('2022-06-30'); echo strftime('%A %e %B %Y', $date->getTimestamp());In this example, we set the locale to French and format a date using the `strftime()` function, which takes a format string and a timestamp. The PHP i18n library is often used in conjunction with gettext or the PHP intl extension. It provides convenient functions to handle translations and localized content.