"; // Print a test message $defdiv.=$word . " translates to $lang as " . gettext($word) . "
"; // Or use the alias _() for gettext() $defdiv.=$word . " translates to $lang as " . _($word) . "
"; echo "

Using gettext with PHP

RJM Programming - August, 2024

" . $defdiv . "


Language FromLanguage ToWord/Phrase to Translate
English ( en_GB )
"; exit; putenv('LC_ALL=de_DE'); setlocale(LC_ALL, 'de_DE'); // Specify location of translation tables bindtextdomain("messages", "/home/rjmprogr/public_html/PHP/gettext/locale/de_DE/LC_MESSAGES"); // Choose domain textdomain("messages"); // Translation is looking for in ./locale/de_DE/LC_MESSAGES/messages.mo now // Print a test message echo gettext("Sidebar"); // Or use the alias _() for gettext() echo _("Sidebar"); exit; require_once("localization.php"); $results = gettext("Sidebar"); if ($results === "Sidebar") { echo "Original English was returned. Something wrong ... \n"; } echo $results . "\n"; $results = gettext("Similar Meaning"); if ($results === "Similar Meaning") { echo "Original English was returned. Something wrong ... \n"; } echo $results . "\n"; echo "
"; echo gettext("via"); echo "
"; $n = 3; printf(ngettext("%d comment", "%d comments", $n), $n); ?>