Write your PHP code.
<?php
bindtextdomain('messages', './');
switch ($argv[1]) {
case 'de':
putenv("LC_ALL=de");
break;
case 'en':
default:
putenv("LC_ALL=en");
break;
}
print _("Hey");
print "\n<br>\n";
print _("This is example number ") . "2!";
?>
Extract the strings from the file, using the xgettext(1) program.
]$ xgettext -a gettext_ex.php
Create the appropriate subdirectories, and place your portable object
files there.
]$ mkdir -p en/LC_MESSAGES/
]$ mv messages.po en/LC_MESSAGES/
]$ mkdir -p de/LC_MESSAGES/
]$ cp en/LC_MESSAGES/messages.po de/LC_MESSAGES/messages.po
Translate it!
Now compile all of your translations with msgfmt(1)
]$ msgfmt messages.po -o messages.mo